rotation of string

Go down

rotation of string

Post  Admin on Wed Aug 13, 2008 7:45 am

you are given two string s1 and s2 and you have to tell whether string s2 is rotation of string s1 or not you have to use strstr function only once ?
example s1=abcde
s2=cdeab
here s2 is a rotation of s1
Question

Admin
Admin

Posts : 39
Join date : 2008-08-03

View user profile http://computerclub09mnnit.forumotion.net

Back to top Go down

this should work...

Post  prani on Wed Aug 13, 2008 9:21 am

s1=s1+s1;
strstr(s1,s2) will tell whether rotation or not

prani

Posts : 15
Join date : 2008-08-12

View user profile

Back to top Go down

Re: rotation of string

Post  ish_mnnit on Wed Aug 13, 2008 11:30 am

#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
int main()
{
char s1[100],s2[100],s[100];
cin>>s1;
cin>>s2;
strcpy(s,s1);
strcat(s1,s);
if(strstr(s1,s2)!=NULL)
cout<<"rotation";
else
cout<<"no rotation";
getch();
}
logic of this programm is that if we add any string two times it will contain all of its rotation.

ish_mnnit

Posts : 4
Join date : 2008-08-10

View user profile

Back to top Go down

Re: rotation of string

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum