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

Post Reply
5olio
New poster
Posts: 4
Joined: Wed Jun 18, 2008 1:23 pm

Re: 10424 - Love Calculator

Post by 5olio » Wed Jun 18, 2008 1:46 pm

pleeez any one help me

what is the wrong in my code?????

Code: Select all

#include <iostream>
#include <iomanip>

using namespace std;

int digit(int n)
{	
	while(n>=0)
	{
		int Temp=0;
		
		if(n>999999999)
		{
			Temp+=n%1000000000;
			n/=1000000000;
		}
		if(n>99999999)
		{
			Temp+=n%100000000;
			n/=100000000;
		}

		if(n>9999999)
		{
			Temp+=n%10000000;
			n/=10000000;
		}
		if(n>999999)
		{
			Temp+=n%1000000;
			n/=1000000;
		}

		if(n>99999)
		{
			Temp+=n%100000;
			n/=100000;
		}

		if(n>9999)
		{
			Temp+=n%10000;
			n/=10000;
		}

		if(n>999)
		{
			Temp+=n%1000;
			n/=1000;
		}

		if(n>99)
		{
			Temp+=n%100;
			n/=100;
		}
		if(n>9)
		{
			Temp+=n%10;
			n/=10;
			
		}
		Temp+=n;
		n=Temp;
		if(n<10)break;
	}	
	return n;
}
void Calculat (char Boy[],char Girl[])
{
	int BoyCounter=0;
	for(int i=0;i<20;i++)
	{
		if(Boy[i]=='\0')
			break;
		if(Boy[i]>64 && Boy[i]<92)
			BoyCounter+=Boy[i]-64;

		else if(Boy[i]>96 && Boy[i]<124)
			BoyCounter+=Boy[i]-96;
	}
	int GirlCounter=0;
	for(int i=0;i<20;i++)
	{
		if(Girl[i]=='\0')
			break;
		if(Girl[i]>64 && Girl[i]<92)
			GirlCounter+=Girl[i]-64;

		else if(Girl[i]>96 && Girl[i]<124)
			GirlCounter+=Girl[i]-96;
	}

	double BoyCounter1 = digit (BoyCounter);
	double GirlCounter1 = digit(GirlCounter);
	double LoveConter;
	if(BoyCounter1>GirlCounter1)
		LoveConter = (GirlCounter1/BoyCounter1)*100;
	else if((BoyCounter1<=GirlCounter1))
		LoveConter = (BoyCounter1/GirlCounter1)*100;
	
	if(BoyCounter1==0&&GirlCounter1==0)
		cout<<endl;
	else if(BoyCounter1==0||GirlCounter1==0)
		cout<<"0.00 %"<<endl;
	else
		cout<<setiosflags(ios::fixed)<<setprecision(2)<<LoveConter<<" %"<<endl;

}

int main()
{
	char Boy[30],Girl[30];
	while(getlin( Boy )&& gets(Girl))
		Calculat(Boy,Girl);
	return 0;
}


Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10424 - Love Calculator

Post by Obaida » Tue Jul 01, 2008 6:52 am

Thank jan vai I got accepted in this program. I found my mistake in the function of making digit. :wink:
try_try_try_try_&&&_try@try.com
This may be the address of success.

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

WA pls help PLEASEEEEEEEEEEEEE

Post by abid_iut » Wed Oct 29, 2008 8:03 pm

what is the problem??
i got correct answer for every input.
please help.

Code: Select all

#include<stdio.h>
#include<string.h>
#include<iostream.h>

int main()
{
	char a[30],b[30],a1[30],b1[30];
	int i,j=0,sum1=0,sum2=0,l1,l2,flag=0;
	float k;
	
	while(1){
		cin>>a;
		cin>>b;
		
		if(a[0]==NULL)break;
		for(i=0;a[i];i++){
			if(a[i]<65 || a[i]>122)sum1=0;
		}
		for(i=0;b[i];i++){
			if(b[i]<65 || b[i]>122)sum2=0;
		}

	for(i=0;a[i];i++){
		if(a[i]>=65 && a[i]<=90){
			a1[j]=a[i]+32;
			j++;
		}
		else if(a[i]==' ')continue;
		else if(a[i]>=91 && a[i]<=122){
			a1[j]=a[i];
			j++;  
		}
	}
	l1=j;
	
	j=0;
	for(i=0;b[i];i++){
		if(b[i]>=65 && b[i]<=90){
			b1[j]=b[i]+32;
			j++;
		}
		else if(b[i]==' ')continue;
		else if(b[i]>=91 && b[i]<=122){
			b1[j]=b[i];
		j++; }
	}
	l2=j;

	if((sum1==0 && sum2==0) && (l1==0 && l2==0)){
		printf("\n");
		for(i=0;a[i];i++){a1[i]=NULL;a[i]=NULL;}
		for(i=0;b[i];i++){b1[i]=NULL;b[i]=NULL;}
		j=0;sum1=0;sum2=0;
		continue;
	}


	for(j=0;j<l1;j++){
		sum1=sum1+(a1[j]-96);
	}

	for(j=0;j<l2;j++){
		sum2=sum2+(b1[j]-96);
	}

	while(sum1>=10){
	sum1=int (sum1/10)+int (sum1%10);
	}

	while(sum2>=10){
	sum2=int (sum2/10)+int (sum2%10);
	}

	

	if(sum1>=sum2){
	k=(float(sum2)/float(sum1))*100;
	printf("%.2f %c\n",k,'%');
	}

	if(sum1<sum2){
	k=(float(sum1)/float(sum2))*100;
	printf("%.2f %c\n",k,'%');
	}
	for(i=0;i<l1;i++){a1[i]=NULL;a[i]=NULL;}
	for(i=0;i<l2;i++){b1[i]=NULL;b[i]=NULL;}
	j=0;sum1=0;sum2=0;
	}
	return 0;
}
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

