Uva 10424 Solution

#include<bits/stdc++.h>
using namespace std;
int rob(char an[30], int d)
{
    int i, s = 0, r, c  = 0;
    for(i=0;i<d;i++)
    {
        an[i] = tolower(an[i]);
        if(an[i] >= 97 && an[i] <= 122)
        {
            s = s + (an[i] - 96);
        }
    }

    while(s > 9)
    {
        while(s > 0)
        {
            r = s %10;
            s = s/10;
            c = c + r;
        }
        s = c;
        c  = 0;
    }
    return s;
}

double anik(char ar[30], char ab[30])
{
    int l;
    double a, b, c;
    l = strlen(ar);
    a = rob(ar, l);
    l = strlen(ab);
    b = rob(ab, l);
    if(a<b || a == b)
        c = a/b;
    if(a>b)
        c = b/a;
    return c*100;
}

int main()
{
    char ch[30], an[30];
    cout << showpoint;
    cout << fixed;
    cout << setprecision(2);
    while(gets(ch) && gets(an))
    {
       double a = anik(ch, an);
       cout << a << " %" << endl;
    }

    return 0;
}

Comments