10424 - Love Calculator

All about problems in Volume 104. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Re: 10424 - Love Calculator

Post by shatil_cse » Fri Apr 13, 2012 8:39 pm

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

User avatar
enamsustcse
New poster
Posts: 9
Joined: Fri May 04, 2012 9:41 pm
Location: SUST, Sylhet, Bangladesh
Contact:

Re: 10424 - Love Calculator

Post by enamsustcse » Fri May 04, 2012 9:52 pm

#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,
SUST, Sylhet, Bangladesh

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

Re: 10424 - Love Calculator

Post by brianfry713 » Tue May 08, 2012 12:01 am

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:

Post by nest » Sun May 20, 2012 10:23 am

#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

Post by brianfry713 » Mon May 21, 2012 11:05 pm

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

Post by nest » Fri May 25, 2012 12:08 am

thanks for reply

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

Re: 10424 - Love Calculator

Post by nest » Thu May 31, 2012 9:27 pm

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

Post by brianfry713 » Fri Jun 01, 2012 12:01 am

post your updated code
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
Location: Dhaka,Bangladesh
Contact:

Re: 10424 - Love Calculator

Post by sumon sarker » Tue Jul 10, 2012 6:39 pm

No error, No warning in my code. But why compilation error?? Please Help me!

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

Re: 10424 - Love Calculator

Post by brianfry713 » Tue Jul 17, 2012 3:22 am

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

Post by mobarak.islam » Sun Jan 06, 2013 12:40 pm

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

Post by brianfry713 » Mon Jan 07, 2013 3:28 am

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

Post by mobarak.islam » Tue Jan 15, 2013 1:11 pm

Thanks @ brianfry713 . I got the Accepted :)

User avatar
enamsustcse
New poster
Posts: 9
Joined: Fri May 04, 2012 9:41 pm
Location: SUST, Sylhet, Bangladesh
Contact:

Re: 10424 - Love Calculator

Post by enamsustcse » Fri Jan 18, 2013 9:15 pm

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,
SUST, Sylhet, Bangladesh

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

Re: 10424 - Love Calculator

Post by raihan_sust5 » Thu Jul 25, 2013 9:06 pm

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

Post Reply

Return to “Volume 104 (10400-10499)”