iceb3rg
New poster
Posts: 7
Joined: Mon Jul 13, 2009 11:30 am
Location: SUST - CSE
Contact:

Love Calc 10424...TLE

Post by iceb3rg » Mon Jul 13, 2009 11:35 am

here's my code.....

2 reduce time....i ommitted <ctype.h> and usage of while loops:
=======================================================================================
#include <stdio.h>

int x;
int func(int i)
{
int r,q,result=0;
for (;i!=0;)
{
r=i%10;
result+=r;
i=i/10;
}

if (result>9)
return func(result);
else
return result;
}
int main()
{
int i,count=0,temp,result1,result2;
double love,r1,r2;
char n1[25],n2[25];

for (;EOF;)
{
scanf (" %[^\n]",n1);
scanf (" %[^\n]",n2);


for (i=0;n1!='\0';i++)
{
//n1=tolower(n1);
if (n1>=97 && n1<=122)
count+=(n1-96);
if (n1>=65 && n1<=90)
count+=(n1-64);
}

result1=func(count);

count=0;

for (i=0;n2!='\0';i++)
{
//n2[i]=tolower(n2[i]);
if (n2[i]>=97 && n2[i]<=122)
count+=(n2[i]-96);
if (n1[i]>=65 && n1[i]<=90)
count+=(n1[i]-64);

}
result2=func(count);

count=0;



if (result1>=result2)
{
temp=result1;
result1=result2;
result2=temp;
}


r1=result1;
r2=result2;
love=r1/r2;
love=love*100;
printf ("%.2f %c \n",love,'%');
love=0;

}



return 0;
}
===================================================================================================
HELP ME!
still a lot to learn & a long long way to go....but I'll keep trying till I have lov 4 it :D

sms.islam
New poster
Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

Re: 10424 - Love Calculator

Post by sms.islam » Thu Oct 15, 2009 5:13 pm

I am getting wrong answer.need help!!!............



#include<stdio.h>
#include<string.h>
#define max 30

int Count_Digit(int n)
{
int sum=0;
if(n<10)
return n;
else
{
while(n>0)
{
sum=sum+n%10;
n=n/10;
}
return sum;
}
}

int main(void)
{
char ch[max],st[max];
int len1 = 0 , len2 = 0, i , j ,sum1 = 0, sum = 0 ;
double dig1 = 0,dig2 = 0,res1 = 0 ;

while(gets(ch) && gets(st))
{
len1 = strlen(ch);
len2 = strlen(st);

for( i = 0 ; i < len1 ; i ++)
{
if(ch >= 65 && ch < 91)
sum=sum+ch-65+1;
else if(ch >= 97 && ch < 122)
sum=sum+ch-97+1;
}

for( j = 0 ; j < len2 ; j ++)
{
if(st[j] >= 65 && st[j] < 91)
sum1=sum1+st[j]-65+1;
else if(st[j] >= 97 && st[j] < 122)
sum1=sum1+st[j]-97+1;
}

while(sum>=10) sum=Count_Digit(sum);
while(sum1>=10) sum1=Count_Digit(sum1);

dig1=double(sum);
dig2=double(sum1);

if(dig1>dig2) res1=(dig2*100)/dig1;
else res1=(dig1*100)/dig2;

printf("%0.2lf %%\n",res1);
sum1=sum=res1=0;
}
return 0;
}

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

Re: 10424 - Love Calculator

Post by arifcsecu » Thu Oct 15, 2009 7:38 pm

Try to
digit2 greater than digit1

and digit2 and digit must less than 10
Try to catch fish rather than asking for some fishes.

sms.islam
New poster
Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

Re: 10424 - Love Calculator

Post by sms.islam » Fri Oct 16, 2009 4:29 pm

This is not working for me.What else can i do now??................

