Advertisement
erfanul007

UVa 11616

Jan 8th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. typedef unsigned long long int ull;
  6. typedef vector<int> vi;
  7. typedef vector<vi> vvi;
  8. typedef pair<int,int> pii;
  9. typedef vector< pii > vpii;
  10. typedef set<int> sti;
  11.  
  12. #define pb push_back
  13. #define pob pop_back
  14. #define mp make_pair
  15. #define ff first
  16. #define ss second
  17. #define loop1(i,n) for(int i=1; i<=int(n); i++)
  18. #define loop(i,y) for(int i=0; i<int(y); i++)
  19. #define rloop(i,y) for(int i=int(y)-1; i>=0; i--)
  20. #define read() freopen("input.txt", "r", stdin)
  21. #define write() freopen("output.txt", "w", stdout)
  22. #define cspf(i) printf("Case %d: ", i)
  23. /// Constants
  24. #define eps 1e-9
  25. #define PI acos(-1.0) // 3.1415926535897932
  26.  
  27. int main()
  28. {
  29. //read();
  30. char x[1000];
  31. while(scanf("%s",x)!=EOF){
  32. if(x[0]>='A' && x[0]<='Z'){
  33. int ln=strlen(x);
  34. int total=0;
  35. rloop(i,ln){
  36. if(x[i]=='V')
  37. total+=5;
  38. else if(x[i]=='L')
  39. total+=50;
  40. else if(x[i]=='D')
  41. total+=500;
  42. else if(x[i]=='I'){
  43. if(x[i+1]=='V' || x[i+1]=='X')
  44. total-=1;
  45. else
  46. total+=1;
  47. }
  48. else if(x[i]=='X'){
  49. if(x[i+1]=='L' || x[i+1]=='C')
  50. total-=10;
  51. else
  52. total+=10;
  53. }
  54. else if(x[i]=='C'){
  55. if(x[i+1]=='D' || x[i+1]=='M')
  56. total-=100;
  57. else
  58. total+=100;
  59. }
  60. else if(x[i]=='M')
  61. total+=1000;
  62. }
  63. printf("%d\n",total);
  64. }
  65. else if(x[0]>='0' && x[0]<='9'){
  66. int ln=strlen(x);
  67. char y[100];
  68. int z=ln;
  69. int j=0;
  70. loop(i,ln){
  71. z--;
  72. int k=x[i]-48;
  73. if(z>=3){
  74. int w=z-3;
  75. w=pow(10,w);
  76. k*=w;
  77. while(k--){
  78. y[j]='M';
  79. j++;
  80. }
  81. }
  82. else if(z==2){
  83. if(k<=3){
  84. while(k--){
  85. y[j]='C';
  86. j++;
  87. }
  88. }
  89. else if(k==4){
  90. y[j]='C';
  91. j++;
  92. y[j]='D';
  93. j++;
  94. }
  95. else if(k==5){
  96. y[j]='D';
  97. j++;
  98. }
  99. else if(k<=8){
  100. y[j]='D';
  101. j++;
  102. k-=5;
  103. while(k--){
  104. y[j]='C';
  105. j++;
  106. }
  107. }
  108. else if(k==9){
  109. y[j]='C';
  110. j++;
  111. y[j]='M';
  112. j++;
  113. }
  114. }
  115. else if(z==1){
  116. if(k<=3){
  117. while(k--){
  118. y[j]='X';
  119. j++;
  120. }
  121. }
  122. else if(k==4){
  123. y[j]='X';
  124. j++;
  125. y[j]='L';
  126. j++;
  127. }
  128. else if(k==5){
  129. y[j]='L';
  130. j++;
  131. }
  132. else if(k<=8){
  133. y[j]='L';
  134. j++;
  135. k-=5;
  136. while(k--){
  137. y[j]='X';
  138. j++;
  139. }
  140. }
  141. else if(k==9){
  142. y[j]='X';
  143. j++;
  144. y[j]='C';
  145. j++;
  146. }
  147. }
  148. else if(z==0){
  149. if(k<=3){
  150. while(k--){
  151. y[j]='I';
  152. j++;
  153. }
  154. }
  155. else if(k==4){
  156. y[j]='I';
  157. j++;
  158. y[j]='V';
  159. j++;
  160. }
  161. else if(k==5){
  162. y[j]='V';
  163. j++;
  164. }
  165. else if(k<=8){
  166. y[j]='V';
  167. j++;
  168. k-=5;
  169. while(k--){
  170. y[j]='I';
  171. j++;
  172. }
  173. }
  174. else if(k==9){
  175. y[j]='I';
  176. j++;
  177. y[j]='X';
  178. j++;
  179. }
  180. }
  181. }
  182. loop(s,j){
  183. printf("%c",y[s]);
  184. }
  185. printf("\n");
  186. }
  187. }
  188. return 0;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement