## 10424 - Love Calculator

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

Moderator: Board moderators

### 10424 - Love Calculator

I think it's a easy problem and I got AC when I submit first. But after REJUDGEMENT. The judge tell me that my code is wrong?
Can u tell me why? thank u?
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int chartonum(char *c)
{
int len=strlen(c);
int i;
int result=0;
for(i=0;i<len;i++)
{
if(c[i]>='a' && c[i]<='z')
result+=c[i]-'a'+1;
if(c[i]>='A' && c[i]<='Z')
result+=c[i]-'A'+1;
}
while(result>=10)
{
int temp=0;
while(result)
{
temp+=result%10;
result=result/10;
}
result=temp;
}
return result;
}

int main()
{
char a[30],b[30];
while(cin.getline(a,25))
{
double r;
//cin.getline(a,25);
cin.getline(b,25);
scanf("%s",b);
int numa=chartonum(a);
int numb=chartonum(b);
if(numa==numb)
r=1.0;
else if(numa>numb)
r=double(numb)/(double)(numa);
else
r=double(numa)/(double)(numb);
r=r*100.0;
cout.setf(ios::fixed);
cout.precision(2);
cout<<r<<" %"<<endl;
}

return 0;
}
galois_godel
New poster

Posts: 17
Joined: Wed Jul 17, 2002 5:00 pm

### 10424 Wrong Answer (Rejudgement) Why?

I think it's a easy problem and I got AC when I submit first. But after REJUDGEMENT. The judge tell me that my code is wrong?
Can u tell me why? thank u?
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int chartonum(char *c)
{
int len=strlen(c);
int i;
int result=0;
for(i=0;i<len;i++)
{
if(c[i]>='a' && c[i]<='z')
result+=c[i]-'a'+1;
if(c[i]>='A' && c[i]<='Z')
result+=c[i]-'A'+1;
}
while(result>=10)
{
int temp=0;
while(result)
{
temp+=result%10;
result=result/10;
}
result=temp;
}
return result;
}

int main()
{
char a[30],b[30];
while(cin.getline(a,25))
{
double r;
//cin.getline(a,25);
cin.getline(b,25);
scanf("%s",b);
int numa=chartonum(a);
int numb=chartonum(b);
if(numa==numb)
r=1.0;
else if(numa>numb)
r=double(numb)/(double)(numa);
else
r=double(numa)/(double)(numb);
r=r*100.0;
cout.setf(ios::fixed);
cout.precision(2);
cout<<r<<" %"<<endl;
}

return 0;
}
galois_godel
New poster

Posts: 17
Joined: Wed Jul 17, 2002 5:00 pm

Hi,

This problem seems easy but i think i have excatly the same problem as u.
Is there any special case to consider, or is it a precision problem
Any tip or I/O data appreciated
Thanks
Bistromath
New poster

Posts: 16
Joined: Fri Oct 11, 2002 11:03 pm
Location: France

galois_godel, I tried to grab your code and ran it ... It looks like something is wrong when you're reading the input (words) ...

I tried with simple input file containing:
saima
shanto

Your solution returned correct answer:
71.43 %

However, just added two more words:
saima
shanto
Pakistan
India

Your solution failed:
14.29 % ==> Looks like the love-ration between saima and Pakistan!
0.00 %

Oh yes, and one more thing that we need to be very careful, the input-description doesn't mention that each word will be in a line by itself.

-turuthok-
turuthok
Experienced poster

Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia

turuthok wrote:
Oh yes, and one more thing that we need to be very careful, the input-description doesn't mention that each word will be in a line by itself.

-turuthok-

I though about that case but problem description also says that a word can contain white spaces.
how do you consider such a line :
a a b b ?

"a a" and "b b" or
"a","a" and "b","b" ?
Bistromath
New poster

Posts: 16
Joined: Fri Oct 11, 2002 11:03 pm
Location: France

Bistromath, you are correct ... please ignore my last paragraph there ... I checked my AC code again ... it also reads one word per line ...

Sorry about that.

