## 10424 - Love Calculator

Moderator: Board moderators

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

### 10424 WA

I got WA on problem 10424
Here are my method.

1. If scan EOF return 0
2. If line one = line two = 0 print a blank line
3. If line one = 0 or line two = 0 print 0.00%
4. If line one <= line two print 100.00%
5. Else print line two / line one

Can some tell me where is wrong?

Eddie
New poster
Posts: 2
Joined: Sat Feb 18, 2006 7:45 am

### 10424

I can't solve a simple portion of 10424.........the last portion of the problem tells that to add a no. like this---------if the no. is 999 then 9+9+9=27.again 2+7=9.then stop CAN ANY ONE HELP ME......................
shuvo

Eddie
New poster
Posts: 2
Joined: Sat Feb 18, 2006 7:45 am

### 10424

I can't solve a simple portion of 10424.........the last portion of the problem tells that to add a no. like this---------if the no. is 999 then 9+9+9=27.again 2+7=9.then stop how could I solve it...CAN ANY ONE HELP ME......................
shuvo

Donotalo
Learning poster
Posts: 56
Joined: Sat Aug 20, 2005 11:05 am

### 10424 - PE

my output code:

Code: Select all

``````if (!n1 || !n2)
cout << endl;
else if (n1 < n2)
printf("%.2f%%\n", 100*double(n1)/n2);
else
printf("%.2f%%\n", 100*double(n2)/n1);
``````
i'm getting PE, why?

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
You are missing a space character. But I am not sure why this works - maybe there are no cases with n1 or n2 being zero.

Donotalo
Learning poster
Posts: 56
Joined: Sat Aug 20, 2005 11:05 am
yes, u r right. there is a space character missing.

but i dont understand what u didnt understand! if any n is 0, i think there shud be a blank line?

i tried with 0.00% (not 0.00 %) too and got PE. probably both works.

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
In my solution I print "100.00 %" for both being 0. And "0.00 %" if one of them is zero. So there are probably no cases where either of them is zero.

Tahasin
New poster
Posts: 6
Joined: Tue Jun 27, 2006 7:19 am

### 10424

#include<iostream>
using namespace std;
#include<stdio.h>
#include<string.h>
int sum2(int p)
{
int q,s=0;
do
{
q=p%10;s+=q;p/=10;
}while(p!=0);
return s;
};
int sum1(char a[100])
{
int i,m,l,n=0;
for(i=0;a!='\0';i++)
{
m=a-'a'+1;
if(m>0)l=m;
else l=m+32;
if(l>=1 && l<=26)n+=l;
}
return n;
};
main()
{
char k[100],t[100];
int x,y,z;
float e,f,g;
while(cin>>k>>t)
{
x=sum1(k);
y=sum1(t);
do{x=sum2(x);}while(x>9);
do{y=sum2(y);}while(y>9);
if(x>y){e=x;f=y;}
else {e=y;f=x;}
g=(f/e)*100;
printf("%.2f %%\n",g);
}
return 0;
}

Iffat
New poster
Posts: 25
Joined: Sat Jul 22, 2006 9:47 am

### 10424..TLE!!

Code: Select all

``````#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
int findnum(char str[])
{
long i,j,l;
int s;
l=strlen(str);
i=0;s=0;
while(i<l)
{

if(str[i] > 96 && str[i] <123)
{
j = str[i]-96;
s = s + j ;
i++;
}
else if(str[i] > 64 && str[i] < 91)
{
j= str[i] -64 ;
s = s + j;
i++;
}

else if(str[i]=='\0'){i++;}
}
return s;
}
int main()
{
char str1[30],str2[30],str3[30],str4[30];
int tt,ttt,l1,l2;
int t,t1,t2,t3,ss,sss;
while(gets(str1))
{
gets(str2);
t1=	findnum(str1);
t=t1;
while(t>9)
{
sprintf(str3,"%d",t);
l1=strlen(str3);
ss=0;
for(tt=0;tt<l1;tt++)
{
ss=((str3[tt]-'0')+ss);
}
t=ss;
}
t2=findnum(str2);
t3=t2;
while(t3>9)
{
sss=0;
sprintf(str4,"%d",t3);
l2=strlen(str4);
for(ttt=0;ttt<l2;ttt++)
{
sss=((str4[ttt]-'0')+sss);
}
t3=sss;
}

double ratio;

if(isalpha(str1[0])!=0&&isalpha(str2[0])!=0)
{
if(t3>=t)
{
ratio=((double)t/t3)*100;
printf("%.2lf %c\n",ratio,'%');
}
else if(t3<t)
{
ratio=((double)t3/t)*100;
printf("%.2lf %c\n",ratio,'%');
}
else if(t==0||t3==0)printf("\n");
}
else
{
printf("\n");
}

}
return 0;
}``````
i can't find wats wrong in my code...i got TLE...plzzzz help me

ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am

### 10424

Last edited by ishtiaq ahmed on Sat Mar 03, 2007 1:06 pm, edited 5 times in total.

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am

### Re: WA(10424)LOVE CALCULATOR?

ishtiaq ahmed wrote:printf("%.2f % \n",res);
This line looks abit fishy to me. Try

Code: Select all

``printf("%.2f %s\n",res,"%"); ``

newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Contact:
Have you checked those forum before posting your problem?

http://online-judge.uva.es/board/viewtopic.php?t=7600,
http://online-judge.uva.es/board/viewtopic.php?t=2497 and
http://online-judge.uva.es/board/viewtopic.php?t=2166)

always tray to seek your solution first if dont get then post.

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Also, this post should go in Volume CIV.

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm
daveon wrote:Also, this post should go in Volume CIV.
Done.

To print a percentage sign with printf you can also use a doubled one in the format string:

Code: Select all

``printf("%.2f %%\n",res);``

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am