## 10424 - Love Calculator

Moderator: Board moderators

shatil_cse
New poster
Posts: 11
Joined: Thu Apr 05, 2012 8:33 pm

### Re: 10424 - Love Calculator

brianfry713 wrote:Doesn't match the sample I/O.
I have got acc.

enamsustcse
New poster
Posts: 9
Joined: Fri May 04, 2012 9:41 pm
Contact:

### Re: 10424 - Love Calculator

#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....
-----
Enamul Hassan,
Student,
2nd year, CSE,

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10424 - Love Calculator

Input:

Code: Select all

``````Love
Calculator``````
AC output:

Code: Select all

``77.78 %``
Check input and AC output for thousands of problems on uDebug!

nest
New poster
Posts: 6
Joined: Sun May 20, 2012 10:18 am

### i can't understand that why wa, pls help me:

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10424 - Love Calculator

Your code is printing a blank line for input:

Code: Select all

``````USA
USSR``````
Check input and AC output for thousands of problems on uDebug!

nest
New poster
Posts: 6
Joined: Sun May 20, 2012 10:18 am

### Re: 10424 - Love Calculator

nest
New poster
Posts: 6
Joined: Sun May 20, 2012 10:18 am

### Re: 10424 - Love Calculator

i corrected it. but again WA
WHY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10424 - Love Calculator

Check input and AC output for thousands of problems on uDebug!

sumon sarker
New poster
Posts: 4
Joined: Tue Mar 20, 2012 7:58 am
Contact:

### Re: 10424 - Love Calculator

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10424 - Love Calculator

Check My Submissions and you can see the reason for your Compile Error.
Check input and AC output for thousands of problems on uDebug!

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

### Re: 10424 - Love Calculator

Code Removed after getting Correct ans
Last edited by mobarak.islam on Tue Jan 15, 2013 1:12 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10424 - Love Calculator

You need to read line by line, there may be white space in a name.
Check input and AC output for thousands of problems on uDebug!

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

### Re: 10424 - Love Calculator

Thanks @ brianfry713 . I got the Accepted

enamsustcse
New poster
Posts: 9
Joined: Fri May 04, 2012 9:41 pm
Contact:

### Re: 10424 - Love Calculator

brianfry713 wrote:Input:

Code: Select all

``````Love
Calculator``````
AC output:

Code: Select all

``77.78 %``
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!!!
-----
Enamul Hassan,
Student,
2nd year, CSE,

raihan_sust5
New poster
Posts: 6
Joined: Tue Jul 23, 2013 3:04 am

### Re: 10424 - Love Calculator

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