Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. // Verdict : Accepted
  2. // Time : 0.00
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <algorithm>
  7. #include <cmath>
  8. #define N 10000
  9. #define sf scanf
  10. #define pf printf
  11. using namespace std;
  12.  
  13. struct my
  14. {
  15. char c;
  16. int in;
  17. };
  18.  
  19. int main ()
  20. {
  21. char ch[N],nam1[N],nam2[N],pnam1[N],pnam2[N];
  22. int namlen1=0,namlen2=0,slen=0,s=0,t1=0,t2=0,n=2,lenp1=0,lenp2=0;
  23. my ar[N];
  24.  
  25. while (gets(nam1))
  26. {
  27. gets(nam2);
  28.  
  29. char tch = 'a';
  30.  
  31. for (int i=1;i<=26;i++)
  32. {
  33. ar[slen].c = tch;
  34. ar[slen].in = i;
  35. slen++; tch++;
  36. }
  37.  
  38. /*for (int i=0;i<slen;i++)
  39. {
  40. pf ("%c %d; ",ar[i].c,ar[i].in);
  41. }*/
  42.  
  43. for (int i=0;i<strlen(nam1);i++)
  44. {
  45. if (nam1[i]>='A' and nam1[i]<='Z')
  46. {
  47. pnam1[lenp1] = nam1[i]+32;
  48. lenp1++;
  49. }
  50.  
  51. else if (nam1[i]>='a' and nam1[i]<='z')
  52. {
  53. pnam1[lenp1] = nam1[i];
  54. lenp1++;
  55. }
  56.  
  57. else
  58. {
  59. continue;
  60. }
  61. }
  62.  
  63. /*for (int i=0;i<lenp1;i++)
  64. {
  65. pf ("%c ",pnam1[i]);
  66. }*/
  67.  
  68. for (int i=0;i<strlen(nam2);i++)
  69. {
  70. if (nam2[i]>='A' and nam2[i]<='Z')
  71. {
  72. pnam2[lenp2] = nam2[i]+32;
  73. lenp2++;
  74. }
  75.  
  76. else if (nam2[i]>='a' and nam2[i]<='z')
  77. {
  78. pnam2[lenp2] = nam2[i];
  79. lenp2++;
  80. }
  81.  
  82. else
  83. {
  84. continue;
  85. }
  86. }
  87.  
  88. /*for (int i=0;i<lenp2;i++)
  89. {
  90. pf ("%c ",pnam2[i]);
  91. }*/
  92.  
  93. for (int i=0;i<lenp1;i++)
  94. {
  95. for (int j=0;j<slen;j++)
  96. {
  97. if (pnam1[i] == ar[j].c)
  98. {
  99. s+=ar[j].in;
  100. }
  101. }
  102. }
  103.  
  104. //cout << s;
  105.  
  106. int a=s,b=s;
  107.  
  108. while (a!=0)
  109. {
  110. a%=10;
  111. t1+=a;
  112. b/=10;
  113. a=b;
  114.  
  115. if (a==0)
  116. {
  117. if (t1<10)
  118. {
  119. break;
  120. }
  121.  
  122. else
  123. {
  124. a = t1; b=t1; t1=0; s=0;
  125. }
  126. }
  127. }
  128.  
  129. //cout << t1;
  130. s=0; a=0; b=0;
  131.  
  132. for (int i=0;i<lenp2;i++)
  133. {
  134. for (int j=0;j<slen;j++)
  135. {
  136. if (pnam2[i] == ar[j].c)
  137. {
  138. s+=ar[j].in;
  139. }
  140. }
  141. }
  142.  
  143. a=s,b=s;
  144.  
  145. while (a!=0)
  146. {
  147. a%=10;
  148. t2+=a;
  149. b/=10;
  150. a=b;
  151.  
  152. if (a==0)
  153. {
  154. if (t2<10)
  155. {
  156. break;
  157. }
  158.  
  159. else
  160. {
  161. a = t2;
  162. b=t2;
  163. t2=0;
  164. }
  165. }
  166. }
  167.  
  168. //cout << t2;
  169. if (t1>t2)
  170. {
  171. //r = 1.0*(t2*100.0)/t1;
  172. pf ("%.2f %%\n",1.0*(t2*100.0)/t1);
  173. }
  174.  
  175. else if (t1<t2)
  176. {
  177. pf ("%.2f %%\n",1.0*(t1*100.0)/t2);
  178. }
  179.  
  180. else
  181. {
  182. pf ("100.00 %%\n");
  183. }
  184.  
  185. lenp1 = 0; lenp2 = 0;t1=0;t2=0;s=0;a=0;b=0; slen=0;
  186. }
  187.  
  188. return 0;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement