Skip to content

Instantly share code, notes, and snippets.

@agr-shrn
Last active September 3, 2015 11:38
Show Gist options
  • Save agr-shrn/4e16cfa71678f304f984 to your computer and use it in GitHub Desktop.
Save agr-shrn/4e16cfa71678f304f984 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string.h>
using namespace std;
void removeDuplicate ( char s [])
{
int len = strlen ( s );
if ( len < 2 ) return ;
bool c [ 256 ];
memset ( c , 0 , sizeof ( c ));
int P = 0 ;
for ( int i = 0 ; i < len ; ++ i )
{
if ( ! c [ s [ i ]])
{
s [ P ++ ] = s [ i ];
c [ s [ i ]] = true ;
}
}
s [ P ] = '\0' ;
}
bool isUnique3( string s )
{
int Check = 0 ,j =0, var = 0;
int len = s . length ();
for ( int i = 0 ; s[i]!='\0' ;)
{
len = s . length ();
int v = ( int ) ( s [ i ] - ' a ' );
if ( Check & ( 1 << v ))
{
for(j=i;j<len;j++)
{
s[j] = s[j+1];
var++;
}
s[j] = '\0';
//return false ;
}
else
i++;
Check = Check | ( 1 << v );
}
cout<<"\n"<<s;
cout<<endl<<var;
return true ;
}
int main()
{
char s[100];
bool a;
cin>>s;
removeDuplicate(s);
cout<<s;
//a = isUnique3(s);
//cout<<"\n"<<(1 << 33);
}
#include <iostream>
#include <String>
using namespace std ;
bool issubstring ( string S1 , string S2 ) {
if ( (S1.find ( S2 )) != string :: npos ) return true ;
else return false ;
}
bool isRotation ( string S1 , string S2 ) {
if ( (S1 . length ()) != S2 . length () || S1 . length () <= 0 )
return false ;
return issubstring ( S1 + S1 , S2 );
}
int main () {
string S1 = "apple" ;
string S2 = "pleap" ;
cout << isRotation ( S1 , S2 ) << endl ;
// cout << endl << String :: npos;
return 0 ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment