Plabon_dutta

Uva 10424

Feb 27th, 2021 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include<math.h>
  4.  
  5. int check(int n);
  6.  
  7. int main() {
  8.     char str1[30], str2[30];
  9.     int n1=0, n2=0;
  10.     float ans;
  11.     while(scanf("%[^\n]%*c %[^\n]%*c", &str1, &str2)!=EOF) {
  12.         int i, l1=strlen(str1), l2=strlen(str2);
  13.         for(i=0; i<l1; i++) {
  14.             if(str1[i]>='a' && str1[i]<='z') n1+=(str1[i]-96);
  15.             else if(str1[i]>='A' && str1[i]<='Z') n1+=(str1[i]-64);
  16.         }
  17.         if(n1>9) n1=check(n1);
  18.         for(i=0; i<l2; i++) {
  19.             if(str2[i]>='a' && str2[i]<='z') n2+=(str2[i]-96);
  20.             else if(str2[i]>='A' && str2[i]<='Z') n2+=(str2[i]-64);
  21.         }
  22.         if(n2>9) n2=check(n2);
  23.         if(n1<n2) ans=(float)n1/n2;
  24.         else ans=(float)n2/n1;
  25.         printf("%.2f %%\n", ans*100.00);
  26.         str1[0]='\0';
  27.         str2[0]='\0';
  28.         n1=n2=0;
  29.     }
  30.     return 0;
  31. }
  32.  
  33. int check(int n) {
  34.     int t=0;
  35.     while(n!=0) {
  36.         t+=n%10;
  37.         n/=10;
  38.     }
  39.     if(t>9) check(t);
  40.     else return t;
  41. }
  42.  
Add Comment
Please, Sign In to add comment