Pages

Tuesday, November 30, 2010

UVA Problem#10424

Question:
http://uva.onlinejudge.org/external/104/10424.html

Solution:
1. Take 2 strings input. adjust the values of each character according to the problem describes. (here it was stored in ans1 and ans2 variables)
2. Then make the sum of these numbers until it comes in one digit. (here it is done in temp1 and temp2 variables)
3. Answer the value of the two ratio in percentage for the larger value of temp1 and temp2.



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

int main(){
.....
......
        for(i=0; i<l1; i++)
            ans1+=adjust(s1[i]);
        for(i=0; i<l2; i++)
            ans2+=adjust(s2[i]);
       
        w=(ans1/100)+(ans1%100);
        x=(w/100)+(w%100);
        y=(x/10)+(x%10);
        temp1=(y/10)+(y%10);
      
        w=(ans2/100)+(ans2%100);
        x=(w/100)+(w%100);
        y=(x/10)+(x%10);
        temp2=(y/10)+(y%10);
......
......

}

No comments:

Post a Comment