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
nahid
New poster
Posts: 18
Joined: Wed Oct 04, 2006 8:59 pm
Location: DHAKA,BANGLADESH
Contact:

10424-WA(disgusting!)

Post by nahid »

i've tried all possible cases (included spases and special letters) but getting :evil: and again :evil: . help me.pls.

Code: Select all

#include<stdio.h>
  int calcu(char a[],int n);
  int add(int d);
 void main()
 {
     int c,d;
	 float res;
     char a[50],b[50];
     while(gets(a)&&gets(b))
	 {
     c=calcu(a,50);
     d=calcu(b,50);
	  if(c<d)
     res=c/(float)d*100;
     else
     res=d/(float)c*100;
	 printf("%.2f %%\n",res);
	 }
     
 }



 int calcu(char a[],int n)
 {
      int c,d=0,i;
      for(i=0;a[i]!='\0';i++)
      {
	  if(a[i]>=65&&a[i]<=90)
	  {
	    c=a[i]-64;
		d+=c;
	  }
	  else if(a[i]>=97&&a[i]<=122)
	  {
	    c=a[i]-96;
		d+=c;
	  }
       }
       while(d>10)
	 d=add(d);


       return(d);
}


  int add(int d)
  {
      int e,f=0;
      while(d!=0)
       {
	   e=d%10;
	   d/=10;
	   f+=e;
       }
      return(f);
  }


Tariq Shahriar
New poster
Posts: 17
Joined: Wed Mar 01, 2006 8:34 pm
Location: 2nd floor

Post by Tariq Shahriar »

Perhaps, problem is in your calcu() function
problem description wrote:make the sum of these numbers until it comes in one digit
so

Code: Select all

while(d>10)
    d=add(d); 
is wrong. beacuse, if d=10 then the loop will stop.

you may change the loop condition by this way-

Code: Select all

while(d>=10)
    d=add(d); 
or,

Code: Select all

while(d>9) 
    d=add(d); 
[ Common thing of every man is that, everyone thinks that he is uncommon ]

john_locke
New poster
Posts: 13
Joined: Sat Oct 07, 2006 6:42 pm
Contact:

Post by john_locke »

hi friends this is my code dont know why i am getting wrong answer
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main()
{
float percen,m1,m2;
char s1[30],s2[30];
int len1,len2,temp,temp2;

while(cin.getline(s1,26))
{
cin.getline(s2,26);
int sum1=0,sum2=0;
len1=strlen(s1);
len2=strlen(s2);
for(int i=0;i<len1;i++)
{
if(s1>=65&&s1<91)
sum1=sum1+s1-65+1;
if(s1>=97&&s1<122)
sum1=sum1+s1-97+1;

}

while(sum1/10!=0)
{
sum1=sum1%10+(sum1/10);
}

for(int i=0;i<len2;i++)
{
if(s2>=65&&s2<91)
sum2=sum2+s2-65+1;
if(s2>=97&&s2[i]<122)
sum2=sum2+s2[i]-97+1;
}

while(sum2/10!=0)
{
sum2=sum2%10+(sum2/10);
}

m1=(float)sum1;
m2=(float)sum2;
if(m1==0&&m2==0)
cout<<"0.00 %\n";
else{
if(sum1>=sum2)
percen=(m2/m1)*100.0;
else
percen=(m1/m2)*100.0;

printf("%.2f ",percen);
cout<<"%\n";}
}
return 0;
}


ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

PE(10424 LOVE CALCULATOR)

Post by ishtiaq ahmed »

PLZ TRY TO HELP ME. MY PROBLEM HANGS ON PRESENTATION ERROR.HERE IS MY CODE

Code: Select all

 The code is removed after getting AC.
No venture no gain

with best regards
------------------------
ishtiaq ahmed

newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton »

dear ishtiaq
please try to change your code

to:

Code: Select all


         printf("%.2f %s\n",res,"%"); 

and must remove the code after AC.







newton.................. simply the best

mrmbdctg
New poster
Posts: 18
Joined: Sun Mar 04, 2007 7:12 am
Location: Bangladesh
Contact:

I have also wrong answer pls helppppppppppppppppp

Post by mrmbdctg »

#include<stdio.h>
#include<string.h>
int sum(char alpha[25]);

void main()
{


char name1[25]="\x0",name2[25]="\x0";
while(scanf("%s%s",&name1,&name2)!=EOF)
{
float ratio=0;
int len1, len2;
int p=0,q=0;
len1=strlen(name1);
len2=strlen(name2);
if(len1>25 || len2>25)
{
continue ;
}
p=sum(name1);
q=sum(name2);

if(p<q)
ratio=((float)p/(float)q)*100;
else
ratio=((float)q/(float)p)*100;

printf("%.2f %%\n",ratio);
//printf(" %\n");
}
}


