## 10424 - Love Calculator

Moderator: Board moderators

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

### Re: 10424 - Love Calculator

Try using double instead of float
Check input and AC output for thousands of problems on uDebug!

IanSwartz
New poster
Posts: 6
Joined: Wed Sep 18, 2013 11:44 am

### Re: 10424 - Love Calculator

Can someone spot the error or paste some test input that breaks the code, thx.

Code: Select all

`````` - removed -, got AC
``````
Thanks, shuvokr.
In hindsight I now see that I only tested with long strings.
Last edited by IanSwartz on Mon Sep 30, 2013 5:43 pm, edited 1 time in total.

shuvokr
Learning poster
Posts: 66
Joined: Tue Oct 02, 2012 8:16 pm

### Re: 10424 - Love Calculator

Try this Input:

Code: Select all

``````EE
E ``````

Code: Select all

``enjoying life ..... ``

saju10
New poster
Posts: 8
Joined: Mon Nov 18, 2013 12:09 am

### Re: 10424 - Love Calculator

import java.util.Scanner;
class LoveCalculator {
public static void main(String args[]){
Scanner input=new Scanner(System.in);
String str1,str2;
while(input.hasNextLine()){
str1=input.nextLine();
str2=input.nextLine();
int a=0,b=0,i,j,l1=str1.length(),l2=str2.length();
char[] girl,boy;
girl=str1.toCharArray();
boy=str2.toCharArray();
for(i=0;i<l1;i++){
if(girl>='A'&&girl<='Z'){
a+=girl-64;
}
else if(girl>='a'&&girl<='z'){
a+=girl-96;
}
}
for(i=0;i<l2;i++){
if(boy>='A'&&boy<='Z'){
b+=boy-64;
}
else if(boy>='a'&&boy[i]<='z'){
b+=boy[i]-96;
}
}

while(a>9){
int r=0;
while(a>0){
r+=a%10;
a=a/10;
}
a=r;
}
while(b>9){
int rr=0;
while(b>0){
rr+=b%10;
b=b/10;
}
b=rr;
}
float ans;
if(a<=b)
System.out.println("100.00 %");
else{
float b1,a1;
a1=a;b1=b;
ans=(b1*100)/a1;
System.out.printf("%.2f",ans);
System.out.println(" %");
}
}
}
}

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

### Re: 10424 - Love Calculator

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

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 10424 - Love Calculator

Here's some input / output that may help those trying to debug or solve this problem.

Input:

Code: Select all

``````saima
shanto
Pakistan
India
USA
USSR
amcsfdfapioeur123  132124

amcsfdfapioeur123  132124

amcsfdfapioeur123  132124

amcsfdfapioeur123  132124
!~@#\$%^&*()_+
:"<>?,./
EE
E
HgU
Alld
Love
C             alcu     lator    ``````
AC Output:

Code: Select all

``````71.43 %
100.00 %
100.00 %
28.57 %

28.57 %
0.00 %
0.00 %
28.57 %

20.00 %
22.22 %
77.78 %``````
And yes, those are blank lines in between.
Check input and AC output for over 7,500 problems on uDebug!

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

### Re: 10424 - Love Calculator

AC

cse dipto
New poster
Posts: 22
Joined: Tue Oct 29, 2013 6:46 pm

### Re why i get WA: 10424 - Love Calculator

remove After AC
Last edited by cse dipto on Fri Jan 03, 2014 4:06 pm, edited 1 time in total.

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

### Re: 10424 - Love Calculator

try this inputs

Code: Select all

``````\$ saima
# saima
blank_line
saima
blank_line
blank_line
``````

cse dipto
New poster
Posts: 22
Joined: Tue Oct 29, 2013 6:46 pm

### Re: 10424 - Love Calculator

Thnks got AC @shihab vai

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am

### Re: 10424 - Love Calculator

Why WA with my code?

Code: Select all

``````Code removed after getting Accepted !!
``````
Last edited by Shahidul.CSE on Wed Jul 23, 2014 7:10 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
Email me: shahidul.cse.brur@gmail.com

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 10424 - Love Calculator

You will be given two names. These two names can have white space or some other non-alphabetical characters like \$ @ & % etc. But only the alphabets from a to z or A to Z will participate in love calculation
Names can contain white space. scanf will stop reading when white space reached.
It will not read full name. You must use gets.

Code: Select all

``````while(scanf("%s%s",&b,&g)!=EOF)
{
sb=sg=0;   //initialize
..``````
It must be

Code: Select all

``````while(gets(b))
{
gets(g);
sb=sg=0;   //initialize
..``````
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am

### Re: 10424 - Love Calculator

I changed my code as bellow:

Code: Select all

``````Code removed after being Accepted !
``````
Last edited by Shahidul.CSE on Wed Jul 23, 2014 7:11 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
Email me: shahidul.cse.brur@gmail.com

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 10424 - Love Calculator

Your changed code is accepted code!

And it gives this output for test above.

Code: Select all

``````71.43 %
100.00 %
100.00 %
28.57 %
100.00 %
28.57 %
0.00 %
0.00 %
28.57 %
100.00 %
20.00 %
22.22 %
0.00 %
``````
Maybe you changed code on your pc again?
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am