fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. int is_shifted (char * s, char * goal)
  4. {
  5. int len_s = strlen(s);
  6. int len_goal = strlen(goal);
  7.  
  8. if(len_s != len_goal)
  9. {
  10. return 0;
  11. }
  12. char temp [2 * len_s + 1];
  13. strcpy (temp,s);
  14. strcat (temp,s);
  15.  
  16. return strstr (temp,goal) != Null;
  17. {
  18. char s [] = "abcde";
  19. char goal [] = "cdeab";
  20. printf("%s\n", is shifted(s,goal) ? "true" : "false");
  21.  
  22. strcpy (s, "abcde");
  23. strcpy(goal, "abced");
  24. printf("%s\n", is shifted(s,goal) ? "true" : "false");
  25.  
  26. strcpy(s, "abcdefg");
  27. strcpy(goal, "defgabc");
  28. printf("%s\n", is shifted(s,goal) ? "false" : "true");
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0.03s 25692KB
stdin
Standard input is empty
stdout
#include <stdio.h>
#include <string.h>
int is_shifted (char * s, char * goal)
{
    int len_s = strlen(s);
    int len_goal = strlen(goal);
    
    if(len_s != len_goal)
    {
        return 0;
    }
    char temp [2 * len_s + 1];
    strcpy (temp,s);
    strcat (temp,s);
    
    return strstr (temp,goal) != Null;
    {
        char s [] = "abcde";
        char goal [] = "cdeab";
        printf("%s\n", is shifted(s,goal) ? "true" : "false");
        
        strcpy (s, "abcde");
        strcpy(goal, "abced");
        printf("%s\n", is shifted(s,goal) ? "true" : "false");
        
        strcpy(s, "abcdefg");
        strcpy(goal, "defgabc");
        printf("%s\n", is shifted(s,goal) ? "false" : "true");
    }
    return 0;
}