fork(4) download
  1. #include <iostream>
  2. #include <vector>
  3. //////////////////////////////////////////////////
  4. class abacus_type
  5. {
  6. friend void operator>>(std::istream& in, abacus_type& obj);
  7.  
  8. std::vector<std::string> abacus;
  9. public:
  10. abacus_type()
  11. : abacus(15) {}
  12.  
  13. void number() const;
  14. void of(std::string &number);
  15. };
  16. //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  17. inline void operator>>(std::istream& in, abacus_type& obj)
  18. {
  19. in.get();
  20. for (auto &z : obj.abacus) getline(in, z);
  21. in.clear(in.rdstate() & ~(std::ios::failbit | std::ios::eofbit));
  22. }
  23. //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  24. void abacus_type::number() const
  25. {
  26. int row_size (abacus[0].size() - 1);
  27. char helper;
  28. std::string as_number;
  29. as_number.resize(row_size);
  30.  
  31. for (int i{1}; i < row_size; i++) {
  32. helper = (abacus[3][i] == '*')? '5' : '0';
  33.  
  34. for (int r{5}; abacus[r][i] != ' '; r++, helper++);
  35.  
  36. as_number[i - 1] = helper;
  37. }
  38.  
  39. as_number.erase(0, as_number.find_first_not_of('0'));
  40. if (as_number[0] == '\0') as_number = "0";
  41.  
  42. std::cout << as_number << '\n';
  43. }
  44. //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  45. void abacus_type::of(std::string &number)
  46. {
  47. number.erase(0, number.find_first_not_of('0'));
  48. if (number[0] == '\0') number = "0";
  49.  
  50. int row_size (number.size());
  51.  
  52. std::string frame (row_size + 2, '-'),
  53. interor {'|' + std::string(row_size, ' ') + '|'},
  54. interor2 {'|' + std::string(row_size, '*') + '|'};
  55.  
  56. abacus[0] = frame;
  57. abacus[1] = interor2;
  58. abacus[2] = interor2;
  59.  
  60. for (int i{3}; i < 14; i++) {
  61. if (i == 4) abacus[i] = '|' + std::string(row_size, '-') + '|';
  62. else abacus[i] = interor;
  63. }
  64.  
  65. abacus[14] = frame;
  66.  
  67. for (int j, i{1}; i <= row_size; i++) {
  68. if (number[i - 1] >= '5') std::swap(abacus[2][i], abacus[3][i]);
  69.  
  70. for (j = 0; j < (number[i - 1] - '0') % 5; j++)
  71. abacus[j + 5][i] = '*';
  72.  
  73. for (; j < 5; j++, abacus[8 + j][i] = '*');
  74. }
  75.  
  76. for (auto &z : abacus)
  77. std::cout << z << '\n';
  78. }
  79. //////////////////////////////////////////////////
  80. int main()
  81. {
  82. bool x;
  83. std::string number;
  84. abacus_type abacus;
  85.  
  86. while (std::cin >> x) {
  87. if (x) {
  88. std::cin >> number;
  89. abacus.of(number);
  90. } else {
  91. std::cin >> abacus;
  92. abacus.number();
  93. }
  94. }
  95. }
Success #stdin #stdout 0.01s 5444KB
stdin
1
0000
0
---
|*|
|*|
| |
|-|
| |
| |
| |
| |
|*|
|*|
|*|
|*|
|*|
---
1
00000009
0
--------
|******|
|******|
|      |
|------|
| *   *|
|      |
|      |
|      |
|* *** |
|******|
|******|
|******|
|******|
--------
1
1234321234321234321234321234321234321234321234321234321
stdout
---
|*|
|*|
| |
|-|
| |
| |
| |
| |
|*|
|*|
|*|
|*|
|*|
---
0
---
|*|
| |
|*|
|-|
|*|
|*|
|*|
|*|
| |
| |
| |
| |
|*|
---
10001
---------------------------------------------------------
|*******************************************************|
|*******************************************************|
|                                                       |
|-------------------------------------------------------|
|*******************************************************|
| ***** ***** ***** ***** ***** ***** ***** ***** ***** |
|  ***   ***   ***   ***   ***   ***   ***   ***   ***  |
|   *     *     *     *     *     *     *     *     *   |
|                                                       |
|*     *     *     *     *     *     *     *     *     *|
|**   ***   ***   ***   ***   ***   ***   ***   ***   **|
|*** ***** ***** ***** ***** ***** ***** ***** ***** ***|
|*******************************************************|
---------------------------------------------------------