C Puzzles

yet another place for C puzzles

Wednesday, December 20, 2006

 

rotated sub string

Given a string s1 and a string s2, write a snippet to say whether s2 is a
rotation of s1 using only one call to strstr routine?

(eg given s1 = ABCD and s2 = CDAB, return true,
given s1 = ABCD, and s2 = ACBD , return false)


I hope this will work:
strcpy (s3,s1); //s3 = ABCD
strcat (s1,s3); // s1 = ABCDABCD
then check for strstr(s1,s2);

Comments:
s2=strcat(s2,s2);
if(s2,s1)
return true;
else
return false;
 
Post a Comment

Subscribe to Post Comments [Atom]





<< Home

Archives

July 2005   August 2005   October 2005   December 2005   March 2006   June 2006   July 2006   December 2006   February 2007   June 2007   March 2010   May 2010  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]