Friday 25 August 2017

Given two string s1 and s2 how will you check if s1 is a rotated version of s2?

If s1 = “crazyforcode” then the following are some of its rotated versions:
 “forcodecrazy”
 “codecrazyfor”

Input Format:
Two strings S1 and S2.
Length(S1), Length(S2) > 1
 
Output Format:
Print "YES" or "NO" without double quotes.
 
Input:
crazyforcode
codeforcrazy

Output:
NO


#include<stdio.h>
#include<string.h>
void main()
{
    char str1[50];
    char str2[50];
    char temp[50];
    char *ptr;
    scanf("%s",str1);
    scanf("%s",str2);
    int len1,len2;
    len1=strlen(str1);
    len2=strlen(str2);
    if(len1!=len2)
        printf("No");
    temp[0]='\0';
    strcat(temp,str1);
    strcat(temp,str1);
    ptr=strstr(temp,str2);
    if(ptr!=NULL)
        printf("\nYes");
    else
        printf("\nNo");
}

No comments:

Post a Comment