Advertisement
DimaT1

Untitled

Oct 15th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. void print(long long a, long long b) {
  8. string s;
  9. int j = 0;
  10. if(a)
  11. {while(a) {
  12. if(j == 3) {
  13. j = 0;
  14. s+= '.';}
  15.  
  16. s+= '0' + a%10;
  17. a/= 10;
  18. j++;
  19. }
  20. reverse(s.begin(), s.end());
  21. cout << s;
  22. }
  23. else
  24. cout << 0;
  25.  
  26. if(b) {
  27. cout << '.';
  28. if(b < 10)
  29. cout << 0 << b;
  30. else
  31. cout << b;
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. string s;
  38. cin >> s;
  39. // s = "a1b220.555c0.16d123.156.156.123.60d0.99e100.99";
  40.  
  41. long long rub = 0;
  42. long long cop = 0;
  43. long long _buf1 = 0;
  44. long long _buf2 = 0;
  45.  
  46. int j = 0;
  47. s+= 'a';
  48.  
  49. bool flag = false;
  50.  
  51. for(int i = 0; i < s.size(); i++) {
  52. if( ('a' <= s.at(i)) && (s.at(i) <= 'z') ) {
  53. if(flag == 0 && _buf1 == 0) {
  54. rub += _buf2;
  55. _buf1 = 0;
  56. _buf2 = 0;
  57. continue;
  58. }
  59.  
  60. flag = false;
  61. if(j == 2) {
  62. cop+= _buf2;
  63. rub+= _buf1;
  64. if(cop >= 100) {
  65. rub++;
  66. cop -= 100;
  67. }
  68. _buf1 = 0;
  69. _buf2 = 0;
  70. }
  71. else {
  72. rub+= (_buf1 * 1000) + _buf2;
  73. _buf1 = 0;
  74. _buf2 = 0;
  75. }
  76. }
  77. else if(s.at(i) == '.') {
  78. j=0;
  79. flag = 1;
  80. if(j == 4)
  81. j = 1;
  82. _buf1*= 1000;
  83. _buf1+= _buf2;
  84. _buf2 = 0;
  85. }
  86. else {
  87. if(flag) {
  88. j++;
  89. }
  90.  
  91. _buf2*= 10;
  92. _buf2+= s.at(i) - '0';
  93. }
  94.  
  95. }
  96.  
  97. print(rub, cop);
  98.  
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement