We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I originally implemented it this way, then I realized the comparisons are not really needed. The program just needs to figure out if it has touched every letter in the alphabet, and can do with a simple integer array that is incremented as the ASCII values are found:
int main() {
int alpha[26] = {0};
int offset = 0;
char input[1024] = {0};
fgets(input, 1024, stdin);
for ( int i=0; input[i] != '\0'; i++) {
if ( input[i] > 96 && input [i] < 123 ) {
offset = input[i] - 97;
alpha[offset] = 1;
} else if ( input[i] > 64 && input[i] < 91 ) {
offset = input[i] - 65;
alpha[offset]= 1;
}
}
for ( int i=0; i < 26; i++) {
if ( alpha[i] == 0 ) {
printf("not pangram\n");
return 0;
}
}
printf("pangram\n");
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Pangrams
You are viewing a single comment's thread. Return to all comments →
I originally implemented it this way, then I realized the comparisons are not really needed. The program just needs to figure out if it has touched every letter in the alphabet, and can do with a simple integer array that is incremented as the ASCII values are found: