-
Notifications
You must be signed in to change notification settings - Fork 0
/
10924.cpp
74 lines (60 loc) · 1010 Bytes
/
10924.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <ctype.h>
/* 10924 - Prime Words */
#define ONEPRIME true
bool isPrime(int x)
{
int i;
if(x == 1)
{
return ONEPRIME;
}
if(x == 2)
{
return true;
}
if(x % 2 == 0)
{
return false;
}
for(i = 3 ; i * i <= x ; i += 2)
{
if(x % i == 0)
{
return false;
}
}
return true;
}
bool isPrimeWord(char *word)
{
int sumOfLetters = 0;
for(int i = 0 ; word[i] != '\0' ; i++)
{
if(islower(word[i]))
{
sumOfLetters += word[i] - 96;
}
else
{
sumOfLetters += word[i] - 38;
}
}
return isPrime(sumOfLetters);
}
int main()
{
char word[21];
while(scanf("%s", word) != EOF)
{
if(isPrimeWord(word))
{
printf("It is a prime word.\n");
}
else
{
printf("It is not a prime word.\n");
}
}
return 0;
}