All about problems in Volume 109. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
sum_sim
New poster
Posts: 4 Joined: Fri May 21, 2010 12:13 pm
Post
by sum_sim » 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[21];
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;
}
sum_sim
New poster
Posts: 4 Joined: Fri May 21, 2010 12:13 pm
Post
by sum_sim » Thu Jun 17, 2010 9:46 pm
I got AC....1 should take as a prime number here...
DD
Experienced poster
Posts: 145 Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:
Post
by DD » Mon Mar 14, 2011 12:32 am
I think the only thing we should take case for this problem is that "1 is prime".
Have you ever...
Wanted to work at best companies ?
Struggled with interview problems that could be solved in 15 minutes?
Wished you could study real-world problems ?
If so, you need to read
Elements of Programming Interviews .
topboy1998
New poster
Posts: 1 Joined: Fri Oct 26, 2012 10:29 am
Post
by topboy1998 » 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.
alimbubt
New poster
Posts: 39 Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh
Contact:
Post
by alimbubt » 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."
triplemzim
New poster
Posts: 48 Joined: Sat Apr 06, 2013 6:02 pm
Post
by triplemzim » 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....
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Nov 26, 2013 2:39 am
1 is a prime in this problem, so a is a prime word.
Check input and AC output for thousands of problems on
uDebug !
triplemzim
New poster
Posts: 48 Joined: Sat Apr 06, 2013 6:02 pm
Post
by triplemzim » Fri Jan 10, 2014 7:21 pm
I was trying to say that the problem statement is contradictory...
uDebug
A great helper
Posts: 475 Joined: Tue Jul 24, 2012 4:23 pm
Post
by uDebug » Sat Apr 12, 2014 8:54 am
Replying to follow the thread.
arefinnomi
New poster
Posts: 1 Joined: Fri Mar 07, 2014 9:13 pm
Post
by arefinnomi » 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[20];
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.
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Jul 08, 2014 10:55 pm
Try solving it without using floating point.
Check input and AC output for thousands of problems on
uDebug !
musfiqur.cse
New poster
Posts: 10 Joined: Tue Dec 03, 2013 8:48 pm
Post
by musfiqur.cse » 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;
}
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » 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)
Check input and AC output for thousands of problems on
uDebug !
liya
New poster
Posts: 10 Joined: Fri Jan 23, 2015 2:36 pm
Post
by liya » Fri Jan 23, 2015 8:34 pm
prob:10924.......it's getting WA.....
Code: Select all
#include<stdio.h>
int main()
{
char str[20];
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");
}
}
}
Last edited by
brianfry713 on Fri Jan 23, 2015 9:40 pm, edited 1 time in total.
Reason: Added code blocks
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Sat Jan 24, 2015 7:34 am
You are missing the period at the end of each line.
Check input and AC output for thousands of problems on
uDebug !