Page 10 of 10

Re: 10424 - Love Calculator

Posted: Sat Dec 06, 2014 3:50 pm
by lighted
Input

Code: Select all

shanto
saima
Acc Output

Code: Select all

71.43 %

Re: 10424 - Love Calculator

Posted: Sat Jan 17, 2015 6:53 pm
by jasir
As i know it is old thread but most of people want to know the code for creating a love calculator and i can help. I have created a web calculator in php and js located here and it is based on a new code and according to my users it is showing correct results. If you want to learn then i can help.

Re: 10424 - Love Calculator

Posted: Mon Sep 07, 2015 10:08 am
by shourovfoisal
Hi,
My code isn't working for the following critical input given in uDebug:

Code: Select all

HgU
Alld
Running this input in my code, I found the output:

Code: Select all

50.00 %
I know the accepted output is 22.22 % . But is this correct? Calculating the input data manually, I found out the result should be 50.00 %. Though I might be wrong. All the other inputs are working correctly I guess. Please help.

Below is my solution in c++:

Code: Select all

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

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

int main()
{
    int i,sum1,sum2;
    float res;
    char n1[30],n2[30];
    while(gets(n1))
    {
        gets(n2);
        sum1=sum2=0;
        for(i=0;n1[i]!='\0';i++)
        {
            if(n1[i]>=97&&n1[i]<=122)
                sum1+=(n1[i]-96);
            else if(n1[i]>=65&&n1[i]<=90)
                sum1+=(n1[i]-64);
        }
        for(i=0;n2[i]!='\0';i++)
        {
            if(n2[i]>=97&&n2[i]<=122)
                sum2+=(n2[i]-96);
            else if(n2[i]>=65&&n2[i]<=90)
                sum2+=(n2[i]-64);
        }
        sum1=lc(sum1);
        sum2=lc(sum2);
        if(sum1<sum2)
            res= (float)sum1*100/(float)sum2;
        else
            res= (float)sum2*100/(float)sum1;
        printf("%.2f %%\n",res);
    }
    return 0;
}