int sum(char alpha[25])
{
int let=0,len,s=0,r,i=0,a[25]={0};
len=strlen(alpha);

for(i=0;i<=len-1;i++)
{
switch(alpha)
{
case'a':
let+=1;
break;
case'b':
let+=2;
break;
case'c':
let+=3;
break;
case'd':
let+=4;
break;
case'e':
let+=5;
break;
case'f':
let+=6;
break;
case'g':
let+=7;
break;
case'h':
let+=8;
break;
case'i':
let+=9;
break;
case'j':
let+=10;
break;
case'k':
let+=11;
break;
case'l':
let+=12;
break;
case'm':
let+=13;
break;
case'n':
let+=14;
break;
case'o':
let+=15;
break;
case'p':
let+=16;
break;
case'q':
let+=17;
break;
case'r':
let+=18;
break;
case's':
let+=19;
break;
case't':
let+=20;
break;
case'u':
let+=21;
break;
case'v':
let+=22;
break;
case'w':
let+=23;
break;
case'x':
let+=24;
break;
case'y':
let+=25;
break;
case'z':
let+=26;
break;
case'A':
let+=1;
break;
case'B':
let+=2;
break;
case'C':
let+=3;
break;
case'D':
let+=4;
break;
case'E':
let+=5;
break;
case'F':
let+=6;
break;
case'G':
let+=7;
break;
case'H':
let+=8;
break;
case'I':
let+=9;
break;
case'J':
let+=10;
break;
case'K':
let+=11;
break;
case'L':
let+=12;
break;
case'M':
let+=13;
break;
case'N':
let+=14;
break;
case'O':
let+=15;
break;
case'P':
let+=16;
break;
case'Q':
let+=17;
break;
case'R':
let+=18;
break;
case'S':
let+=19;
break;
case'T':
let+=20;
break;
case'U':
let+=21;
break;
case'V':
let+=22;
break;
case'W':
let+=23;
break;
case'X':
let+=24;
break;
case'Y':
let+=25;
break;
case'Z':
let+=26;
break;
}

}

while(let>0)
{
r=let%10;
a=r;
s=s+r;
i++;
let=let/10;
if(s>9 && let==0)
{
let=s;
s=0;
}

}
r=0;
return s;
}
Mizanur Rahaman Mizan
USTC, CHITTAGONG
BANGLADESH
Website:http://www.teronga.com

sufi
New poster
Posts: 1
Joined: Mon Feb 12, 2007 12:21 pm
Location: Dhaka University

Post by sufi »

Wrong Answer
Plz some one help me.

Code: Select all

#include<stdio.h>
float cout(char st[100000]);
void main()
{
	float x,y;
	float sum=0;
	char st1[100000],st2[100000];
	while(gets(st1))
	{
		x=cout(st1);
		gets(st2);
		y=cout(st2);
		if(x>y)
			sum=(float)(y*100/x);
		else
			sum=(float)(x*100/y);

		printf("%.2f %c",sum,'%');
		printf("\n");
	}
}

float cout(char st[])
{
	long i,tot=0;
	float sum;
	for(i=0;st[i];i++)
	{
		sum=0;
		if(st[i]>='a'&&st[i]<='z')
			sum=st[i]-96;
		if(st[i]>='A'&&st[i]<='Z')
			sum=st[i]-64;
		tot=tot+sum;
	}
	sum=tot%9;
	return sum;
}




apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

where's wrong in 10424

Post by apurba »

Code: Select all


removed after accepted
		
Last edited by apurba on Wed Dec 12, 2007 8:46 pm, edited 2 times in total.

Code: Select all

keep dreaming...

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Use

Code: Select all

while(scanf("%s %s",s1,s2)==2)
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

mask_man
New poster
Posts: 2
Joined: Mon Mar 17, 2008 8:11 pm

10424 where is the CE

Post by mask_man »

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

