Guest User

Untitled

a guest
Jan 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cctype>
  3. #include <cstring>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. char word[21];
  9. int resp;
  10.  
  11. bool read() {
  12.     return scanf("%s", word) != EOF;
  13. }
  14.  
  15. bool isPrime(int x) {
  16.     if (x == 1 || x == 2 || x == 3) return true;
  17.     else for (int i = 2; i < sqrt(x)+1; i++) if (x % i == 0) return false;
  18.     return true;
  19. }
  20.  
  21. void process() {
  22.     resp = 0;
  23.     for (int i = 0; i < strlen(word); i++) {
  24.         if (islower(word[i])) resp += ((int) (word[i]-96));
  25.         else if (isupper(word[i])) resp += ((int) (word[i]-38));
  26.     }
  27.  
  28.     if (isPrime(resp)) printf("It is a prime word.\n");
  29.     else printf("It is not a prime word.\n");
  30. }
  31.  
  32. int main() {
  33.     while(read()) process();
  34. }
Add Comment
Please, Sign In to add comment