-turuthok-
turuthok
Experienced poster

Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia

galois_godel, try to remove or comment out your 'scanf' ... it might work.

-turuthok-
turuthok
Experienced poster

Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia

### also help me,please

i also meet the same proble..my code is :
[pascal]
var
table:array[0..128] of integer;
in1,in2:string;
sum1,sum2:integer;

procedure init();

var
i,x:integer;

begin
for i:=0 to 128 do
table[i]:=0;

x:=64;
for i:=1 to 26 do
table[x+i]:=i;
x:=96;

for i:=1 to 26 do
table[x+i]:=i;
end;

function len(i:integer):integer;
var
len,tem:integer;
begin
len:=1;
tem:=i;
while(tem>9) do
begin
inc(len);
tem:=tem div 10;
end;
len:=len;
end;

function getsum(s:String):integer;
var
i,tem,l:integer;

begin
tem:=0;
i:=1;
l:=length(s);

for i:=1 to l do
tem:=tem+table[ord(s[i])];
getsum:=tem;
end;

function getresult(i:integer):integer;
var
tem,x,j:integer;
begin
tem:=i;
x:=0;

while(tem>9) do
begin
if(tem>9) then
begin
for j:=0 to len(tem) do
begin
x:=x+tem mod 10;
tem:=tem div 10;
end;
tem:=x;
x:=0;
end;
end;
getresult:=tem;
end;

begin
init();
WHILE(NOT EOF) DO
begin
readln(in1);
readln(in2);
sum1:=getsum(in1);
sum1:=getresult(sum1);
sum2:=getsum(in2);
sum2:=getresult(sum2);
if(sum1>sum2) then
writeln(sum2/sum1*100:0:2,' %')
else writeln(sum1/sum2*100:0:2,' %');
end;

end.
Code: Select all
` plseae help me...thank you very much!`
liusu
New poster

Posts: 22
Joined: Thu Aug 01, 2002 10:26 am

### Check

It's so easy problem. Check your code ... debug it.
it's also easy to find out inputs and outputs for this problem. so, find some others inputs and calculate the output urself 1st.. then check with ur program...

Best of LUCK...
Sajid Online: www.sajidonline.com
Sajid
Learning poster

Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.

### 10424 WA HEEEEEEEELLLPPPPP plzzzzzzzz

I cant find any wrong in this....... :o

#include<stdio.h>
#include<string.h>

void main()
{
int i,j,sum1=0,sum2=0;
double digit1=0.0,digit2=0.0,per;
char name1[30],name2[30];

while(gets(name1) && gets(name2))
{

for(i=0;i<strlen(name1);i++)
{
if(name1[i]>='A'&&name1[i]<='Z')
sum1+=name1[i]-'A'+1;
if(name1[i]>='a'&&name1[i]<='z')
sum1+=name1[i]-'a'+1;

}
for(i=0;i<strlen(name2);i++)
{

if(name2[i]>='A'&&name2[i]<='Z')
sum2+=name2[i]-'A'+1;
if(name2[i]>='a'&&name2[i]<='z')
sum2+=name2[i]-'a'+1;
}

if(sum1==0)digit1=0.0;
if(sum2==0)digit2=0.0;
while(sum1>0)
{
digit1+=float(sum1%10);
if(digit1>9){sum1=int(digit1);digit1=0;}
else sum1=sum1/10;

}
while(sum2>0)
{
digit2+=float(sum2%10);
if(digit2>9){sum2=int(digit2);digit2=0;}
else sum2=sum2/10;

}
if(digit1>=digit2)
{
per=(digit2/digit1)*100;
printf("%.2f %%\n",per);
}
else if(digit2>=digit1)
{
per=(digit1/digit2)*100;
printf("%.2f %%\n",per);
}

digit1=0.0;digit2=0.0;sum1=0;sum2=0;
//memset(name1,0,sizeof(name1)-1);
//memset(name2,0,sizeof(name2)-1);
}
}

Angel
New poster

Posts: 8
Joined: Wed Nov 20, 2002 3:49 pm

### test

test

