Page 2 of 10
Posted: Wed Apr 09, 2003 3:54 am
by rodriwan
what am I doing wrong?
Thought a lot and cant see what is the problem with this code...
[c]
#include <stdio.h>
#include <ctype.h>
#define MAX(x, y) ( (x) > (y) ) ? (x) : (y)
#define MIN(x, y) ( (x) < (y) ) ? (x) : (y)
int
main(void)
{
int r1, r2, sum, i;
float res, min, max;
char str1[256], str2[256], c;
while (fgets(str1, 256, stdin) &&
fgets(str2, 256, stdin)) {
r1 = r2 = 0;
for (i = 0; str1; ++i) {
c = tolower(str1);
if (c >= 'a' && c <= 'z')
r1 += (c - 'a'+1);
}
for (i = 0; str2; ++i) {
c = tolower(str2);
if (c >= 'a' && c <= 'z')
r2 += (c - 'a'+1);
}
while (r1 > 9) {
sum = 0;
while (r1 > 0) {
sum += r1%10;
r1 /= 10;
}
r1 = sum;
}
while (r2 > 9) {
sum = 0;
while (r2 > 0) {
sum += r2%10;
r2 /= 10;
}
r2 = sum;
}
min = (float) MIN(r1, r2);
max = (float) MAX(r1, r2);
res = 100.0 * (min / max);
printf("%.2f\n", res);
}
return 0;
}
[/c]
thanks
Posted: Thu Apr 10, 2003 6:29 am
by soyoja
If max = min = 0, then what value printed?
I think that there is a trap.
10424 why wrong anz plz help me
Posted: Tue Nov 04, 2003 8:56 am
by bayzid
/* @JUDGE_ID: xxxxxx 10424 C++ */
I think this program is correct but judge reply wrong ans.anyone help me?
#include<stdio.h>
#include<string.h>
#include<math.h>
main()
{
char get1[26],c;
char get2[26];
while(scanf("%s%s",get1,get2)!=EOF)
{
int x[26],l=0,l1=0;
for(int i=0;i<26;i++)
x=0;
for(i=0;i<strlen(get1);i++)
{
if(get1>='a'&&get1<='z')
l=l+(get1-96);
if(get1>='A'&&get1<='Z')
l=l+(get1-64);
}
for(i=0;i<strlen(get2);i++)
{
if(get2>='a'&&get2<='z')
l1=l1+(get2-96);
if(get2[i]>='A'&&get2[i]<='Z')
l1=l1+(get2[i]-64);
}
int l2=0,store=0;
A:
while(l!=0)
{
l2=l2+fmod(l,10);
l=l/10;
}
if(l2>9)
{
l=l2;
l2=0;
goto A;
}
int l3=0;
B:
while(l1!=0)
{
l3=l3+fmod(l1,10);
l1=l1/10;
}
if(l3>9)
{
l1=l3;
l3=0;
goto B;
}
float sto;
if(l2>l3)
{
sto=(float (l3)/float (l2))*100;
printf("%.2f %\n",sto);
sto=0;
}
else
{
sto=(float (l2)/float (l3))*100;
printf("%.2f %\n",sto);
sto=0;
}
}
}[/u]
Posted: Thu Jan 22, 2004 1:22 pm
by babor
Hai guy,
I didn't analyze ur code but I also suffered much with this problem.
I think you should be conscious abt taking input. And you have to
check the condition fulfilled (I did mistake on proble specification).
I am not sure abt ur mistake.
Thanks.
Posted: Tue Jan 27, 2004 2:46 pm
by WR
If both values are zero simply output an empty line.
I got AC that way.
Posted: Thu Apr 15, 2004 6:41 am
by minskcity
My code is basicly the same as rodriwan's... And I'm getting WA too, even after printing a new line in case n1 = n2 = 0. Is there any other tricky inputs???
[cpp]#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
string s;
long n1, n2, h;
int main(){
while(getline(cin, s)){
n1 = n2 = 0;
for(unsigned long i = 0; i < s.size(); i++) s = tolower(s);
for(unsigned long i = 0; i < s.size(); i++)
if(s >= 'a' && s <= 'z') n1 += s - 'a' + 1;
while(n1 > 10){
h = 0;
while(n1){
h += n1%10;
n1 /= 10;
}
n1 = h;
}
getline(cin, s);
for(unsigned long i = 0; i < s.size(); i++) s = tolower(s);
for(unsigned long i = 0; i < s.size(); i++)
if(s >= 'a' && s <= 'z') n2 += s - 'a' + 1;
while(n2 > 10){
h = 0;
while(n2){
h += n2%10;
n2 /= 10;
}
n2 = h;
}
cout.setf(ios::fixed);
cout.precision(2);
if(!(n1 + n2)) cout << endl;
else if(n1 < n2) cout << 100*((double)n1)/((double)n2) << " %\n";
else cout << 100*((double)n2)/((double)n1) << " %\n";
}
return 0;
}
[/cpp]
10424 WA
Posted: Sat May 08, 2004 5:51 pm
by Rui [pOsSuId0]
Hi, everyone, I'm getting furious

