10424 - Love Calculator

All about problems in Volume 104. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

rodriwan
New poster
Posts: 8
Joined: Mon Jun 03, 2002 8:13 pm

Post by rodriwan » Wed Apr 09, 2003 3:54 am

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:

Post by soyoja » Thu Apr 10, 2003 6:29 am

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
Location: bangladesh
Contact:

10424 why wrong anz plz help me

Post by bayzid » Tue Nov 04, 2003 8:56 am

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

User avatar
babor
New poster
Posts: 16
Joined: Sat Jun 07, 2003 4:23 pm
Contact:

Post by babor » Thu Jan 22, 2004 1:22 pm

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

Post by WR » Tue Jan 27, 2004 2:46 pm

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

Post by minskcity » Thu Apr 15, 2004 6:41 am

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

Post by Rui [pOsSuId0] » Sat May 08, 2004 5:51 pm

Hi, everyone, I'm getting furious :evil: 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~ :o

Cases:
Input (%19823@#2 && /&7667672=

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

10424 Love Calculator

Post by cytmike » Fri Jun 04, 2004 5:43 pm

:evil:
What happened to my code that gets WA....
:cry:

[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]

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

Post by cytmike » Sat Jun 05, 2004 4:49 am

solved!!! :D

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

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

Post by vut » Mon Jun 07, 2004 1:01 am

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

Post by pavelph » Mon Jun 21, 2004 11:23 pm

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

Post by abhijit » Sat Oct 23, 2004 5:48 am

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

Post by Dani Rodrigo » Sun Dec 12, 2004 3:00 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:

Post by Niaz » Fri Dec 17, 2004 9:09 pm

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

Post by MrED » Sat Jan 01, 2005 3:40 pm

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

Post Reply

Return to “Volume 104 (10400-10499)”