## 10424 - Love Calculator

Moderator: Board moderators

rodriwan
New poster
Posts: 8
Joined: Mon Jun 03, 2002 8:13 pm
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

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:
If max = min = 0, then what value printed?

I think that there is a trap.

bayzid
New poster
Posts: 7
Joined: Sun Sep 14, 2003 8:09 am
Contact:

### 10424 why wrong anz plz help me

/* @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]
arahman

babor
New poster
Posts: 16
Joined: Sat Jun 07, 2003 4:23 pm
Contact:
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.
babor

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am
If both values are zero simply output an empty line.
I got AC that way.

minskcity
Experienced poster
Posts: 199
Joined: Tue May 14, 2002 10:23 am
Location: Vancouver
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]

Rui [pOsSuId0]
New poster
Posts: 1
Joined: Sat May 08, 2004 2:14 am
Location: Portugal, Pombal-Caparica
Contact:

### 10424 WA

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=

cytmike
Learning poster
Posts: 95
Joined: Mon Apr 26, 2004 1:23 pm
Location: Hong Kong and United States
Contact:

### 10424 Love Calculator

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]

cytmike
Learning poster
Posts: 95
Joined: Mon Apr 26, 2004 1:23 pm
Location: Hong Kong and United States
Contact:
solved!!!

vut
New poster
Posts: 1
Joined: Mon Jun 07, 2004 12:53 am

### 10424-what's wrong?? why W.A??

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]

pavelph
Learning poster
Posts: 57
Joined: Wed Dec 10, 2003 7:32 pm
Location: Russia, Saint-Petersburg
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

Code: Select all

``````@@
123``````
- sum of their "characters" is 0 and you must to find 0/0.
Realy in this case you should output clear line.

abhijit
New poster
Posts: 12
Joined: Mon May 24, 2004 2:13 pm
cin.getline(b,25);
scanf("%s",b);

Have u submitted these two lines as-is ? Then, that might be the problem.

Dani Rodrigo
New poster
Posts: 11
Joined: Sun Jul 18, 2004 1:39 am
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]");

Niaz
Learning poster
Posts: 77
Joined: Fri Dec 17, 2004 11:06 am
Location: East West University, Dhaka, Bangladesh
Contact:
Use gets() to take inputs.
Please join The ACM Solver Group at Yahoo
http://groups.yahoo.com/group/acm_solver/

MrED
New poster
Posts: 1
Joined: Sat Jan 01, 2005 3:35 pm
Location: Erlangen, Germany
I did the same mistake as minskcity did.

His sum is wrong because 10 is a final sum for him.

Consider input
EE
E