Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cctype>
- #include <cstring>
- #include <cmath>
- using namespace std;
- char word[21];
- int resp;
- bool read() {
- return scanf("%s", word) != EOF;
- }
- bool isPrime(int x) {
- if (x == 1 || x == 2 || x == 3) return true;
- else for (int i = 2; i < sqrt(x)+1; i++) if (x % i == 0) return false;
- return true;
- }
- void process() {
- resp = 0;
- for (int i = 0; i < strlen(word); i++) {
- if (islower(word[i])) resp += ((int) (word[i]-96));
- else if (isupper(word[i])) resp += ((int) (word[i]-38));
- }
- if (isPrime(resp)) printf("It is a prime word.\n");
- else printf("It is not a prime word.\n");
- }
- int main() {
- while(read()) process();
- }
Add Comment
Please, Sign In to add comment