10424 - Love Calculator
Moderator: Board moderators
-
- 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?
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?
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
10424 - PE
my output code:
i'm getting PE, why?
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);

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;
}
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;
}
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;
}





-
- Learning poster
- Posts: 53
- Joined: Sat Jul 29, 2006 7:33 am
- Location: (CSE,DU), Dhaka,Bangladesh
10424
Last edited by ishtiaq ahmed on Sat Mar 03, 2007 1:06 pm, edited 5 times in total.
Re: WA(10424)LOVE CALCULATOR?
This line looks abit fishy to me. Tryishtiaq ahmed wrote:printf("%.2f % \n",res);
Code: Select all
printf("%.2f %s\n",res,"%");
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- 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.
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.
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
Done.daveon wrote:Also, this post should go in Volume CIV.
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);