In the Byteland country a string "S" is said to super ascii string if and only if count of each character in the string is equal to its ascii value.
In the Byteland country ascii code of 'a' is 1, 'b' is 2 ...'z' is 26.
Your task is to find out whether the given string is a super ascii string or not.
int main(){ char string[maxlenght]; int count[26]; int i, j, n, flag, lenght;
scanf_s("%d", &n);//read test count for (j = 0; j < n; j++){// for each string
for (i = 0; i < 26; i++){ count[i] = 0;}//reset letter count
fgets(string, maxlenght, stdin);// read string if (string[0] == '\n') fgets(string, maxlenght, stdin);// if read empty string
lenght = strlen(string); // get string lenght for (i = 0; i < lenght; i++){// for each letter if ((string[i] >= 'a') && (string[i] <= 'z')){//if lower case alphabets count[string[i] - 'a']++;// a - count[0], z - count[25] } }
flag = 1; for (i = 0; i < 26; i++){ if (count[i] != (i + 1) && (count[i] != 0)){ flag = 0; break; }//if the condition isn't satisfied } if (flag){ printf("Yes\n"); } else{ printf("No\n"); } } getchar(); return 0; }
Comments
Leave a comment