Page 3 of 3

### Re: 10924 - Prime Words

Posted: Thu Jun 17, 2010 8:35 pm
Hey plz help me...um getting WA...here is my code...please check it..

Code: Select all

``````#include<iostream>
using namespace std;
int j;
bool prime_check(int p)
{
if(p == 1) return false;
else if(p == 2) return true;
else if(p%2==0) return false;
else if( p > 2)
for(j=3; j*j<=p; j += 2)
if( p%j == 0){ return false; break;}

return true;
}

int main()
{
char simon;
int c=0,i,sum=0;
while(cin.getline(simon,21,'\n'))
{
sum=0;
for(i=0;simon[i]!='\0';i++)
{
if(simon[i] >='A' && simon[i] <= 'Z'){sum += (simon[i]-38);}
if(simon[i] >='a' && simon[i] <= 'z') {sum += (simon[i]-96);}
}

if(prime_check(sum)) printf("It is a prime word.");

else printf("It is not a prime word.");

}

return 0;
}
``````

### Re: 10924 - Prime Words

Posted: Thu Jun 17, 2010 9:46 pm
I got AC....1 should take as a prime number here... ### Re: 10924 - Prime Words

Posted: Mon Mar 14, 2011 12:32 am
I think the only thing we should take case for this problem is that "1 is prime".

### 10924 - spelling error

Posted: Sat Dec 08, 2012 12:42 pm
Hi,
There is a spelling error in the input section of the problem 10924 - "Prime Words" it says
input is terminated by enf of file
while it should be :
input is terminated by end of file
So, I request editing the problem statement to correct the spelling error
Thanks in regards.

### Re: 10924 - Prime Words

Posted: Fri Feb 15, 2013 7:31 pm

Code: Select all

``````The only tricky test case for this problem is 1 is considered as prime number which has been stated on the top of the problem.
" A prime number is a number that has only two divisors: itself and the number one. Examples of prime numbers are: 1, 2, 3, 5, 17, 101 and 10007."``````

### Re: 10924 - Prime Words

Posted: Sun Nov 24, 2013 3:33 pm
As the problem statement is a prime number has only two divisors (1 and itself) , 1 should not be added to the list of prime numbers....

### Re: 10924 - Prime Words

Posted: Tue Nov 26, 2013 2:39 am
1 is a prime in this problem, so a is a prime word.

### Re: 10924 - Prime Words

Posted: Fri Jan 10, 2014 7:21 pm
I was trying to say that the problem statement is contradictory...

### Re: 10924 - Prime Words

Posted: Sat Apr 12, 2014 8:54 am

### 10924 - Prime Words

Posted: Mon Jul 07, 2014 10:59 pm
i have tested many case.
this code have passed successfully.
but got WA.

Code: Select all

``````#include <stdio.h>
char prime(int n)
{
int a;
char re;
double remainder;
for(a=2; a<n; a++)
{
remainder=n%a;
if(remainder==0)
{
break;
}
}
if(remainder==0)
{
re = 'n';
}
else
{
re='p';
}

return re;
}

int char_num(char a)
{
int num;
if(a>='a'&&a<='z')
{
num= a-96;
}
else num = a-38;
return num;
}

int main()
{
char a;
while(gets(a))
{
int n, total=0;
for(n=0; n<20; n++)
{
if(a[n]=='\0') break;
else
{
total=total + char_num(a[n]);
}
}
char ch = prime(total);
if(ch=='p') printf("It is a prime word.");
else printf("It is not a prime word.");
printf("\n");
}
return 0;
}
``````

what's wrong with is code.

### Re: 10924 - Prime Words

Posted: Tue Jul 08, 2014 10:55 pm
Try solving it without using floating point.

### Re: 10924 - Prime Words

Posted: Tue Aug 26, 2014 10:16 pm
Help Me please getting WA ! :'(

Code: Select all

``````#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
#define ll long long
#define MAX 1000007
bool a[MAX];
void isPrime()
{
ll i,j;
for(i=3;i*i<=MAX;i+=2)
{
if(a[i]==false){
for(j=i*i;j<=MAX;j+=i+i){
a[j]=true;
}
}

}
}
bool checkprime(ll n)
{
if(n<1)  return false;
else if(n==1) return true;
else if(n==2) return true;
else if(n%2==0) return false;
else return a[n]==false;
}

int main()
{
ll p,q,r,s,i,j,k,sum;
isPrime();
string ss;

while(!cin.eof())

{

cin>>ss;
sum=0;
for(i=0;i<ss.size();i++)
{
if(isupper(ss[i]))
sum+=(ll)(ss[i]-'A')+27;
else
sum+=(ll)(ss[i]-'a')+1;

}

if(checkprime(sum))
cout<<"It is a prime word."<<endl;
else
cout<<"It is not a prime word."<<endl;

}

return 0;
}

``````

### Re: 10924 - Prime Words

Posted: Wed Aug 27, 2014 7:43 pm
Don't use cin.eof(), there will be a newline char at the end of the last line. Use something like this instead:
while(cin >> ss)

### Re: 10924 - Prime Words

Posted: Fri Jan 23, 2015 8:34 pm
prob:10924.......it's getting WA.....

Code: Select all

``````#include<stdio.h>
int main()
{
char str;
int i,sum,count;
while((scanf("%s",&str))!=EOF)
{
sum=0;
for(i=0;str[i]!='\0';i++)
{
if(str[i]>='a'&&str[i]<='z')
{
sum=sum+str[i]-'a'+1;

}
else
{
sum=sum+str[i]-'A'+27;
}
}
count=0;
for(i=2;i<=sum/2;i++)
{
if(sum%i==0)
{
count++;
break;
}
}
if(count==0||sum==1)
{
printf("It is a prime word\n");
}
else if(count==1)
{
printf("It is not a prime word\n");
}

}
}``````

### Re: 10924 - Prime Words

Posted: Sat Jan 24, 2015 7:34 am
You are missing the period at the end of each line.