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

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

Re: 10424 - Love Calculator

Post by brianfry713 » Sat Jul 27, 2013 3:20 am

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

Post by IanSwartz » Sun Sep 29, 2013 12:51 pm

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
Location: Bangladesh

Re: 10424 - Love Calculator

Post by shuvokr » Mon Sep 30, 2013 2:29 pm

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

Post by saju10 » Tue Nov 19, 2013 10:16 am

why wrong answer?here given code.

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

Post by brianfry713 » Tue Nov 19, 2013 9:13 pm

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

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

Re: 10424 - Love Calculator

Post by uDebug » Thu Dec 19, 2013 9:08 am

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
aadsfdmkxvczp[we
amcsfdfapioeur123  132124


aadsfdmkxvczp[we
amcsfdfapioeur123  132124

amcsfdfapioeur123  132124
aadsfdmkxvczp[we

aadsfdmkxvczp[we
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!

Find us on Facebook. Follow us on Twitter.

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

Re: 10424 - Love Calculator

Post by Shihab » Thu Dec 19, 2013 12:52 pm

AC :D

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

Re why i get WA: 10424 - Love Calculator

Post by cse dipto » Wed Jan 01, 2014 11:37 pm

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

Post by Shihab » Thu Jan 02, 2014 10:48 am

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

Post by cse dipto » Fri Jan 03, 2014 4:05 pm

Thnks got AC :D @shihab vai

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

Re: 10424 - Love Calculator

Post by Shahidul.CSE » Tue Jul 22, 2014 9:51 pm

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
My facebook account,
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

Post by lighted » Tue Jul 22, 2014 10:33 pm

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
Location: Rangpur, Bangladesh

Re: 10424 - Love Calculator

Post by Shahidul.CSE » Tue Jul 22, 2014 10:51 pm

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
My facebook account,
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

Post by lighted » Tue Jul 22, 2014 11:10 pm

Your changed code is accepted code! :D

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? :D
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
Location: Rangpur, Bangladesh

Re: 10424 - Love Calculator

Post by Shahidul.CSE » Wed Jul 23, 2014 7:13 am

Thank you! Accepted !!
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

Post Reply

Return to “Volume 104 (10400-10499)”