fork(8) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <vector>
  5. #include <queue>
  6. #include <valarray>
  7. #include <string>
  8. #include <cmath>
  9. #include <numeric>
  10. #include <cctype>
  11. #include <set>
  12. #include <map>
  13.  
  14. #define PB push_back
  15. #define SIZE(x) (int)x.size()
  16.  
  17. using namespace std;
  18.  
  19. typedef long long LL;
  20. typedef unsigned long long ULL;
  21.  
  22. typedef vector<int> VI;
  23. typedef vector<string> VS;
  24. typedef vector<bool> VB;
  25. typedef valarray<LL> VALI;
  26. typedef valarray<char> VALC;
  27. typedef multiset<char> MC;
  28. typedef set<int> SI;
  29. typedef vector<string> VS;
  30.  
  31. //inline double round(const double& x) { return floor(x+0.5); }
  32.  
  33. template <class T>
  34. istream& operator>>(istream& input, vector<T>& V)
  35. {
  36. for (int i = 0; i<SIZE(V); ++i) input >> V[i];
  37. return input;
  38. }
  39.  
  40. class abakus
  41. {
  42. private:
  43. string T[15];
  44. int ileKolumn;
  45. string cyfryKol[10];
  46. string napis;
  47.  
  48. void budujKolumne(int kolumna, int cyfra)
  49. {
  50. for (int i = 0; i<11; ++i) T[i + 2][kolumna] = cyfryKol[cyfra][i];
  51. }
  52. int czytajKolumne(int kolumna)
  53. {
  54. string kol;
  55. for (int i = 0; i<11; ++i) kol += T[i + 2][kolumna];
  56. for (int cyfra = 0; cyfra <= 9; ++cyfra)
  57. {
  58. if (cyfryKol[cyfra] == kol) return cyfra;
  59. }
  60. return -1;
  61. }
  62. void usunWiodaceZera()
  63. {
  64. napis.erase(0, napis.find_first_not_of('0'));
  65. if (napis.empty()) napis = "0";
  66. }
  67. public:
  68. abakus()
  69. {
  70. cyfryKol[0] = "* - ****";
  71. cyfryKol[1] = "* -* ***";
  72. cyfryKol[2] = "* -** **";
  73. cyfryKol[3] = "* -*** *";
  74. cyfryKol[4] = "* -**** ";
  75. cyfryKol[5] = " *- ****";
  76. cyfryKol[6] = " *-* ***";
  77. cyfryKol[7] = " *-** **";
  78. cyfryKol[8] = " *-*** *";
  79. cyfryKol[9] = " *-**** ";
  80. }
  81. void czytaj(const string& S)
  82. {
  83. napis = S;
  84. ileKolumn = SIZE(S);
  85.  
  86. for (int i = 0; i<15; ++i)
  87. {
  88. if (i == 0 || i == 14) T[i] = string(ileKolumn + 2, '-');
  89. else T[i] = string(ileKolumn + 2, '|');
  90. }
  91. for (int i = 1; i <= ileKolumn; ++i)
  92. {
  93. T[0][i] = T[14][i] = '-';
  94. T[13][i] = T[1][i] = '*';
  95. }
  96.  
  97. for (int i = 0; i<ileKolumn; ++i)
  98. {
  99. int cyfra = S[i] - '0';
  100. budujKolumne(i + 1, cyfra);
  101. }
  102. }
  103. void czytaj()
  104. {
  105. cin.ignore();
  106.  
  107. for (int i = 0; i<15; ++i)
  108. {
  109. string wiersz;
  110. getline(cin, wiersz);
  111. if (i == 0) ileKolumn = SIZE(wiersz);
  112. T[i] = wiersz;
  113. }
  114. for (int i = 1; i<ileKolumn - 1; ++i)
  115. {
  116. int cyfra = czytajKolumne(i);
  117. napis += '0' + cyfra;
  118. }
  119. usunWiodaceZera();
  120. }
  121. void wypisz()
  122. {
  123. cout << napis;
  124. }
  125. void rysuj()
  126. {
  127. for (int i = 0; i<14; ++i) cout << T[i] << endl;
  128. cout << T[14];
  129. }
  130. };
  131.  
  132. int main()
  133. {
  134. ios::sync_with_stdio(0);
  135.  
  136. bool first = true;
  137.  
  138. int x;
  139. while (cin >> x)
  140. {
  141. if (first) first = false;
  142. else cout << endl;
  143.  
  144. abakus A;
  145. if (x == 0)
  146. {
  147. A.czytaj();
  148. A.wypisz();
  149. }
  150. else
  151. {
  152. string napis;
  153. cin >> napis;
  154. A.czytaj(napis);
  155. A.rysuj();
  156. }
  157. }
  158.  
  159. return 0;
  160. }
Success #stdin #stdout 0s 15240KB
stdin
0
---------------------------------------------------------
|*******************************************************|
|*******         *******         *******         *******|
|       *********       *********       *********       |
|-------------------------------------------------------|
|******* ******* ******* ******* ******* ******* *******|
|*** ***  *****  *** ***  *****  *** ***  *****  *** ***|
|**   **   ***   **   **   ***   **   **   ***   **   **|
|*     *    *    *     *    *    *     *    *    *     *|
|       *       *       *       *       *       *       |
|   *   **     **   *   **     **   *   **     **   *   |
|  ***  ***   ***  ***  ***   ***  ***  ***   ***  ***  |
| ***** **** **** ***** **** **** ***** **** **** ***** |
|*******************************************************|
---------------------------------------------------------
0
-----
|***|
|***|
|   |
|---|
|   |
|   |
|   |
|   |
|***|
|***|
|***|
|***|
|***|
-----
0
----
|**|
|**|
|  |
|--|
| *|
|  |
|  |
|  |
|* |
|**|
|**|
|**|
|**|
----
stdout
4321234567898765432123456789876543212345678987654321234
0
1