Angel
New poster

Posts: 8
Joined: Wed Nov 20, 2002 3:49 pm

### 10424.... the poor love calculator.

[cpp]
#include <stdio.h>
#include <string.h>
struct shit{
char name[26];
int n_value;
int len_name;
};
int die1,die2;
shit n1,n2;
int i;
double ans;
void main(void)
{
while (1)
{
ans=0;
gets(n1.name);
if (feof(stdin))
break;
gets(n2.name);
if (feof(stdin))
break;
n1.len_name =strlen(n1.name );
n2.len_name =strlen(n2.name );
for (i=0;i<n1.len_name ;i++)
if (n1.name[i]>=65 && n1.name [i]<=90)
n1.name [i]+=32;
for (i=0;i<n2.len_name ;i++)
if (n2.name[i]>=65 && n2.name [i]<=90)
n2.name [i]+=32;
die1=0;
for (i=0;i<n1.len_name ;i++)
{
if ((n1.name [i]>=65 && n1.name[i] <=90)||(n1.name[i]>=97 && n1.name[i]<=122))
{
die1=1;
break;
}
}
die2=0;
for (i=0;i<n2.len_name ;i++)
{
if ((n2.name [i]>=65 && n2.name[i] <=90)||(n2.name[i]>=97 && n2.name[i]<=122))
{
die2=1;
break;
}
}
n1.n_value =0;
for (i=0;i<n1.len_name ;i++)
{
if (n1.name[i]>=97 && n1.name[i]<=122)
n1.n_value +=n1.name[i]-96;
}
n2.n_value =0;
for (i=0;i<n2.len_name ;i++)
{
if (n2.name[i]>=97 && n2.name[i]<=122)
n2.n_value +=n2.name[i]-96;
}

for (i=0;i<=5;i++)
{
if (n1.n_value >=10 && n1.n_value <=99)
{
n1.n_value =n1.n_value/10+n1.n_value % 10;
}
if (n1.n_value >=100 && n1.n_value <=600)
{
n1.n_value =n1.n_value /100+((n1.n_value /10) % 10)+n1.n_value % 100;
}

if (n2.n_value >=10 && n2.n_value <=99)
{
n2.n_value =n2.n_value/10+n2.n_value % 10;
}
if (n2.n_value >=100 && n2.n_value <=600)
{
n2.n_value =n2.n_value /100+((n2.n_value /10) % 10)+n2.n_value % 100;
}

}
if (n1.n_value >n2.n_value )
ans=n2.n_value /(double)n1.n_value;
else
ans=n1.n_value /(double)n2.n_value;

ans*=100;

if (die1==0 || die2==0)
printf("0.00 ");
else
printf("%0.2f ",ans);
printf("%%\n");
}
}

[/cpp]

if the ratio of the result is more than 1, say x, i take 1/x...
if user only input rubbish charactar in one of the name...
the result will be 0.00 %....

am i right?

any other rules that i havent consider?

i got a WA..
pls help me to take a look.
SilVer DirectXer
New poster

Posts: 39
Joined: Wed Jan 22, 2003 11:02 am

hello.

the problem-statement states that only the alphabetic characters have values. so if you get any other character, then ASCII code for that character should NOT be added.

if you haven't got AC yet, hope this helps.
Adil
Learning poster

Posts: 57
Joined: Sun Sep 29, 2002 12:00 pm
Location: in front of the monitor :-)

What a complicated program and so long for such a problem!! You should start again and think in a simple way..

For ratio, the problem is for 2 numbers A and B to calculate (A/B)*100 si A is smaller than B and (B/A)*100 if B smaller than A...[/java]
Calvin
New poster

Posts: 5
Joined: Sat Mar 08, 2003 12:50 pm

The code is so complicated. Think it so easily.
The ratio

if(a > b) b / a;
else a / b;
Syed Mubashshir Husain
New poster

Posts: 9
Joined: Wed Apr 02, 2003 10:28 am

Next

Return to Volume CIV

### Who is online

Users browsing this forum: No registered users and 1 guest