with this problem (10424) Love Calculation.
Why do I get wrong answer??
When both sums are 0, i output an empty new line.
and I put the right value, otherwise.
I would like to know, if there is any problem with the input (blank lines,...etc)
If someone can help me with this "very simple" problem, I'll apreciate??
Thank you~
Cases:
Input (%19823@#2 && /&7667672=
10424 Love Calculator
Posted: Fri Jun 04, 2004 5:43 pm
by cytmike
What happened to my code that gets WA....
[cpp]
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string p,h;
while (cin>>p>>h)
{
int l=0,i=0;
for (int y=0;y<p.length();y++)
if ((p[y]-'A'>=0)&&(p[y]-'A'<=25))
l+=p[y]-'A'+1;
else if ((p[y]-'a'>=0)&&(p[y]-'a'<=25))
l+=p[y]-'a'+1;
while (l>10)
l=l/100+l/10%10+l%10;
for (int y=0;y<h.length();y++)
if ((h[y]-'A'>=0)&&(h[y]-'A'<=25))
i+=h[y]-'A'+1;
else if ((h[y]-'a'>=0)&&(h[y]-'a'<=25))
i+=h[y]-'a'+1;
while (i>10)
i=i/100+i/10%10+i%10;
if ((i==0)&&(l==0)) cout<<endl;
else if (i>l)
cout<<setiosflags(ios::showpoint|ios::fixed)<<setprecision(2)<<100.0*(double)l/(double)i<<" %"<<endl;
else cout<<setiosflags(ios::showpoint|ios::fixed)<<setprecision(2)<<100.0*(double)i/(double)l<<" %"<<endl;
}
return 0;
} [/cpp]
Posted: Sat Jun 05, 2004 4:49 am
by cytmike
solved!!!

10424-what's wrong?? why W.A??
Posted: Mon Jun 07, 2004 1:01 am
by vut
i don't kn#include<stdio.h>
#include<string.h>
#define S 50
int C[300];
void Initilization()
{
int i,j,k;
memset(C,0,sizeof(C));
k=1;
for(i=65,j=97;i<91;i++,j++)
{
C=k;
C[j]=k++;
}
}
int main()
{
int l,m;
int i,j,k;
double x,y,z;
char s1[S],s2[S],ch;
ch='%';
Initilization();
while(gets(s1))
{
gets(s2);
l=0;
m=0;
j=strlen(s1);
for(i=0;i<j;i++)
if(C[s1]>0)
l+=C[s1];
j=strlen(s2);
for(i=0;i<j;i++)
if(C[s2]>0)
m+=C[s2];
y=0;
while(m>10)
{
y=0;
while(m>0)
{
y+=m%10;
m=m/10;
}
m=(int)y;
}
z=0;
while(l>10)
{
z=0;
while(l>0)
{
z+=l%10;
l=l/10;
}
l=(int)z;
}
/*while(m>10)
m=m/100+m/10%10+m%10;
while(l>10)
l=l/100+l/10%10+l%10;*/
//y=(double)m;
//z=(double)l;
if(z>y)
x=(100*y)/z;
else if(z<y)
x=(100*z)/y;
else if(y==z)
x=100.00;
printf("%.2lf %c\n",x,ch);
}
return 0;
}ow why it get W.A............[cpp][/cpp]
Posted: Mon Jun 21, 2004 11:23 pm
by pavelph
Sorry, I didn't read you code. But today I get accepted for this problem after some WAs. My mistake was that program hadn't worked with words like
- sum of their "characters" is 0 and you must to find 0/0.
Realy in this case you should output clear line.
Posted: Sat Oct 23, 2004 5:48 am
by abhijit
cin.getline(b,25);
scanf("%s",b);
Have u submitted these two lines as-is ? Then, that might be the problem.
Posted: Sun Dec 12, 2004 3:00 am
by Dani Rodrigo
Hi,
I received many times WA because I use to read scanf ("%s",a) to get the names. This have a problem, when it finds a space, it stops reading.
Finally I got AC usint scanf ("%[^\n]");
Posted: Fri Dec 17, 2004 9:09 pm
by Niaz
Use gets() to take inputs.
Posted: Sat Jan 01, 2005 3:40 pm
by MrED
I did the same mistake as minskcity did.
His sum is wrong because 10 is a final sum for him.
Consider input
EE
E
His answer would be
50.00 %
But correct would be:
20.00 %
Greetings, Rene