rotation of string
Page 1 of 1 • Share •
rotation of string
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

example s1=abcde
s2=cdeab
here s2 is a rotation of s1
Admin- Admin
- Posts: 39
Join date: 2008-08-03

this should work...
s1=s1+s1;
strstr(s1,s2) will tell whether rotation or not
strstr(s1,s2) will tell whether rotation or not
prani- Posts: 15
Join date: 2008-08-12
Re: rotation of string
#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.
#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
Permissions of this forum:
You cannot reply to topics in this forum