if((dig1<10) &&(dig2<10))
{
if(dig2>dig1) res1=(dig1*100)/dig2;
else res1=(dig2*100)/dig1;
}

sms.islam
New poster
Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

Re: 10424 - Love Calculator

Post by sms.islam » Fri Oct 16, 2009 4:55 pm

i have got accepted!!!!!!! my code is not working for
z
z
..............

got this point.
thanx

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

Re: 10424 - Love Calculator

Post by arifcsecu » Sat Oct 17, 2009 3:30 pm

sms.islam wrote:i have got accepted!!!!!!! my code is not working for
z
z
..............

got this point.
thanx
remove ur code if u got accepted
Try to catch fish rather than asking for some fishes.

ikukochyan
New poster
Posts: 1
Joined: Tue Mar 30, 2010 1:54 am

10424 Love Calculator - Runtime Error

Post by ikukochyan » Tue Mar 30, 2010 1:59 am

I got a Runtime Error! :cry:
It said that:
---
Your submission with number 7855591 for the problem 10424 - Love Calculator has failed with verdict Runtime error.

This means that the execution of your program didn't finish properly. Remember to always terminate your code with the exit code 0.
---

I did so by adding Sysmtem.exit(0) in the end, but it didn't work :(

Can anybody help my to find out how should I fix it? Thx~ :D
My code:


Code: Select all

import java.util.*;
import java.lang.String;
import javax.swing.*;
import java.io.*; 

class LoveCalculator {

	public static int getValueOfName(String inputOfLover) throws RuntimeException{
	  	int i;
	  	int valueOfLover=0;
	  	int temp;

	  	char[] nameOfLover = inputOfLover.toCharArray();

	  	if(nameOfLover.length>25)
	  		System.out.println("The length of name should be less than 25");
	  	else{
	  		for(i=0;i<nameOfLover.length;i++){
	  		if(Character.getNumericValue(nameOfLover[i])>=10 && Character.getNumericValue(nameOfLover[i])<=35)
	  			valueOfLover += (Character.getNumericValue(nameOfLover[i])-9);
	  		else
	  			valueOfLover+=0;
	  		}
	  		
		  	while(true){
			  	if(valueOfLover>=10){
			  		temp = 0;
				  	while(valueOfLover>=10){
				  		while(valueOfLover != 0){
				  			temp+=valueOfLover%10;
				  			valueOfLover = valueOfLover/10;
				  		}
				  	}
				  	valueOfLover = temp;
			  	}
			  	else
			  		break;
		  	}
		  	System.out.println("\nThe value is "+valueOfLover);  
	  	}
	  	return valueOfLover;
	}
	  
	public static void main(String[] arguments) throws RuntimeException {
		
		String nameOfLoverA = "";
		String nameOfLoverB = "";
		BufferedReader reader;
		
		reader = new BufferedReader(new InputStreamReader(System.in)); 
		System.out.println("Please input your name:");
		try{
			nameOfLoverA = reader.readLine();
		}
		catch (IOException ioe){
			System.out.println("An unexpected error occured."); 
		} 
		
		reader = new BufferedReader(new InputStreamReader(System.in)); 
		System.out.println("Please input your lover's name:");
		try{
			nameOfLoverB = reader.readLine();
		}
		catch (IOException ioe){
			System.out.println("An unexpected error occured."); 
		}
		
		int valueOfLoverA = getValueOfName(nameOfLoverA);
	  	int valueOfLoverB = getValueOfName(nameOfLoverB);

	  	float result = Float.intBitsToFloat(valueOfLoverA)/Float.intBitsToFloat(valueOfLoverB)*100;
	  	System.out.print("The result is "+result+"%");
	  	
	  	System.exit(0);
  	}
  }

cse.mehedi
New poster
Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

10424 why not AC?

Post by cse.mehedi » Tue Mar 27, 2012 9:11 pm

Plz Any One Help Me!!
:( :( :oops:

Code: Select all

AC

Last edited by cse.mehedi on Wed Mar 28, 2012 4:31 am, edited 1 time in total.

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

Re: 10424 why not AC?

Post by brianfry713 » Wed Mar 28, 2012 12:17 am

Rules

You will be given two names. These two names can have white space
Check input and AC output for thousands of problems on uDebug!

cse.mehedi
New poster
Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

Re: 10424 why not AC?

Post by cse.mehedi » Wed Mar 28, 2012 4:32 am

brianfry713 wrote:Rules

You will be given two names. These two names can have white space
Thank You Dear! :D :D

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

Re: 10424 - Love Calculator

Post by shatil_cse » Sat Apr 07, 2012 7:31 pm

please help me ............
Why WA????????????
Last edited by shatil_cse on Fri Apr 13, 2012 8:40 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 Apr 09, 2012 9:50 pm

Doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 104 (10400-10499)”