Code: Select all
deleted..
Moderator: Board moderators
Code: Select all
deleted..
Code: Select all
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
/*
bool isupper(char x){
return (x >= 'A' && x <= 'Z')? true: false;
}
*/
int value(char x){
if(isupper(x))
return x-38;
return x-96;
}
bool isprime(int n){
if(n == 0 || n == 1) return true;
for(int i=2; i<n/2; i++){
if(n % i == 0)
return false;
}
return true;
}
int main(int argc, char **argv){
string word;
int sum;
while(getline(cin, word)){
if(word.empty()) break;
sum = 0;
for(int i=0; i<word.size(); i++){
sum += value(word[i]);
}
if(isprime(sum))
cout << "It is a prime word." << endl;
else
cout << "It is not a prime word." << endl;
}
return 0;
}
BTW: are you sure you want isprime() to work this way? According to it 0 and 1 are prime, so is 4. I don't think you'll get AC with that.shines wrote:Code: Select all
#include <iostream> bool isprime(int n){ if(n == 0 || n == 1) return true; for(int i=2; i<n/2; i++){ if(n % i == 0) return false; } return true; }
Code: Select all
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
#undef isupper
bool isupper(char x){
return (x >= 'A' && x <= 'Z')? true: false;
}
int value(char x){
if(isupper(x))
return x-38;
return x-96;
}
... etc.
Btw, it's too slow, although it may pass for that particular problem.Krzysztof Duleba wrote:BTW: are you sure you want isprime() to work this way? According to it 0 and 1 are prime, so is 4. I don't think you'll get AC with that.shines wrote:Code: Select all
#include <iostream> bool isprime(int n){ if(n == 0 || n == 1) return true; for(int i=2; i<n/2; i++){ if(n % i == 0) return false; } return true; }
you are right. I make a mistake there. So I got WA after solve CE problem.Krzysztof Duleba wrote:BTW: are you sure you want isprime() to work this way? According to it 0 and 1 are prime, so is 4. I don't think you'll get AC with that.shines wrote:Code: Select all
#include <iostream> bool isprime(int n){ if(n == 0 || n == 1) return true; for(int i=2; i<n/2; i++){ if(n % i == 0) return false; } return true; }