Page 4 of 10
10424 WA
Posted: Sun Feb 19, 2006 11:30 am
by Wei-Ming Chen
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?
10424
Posted: Thu Mar 02, 2006 8:01 am
by Eddie
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......................
10424
Posted: Thu Mar 02, 2006 8:03 am
by Eddie
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......................
10424 - PE
Posted: Fri Aug 04, 2006 7:55 pm
by Donotalo
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?
Posted: Fri Aug 04, 2006 8:18 pm
by Darko
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.
Posted: Fri Aug 04, 2006 8:24 pm
by Donotalo
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.
Posted: Fri Aug 04, 2006 9:03 pm
by Darko
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.
10424
Posted: Thu Aug 17, 2006 1:54 pm
by Tahasin
#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;
}
10424..TLE!!
Posted: Mon Aug 21, 2006 3:52 pm
by Iffat
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

10424
Posted: Sat Aug 26, 2006 6:15 am
by ishtiaq ahmed
Re: WA(10424)LOVE CALCULATOR?
Posted: Thu Aug 31, 2006 2:48 am
by daveon
ishtiaq ahmed wrote:printf("%.2f % \n",res);
This line looks abit fishy to me. Try
Posted: Wed Sep 06, 2006 12:25 pm
by newton
Posted: Sat Sep 09, 2006 10:57 pm
by daveon
Also, this post should go in Volume CIV.
Posted: Sat Sep 09, 2006 11:38 pm
by little joey
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:
Posted: Wed Sep 13, 2006 4:03 am
by daveon
Ah, so the % is the escape character. Cool! Thanks little Joey, your code is shorter.