10424 - Love Calculator
Moderator: Board moderators
-
- 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!
Re: 10424 - Love Calculator
Can someone spot the error or paste some test input that breaks the code, thx.
Thanks, shuvokr.
In hindsight I now see that I only tested with long strings.
Code: Select all
- removed -, got AC
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.
Re: 10424 - Love Calculator
Try this Input:
Code: Select all
EE
E
Code: Select all
enjoying life .....
Re: 10424 - Love Calculator
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(" %");
}
}
}
}
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(" %");
}
}
}
}
-
- 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!
Re: 10424 - Love Calculator
Here's some input / output that may help those trying to debug or solve this problem.
Input:
AC Output:
And yes, those are blank lines in between.
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
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 %
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.
Re: 10424 - Love Calculator
try this inputs
Code: Select all
$ saima
# saima
blank_line
saima
blank_line
blank_line
Re: 10424 - Love Calculator
Thnks got AC @shihab vai
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
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
My facebook account,
Email me: shahidul.cse.brur@gmail.com
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
Re: 10424 - Love Calculator
Names can contain white space. scanf will stop reading when white space reached.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
It will not read full name. You must use gets.
Code: Select all
while(scanf("%s%s",&b,&g)!=EOF)
{
sb=sg=0; //initialize
..
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
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
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
My facebook account,
Email me: shahidul.cse.brur@gmail.com
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
Re: 10424 - Love Calculator
Your changed code is accepted code!
And it gives this output for test above.
Maybe you changed code on your pc again?
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 %
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 10424 - Love Calculator
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
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