int main()
{
char name1[27];
char name2[27],a='%';

int sum1,sum2;
int len1,len2;
float output,s1,s2;


while(scanf("%s%s",name1,name2)==2)
{
len1=strlen(name1);
len2=strlen(name2);

sum1=0;
sum2=0;


for(int i=0;i<len1;i++)
{
if(name1>=65&&name1<=90)
{
sum1+=name1-64;
}

if(name1>=97&&name1<=122)
{
sum1+=name1-96;
}

}

for( i=0;i<len2;i++)
{
if(name2>=65&&name2<=90)
{
sum2+=name2-64;
}

if(name2>=97&&name2[i]<=122)
{
sum2+=name2[i]-96;
}

}


sum1=sum1%9;
sum2=sum2%9;


if(sum1==0)
sum1=9;
if(sum2==0)
sum2=9;

s1=(float)sum1;
s2=(float)sum2;

output=s2/s1;


if(output>100)
printf("100.00 %c\n",a);
else if(output==0)
printf("100.00 %c\n",a);
else
{
output=output*100.00;
printf("%.2f %c\n",output,a);
}

}

return 0;

}




/// Can any one say where is the Compilation Error........help me

OmarOthman
New poster
Posts: 4
Joined: Mon Apr 03, 2006 1:05 am
Location: Cairo - Egypt
Contact:

10424 (Love Calculator): Java Question

Post by OmarOthman »

This is my code. It throws a runtime error. My question is: Is this way of acquiring user input correct ?! Please if it were correct take a look and tell me why the runtime error appears...

import java.io.*;
import java.text.DecimalFormat;

class Main {

public static void main(String[] args) throws IOException {

InputStreamReader isr = new InputStreamReader( System.in );
BufferedReader stdin = new BufferedReader( isr );
String input = "", output = "";

double lover1, lover2, loveRatio;
DecimalFormat formatter = new DecimalFormat("##0.00");
formatter.setDecimalSeparatorAlwaysShown(true);

input = stdin.readLine();
while(!(input.equals(null) || input.equals("")))
{
input = input.toUpperCase();
input = input.replaceAll("[^A-Z]", "");
lover1 = EvaluateDigitsSum(input);

input = stdin.readLine();

input = input.toUpperCase();
input = input.replaceAll("[^A-Z]", "");
lover2 = EvaluateDigitsSum(input);

if (lover1 == 0 || lover2 == 0)
loveRatio = 0;
else
loveRatio = (lover1 > lover2) ? (lover2 / lover1) : (lover1 / lover2);

loveRatio *= 100;
output += formatter.format(loveRatio) + " %\n";

input = stdin.readLine();
}

System.out.print(output.substring(0, output.length() - 1));
}

private static int EvaluateDigitsSum(String input)
{
int inputLength, i, sum, digisum;

sum = 0;
inputLength = input.length();
for (i = 0; i < inputLength; i++)
sum += input.charAt(i) - 'A' + 1;

// Find the individual digits sum.
digisum = sum % 10;
sum /= 10;
digisum += sum % 10;
sum /= 10;
digisum += sum % 10;

if (digisum > 9)
digisum = digisum % 10 + digisum / 10;

return digisum;
}

}
Omar Mohammad Othman

Teaching Assistant
Scientific Computing Department
Faculty of Computer & Information Sciences
AinShams University
Abbassia, Cairo, Egypt
http://cis.shams.edu.eg/

Mob.: +20 10 535 94 96
Mail: omar_m_othman@yahoo.com

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

Well, this one is obviously wrong:
while(!(input.equals(null) || input.equals("")))
If input is null, you're not allowed to call any of its methods. The right thing to use is just 'input == null'.

System.out.print(output.substring(0, output.length() - 1));
Why strip the last \n? It doesn't harm anyone.

And you can do formatted output much easier - System.out.printf("%.2f %%\n", x);

OmarOthman
New poster
Posts: 4
Joined: Mon Apr 03, 2006 1:05 am
Location: Cairo - Egypt
Contact:

Post by OmarOthman »

Thank you very much for the fast and detailed reply. Sorry about that... but the anomaly of using == and equals in Java always causes me nightmares!! I'm an expert on C#, and this one is well handled there...
Regarding the last '\n', actually it was considered an "output format error" during the college days, so this has become a "habit"... :D
Omar Mohammad Othman

Teaching Assistant
Scientific Computing Department
Faculty of Computer & Information Sciences
AinShams University
Abbassia, Cairo, Egypt
http://cis.shams.edu.eg/

Mob.: +20 10 535 94 96
Mail: omar_m_othman@yahoo.com

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 »

Code: Select all

I have accepted
Last edited by Obaida on Sun Nov 02, 2008 11:53 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 10424 - Love Calculator

Post by Jan »

Try the case.

Input:

Code: Select all

HgU
Alld
Output:

Code: Select all

22.22 %
Hope it helps. Never use 'float', use 'double'.
Ami ekhono shopno dekhi...
HomePage

Post Reply

Return to “Volume 104 (10400-10499)”