Saleh127

UVA 11616

Jul 1st, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. int main()
  7. {
  8. fellow_junior
  9. string a;
  10. ll c,d,e,f,i,j,k,l;
  11. while(cin>>a)
  12. {
  13. l=a.size();
  14. if(a[0]>='A' && a[0]<='Z')
  15. {
  16. c=0;
  17. for(i=0; i<l; i++)
  18. {
  19. if(a[i]=='I' && a[i+1]=='V')
  20. {
  21. c+=4;
  22. i+=1;
  23. }
  24. else if(a[i]=='I' && a[i+1]=='X')
  25. {
  26. c+=9;
  27. i+=1;
  28. }
  29. else if(a[i]=='X' && a[i+1]=='L')
  30. {
  31. c+=40;
  32. i+=1;
  33. }
  34. else if(a[i]=='X' && a[i+1]=='C')
  35. {
  36. c+=90;
  37. i+=1;
  38. }
  39. else if(a[i]=='C' && a[i+1]=='D')
  40. {
  41. c+=400;
  42. i+=1;
  43. }
  44. else if(a[i]=='C' && a[i+1]=='M')
  45. {
  46. c+=900;
  47. i+=1;
  48. }
  49. else if(a[i]=='I') c+=1;
  50. else if(a[i]=='X') c+=10;
  51. else if(a[i]=='C') c+=100;
  52. else if(a[i]=='V') c+=5;
  53. else if(a[i]=='L') c+=50;
  54. else if(a[i]=='D') c+=500;
  55. else if(a[i]=='M') c+=1000;
  56. }
  57. cout<<c<<endl;
  58. }
  59. else
  60. {
  61. d=0;
  62. d=stoi(a);
  63. string x="";
  64. while(d>0)
  65. {
  66. if(d>=1000)
  67. {
  68. x+='M';
  69. d-=1000;
  70. }
  71. else if(d>=900)
  72. {
  73. x+='C';
  74. x+='M';
  75. d-=900;
  76. }
  77. else if(d>=500)
  78. {
  79. x+='D';
  80. d-=500;
  81. }
  82. else if(d>=400)
  83. {
  84. x+='C';
  85. x+='D';
  86. d-=400;
  87. }
  88. else if(d>=100)
  89. {
  90. x+='C';
  91. d-=100;
  92. }
  93. else if(d>=90)
  94. {
  95. x+='X';
  96. x+='C';
  97. d-=90;
  98. }
  99. else if(d>=50)
  100. {
  101. x+='L';
  102. d-=50;
  103. }
  104. else if(d>=40)
  105. {
  106. x+='X';
  107. x+='L';
  108. d-=40;
  109. }
  110. else if(d>=10)
  111. {
  112. x+='X';
  113. d-=10;
  114. }
  115. else if(d>=9)
  116. {
  117. x+='I';
  118. x+='X';
  119. d-=9;
  120. }
  121. else if(d>=5)
  122. {
  123. x+='V';
  124. d-=5;
  125. }
  126. else if(d>=4)
  127. {
  128. x+='I';
  129. x+='V';
  130. d-=4;
  131. }
  132. else if(d>=1)
  133. {
  134. x+='I';
  135. d-=1;
  136. }
  137. }
  138. cout<<x<<endl;
  139. }
  140. }
  141. return 0;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment