Question #278800

The students of Dr. Kyle have submitted an unique string that Dr. Kyle gave them for homework. He is checking the strings of student A and student B which are denoted as  and . Dr. Kyle wants to find out if they copied each other's work. If the string  can be transformed into string  with rotations, it'll be obvious to Dr. Kyle that they have cheated.


Expert's answer

#include <stdio.h>
#include <stdbool.h>

char count[256];

int main() {
  char *a, *b;
  scanf("%s %s", &a, &b);
  for (int i = 0; i < strlen(a); i++)
    count[a[i]]++;
  for (int i = 0; i < strlen(b); i++)
    count[b[i]]++;
  bool flag = true;
  for (int i = 0; i < 256; i++)
    if (count[i] != 0) flag = false;
  if (flag)
    printf("unique");
  else
    printf("not unique"); 
}
LATEST TUTORIALS
APPROVED BY CLIENTS