Created
February 7, 2011 16:14
-
-
Save sinmaplewing/814623 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<ctype.h> | |
#include<string.h> | |
int letter_to_i( char c ) | |
{ | |
if( isupper(c) ) | |
return c - 'A' + 27; | |
else if( islower(c) ) | |
return c - 'a' + 1; | |
else | |
return 0; | |
} | |
int main() | |
{ | |
int prime[10005] = { 1, 0, 0 }; | |
int i, j; | |
for( i = 2 ; i <= 10000 ; i++ ) | |
if( !prime[i] ) | |
for( j = i+i ; j <= 10000 ; j+=i ) | |
prime[j] = 1; | |
char word[25]; | |
while( gets(word) ) | |
{ | |
int L = strlen(word); | |
int sum = 0; | |
for( i = 0 ; i < L ; i++ ) | |
sum += letter_to_i( word[i] ); | |
if( prime[sum] ) | |
printf( "It is not a prime word.\n" ); | |
else | |
printf( "It is a prime word.\n" ); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment