Page 7 of 10
Re: 10424 - Love Calculator
Posted: Fri Apr 13, 2012 8:39 pm
by shatil_cse
brianfry713 wrote:Doesn't match the sample I/O.
thanks for the REPLY .
I have got acc.
Re: 10424 - Love Calculator
Posted: Fri May 04, 2012 9:52 pm
by enamsustcse
#include <stdio.h>
#include <string.h>
int main()
{
int i, len1, len2, sum1, sum2, v, x, y, z, flag;
double ratio, s1, s2;
char a[30], b[30];
while(gets(a) && gets(b))
{
flag = 1;
sum1 = sum2 = 0;
len1 = strlen(a);
len2 = strlen(b);
for (i = 0; i < len1; ++i)
{
if(a >= 'a' && a <= 'z') sum1 += a - 'a' + 1;
else if(a >= 'A' && a <= 'Z') sum1 += a - 'A' + 1;
}
for (i = 0; i < len2; ++i)
{
if(b >= 'a' && b <= 'z') sum2 += b - 'a' + 1;
else if(b >= 'A' && b[i] <= 'Z') sum2 += b[i] - 'A' + 1;
}
//if ((sum1 == 0 && len1 == 0) && (sum2 == 0 && len2 == 0)) flag = 0;
if ((sum1 == 0 && len1 == 0) || (sum2 == 0 && len2 == 0))
{
sum1 = 0;
sum2 = 9;
}
else if(sum1 == 0 && sum2 == 0)
{
sum1 = 1;
sum2 = 1;
}
else if (sum2 == 0)
{
sum1 = sum1 % 9;
if (sum1 == 0) sum1 = 9;
sum2 = 9;
}
else if (sum1 == 0)
{
sum2 = sum2 % 9;
if (sum2 == 0) sum2 = 9;
sum1 = 9;
}
while (sum1 >= 10)
{
x = sum1 / 1000;
y = sum1 / 100;
z = sum1 / 10;
v = sum1 % 10;
sum1 = v + x + y + z;
}
while (sum2 >= 10)
{
x = sum2 / 1000;
y = sum2 / 100;
z = sum2 / 10;
v = sum2 % 10;
sum2 = v + x + y + z;
}
s1 = sum1;
s2 = sum2;
if (s1 > s2) ratio = 100 * s2 / s1;
else ratio = 100 * s1 / s2;
if(flag == 1) printf("%.2lf %c\n", ratio,'%');
else printf("\n");
}
return 0;
}
What is the rest case(s) that I did not considerin the code here??
plz help me....
Re: 10424 - Love Calculator
Posted: Tue May 08, 2012 12:01 am
by brianfry713
i can't understand that why wa, pls help me:
Posted: Sun May 20, 2012 10:23 am
by nest
#include<stdio.h>
//#include<conio.h>
#include<string.h>
float sum_s(int n,char s[]);
int main(){
int n1,n2,f;
double res;
char s1[30],s2[30];
while(gets(s1)){
gets(s2);
n1=strlen(s1);
n2=strlen(s2);
double s11=sum_s(n1,s1);
double s22=sum_s(n2,s2);
if(s11==0.00&&s22==0.00){
printf("\n");
}else{
if(s11>s22)
res=s22/s11*100;
else
res=s11/s22*100;
printf("%.2f %\n",res);
}
}
return 0;
}
float sum_s(int n,char s[]){
int x=0,sum=0,sm=0;
for(int i=0;i<n;i++){
if(s>='a'&&s<='z'){
x=s-'a'+1;
}
else if(s>='A'&&s=='Z'){
x=s-'A'+1;
}
sum+=x;
}
if(sum>9){
do{
while(sum!=0){
x=sum%10;
sm+=x;
sum/=10;
}
sum=sm;
sm=0;
}while(sum>9);
}
return sum;
}
Re: 10424 - Love Calculator
Posted: Mon May 21, 2012 11:05 pm
by brianfry713
Your code is printing a blank line for input:
Re: 10424 - Love Calculator
Posted: Fri May 25, 2012 12:08 am
by nest
thanks for reply
Re: 10424 - Love Calculator
Posted: Thu May 31, 2012 9:27 pm
by nest
i corrected it. but again WA
WHY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Re: 10424 - Love Calculator
Posted: Fri Jun 01, 2012 12:01 am
by brianfry713
post your updated code
Re: 10424 - Love Calculator
Posted: Tue Jul 10, 2012 6:39 pm
by sumon sarker
No error, No warning in my code. But why compilation error?? Please Help me!
Re: 10424 - Love Calculator
Posted: Tue Jul 17, 2012 3:22 am
by brianfry713
Check My Submissions and you can see the reason for your Compile Error.
Re: 10424 - Love Calculator
Posted: Sun Jan 06, 2013 12:40 pm
by mobarak.islam
Code Removed after getting Correct ans

Re: 10424 - Love Calculator
Posted: Mon Jan 07, 2013 3:28 am
by brianfry713
You need to read line by line, there may be white space in a name.
Re: 10424 - Love Calculator
Posted: Tue Jan 15, 2013 1:11 pm
by mobarak.islam
Thanks @ brianfry713 . I got the Accepted

Re: 10424 - Love Calculator
Posted: Fri Jan 18, 2013 9:15 pm
by enamsustcse
brianfry713 wrote:Input:
AC output:
Thanx boss. This test case helped me to find the bug in my code. there was a silly mistake in reducing the number to 1 digit.
Thanks a lot!!!

Re: 10424 - Love Calculator
Posted: Thu Jul 25, 2013 9:06 pm
by raihan_sust5
here is my code...i can''t why i am getting WA pls anyone help me..
#include<stdio.h>
#include<ctype.h>
#include<string.h>
float love_calculator (char str[]);
int main()
{
char str1[35], str2[35];
int count, num = 1;
float p1, p2, res;
while(num < 100000)
{
gets(str1);
gets(str2);
p1 = love_calculator(str1);
p2 = love_calculator(str2);
if (p1 > p2)
res = (p2 / p1) * 100;
else
res = (p1 / p2) * 100;
printf("%.2f %%\n", res);
++num;
}
return 0;
}
float love_calculator (char str[])
{
int div = 1, sum = 0,count = 0;
float bin;
while(str[count] != '\0')
{str[count] = toupper(str[count]);
++count;
}
count = 0;
while(str[count]!= '\0')
{
if (str[count] >= 'A' && str[count]<= 'Z')
sum += str[count] % 64;
++count;
}
while(sum > 10)
{
div = sum;
sum = 0;
while(div > 0)
{
sum += div % 10;
div /= 10;
}
}
bin = (float) sum;
return (bin);
}