Advertisement
Guest User

Untitled

a guest
Jan 31st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. string NumbersToString(int n, int count) {
  6.     string tmp;
  7.     for (int i = 0; i < count; i++) tmp += to_string(n);
  8.     return tmp;
  9. }
  10.  
  11. int main(int argc, char ** argv) {
  12.     int count[10];
  13.     for (int i = 0; i < 10; i++) count[i] = 0;
  14.  
  15.     char cur = 'a';
  16.     while (cur != '0')
  17.     {
  18.         cin >> cur;
  19.         int number = int(cur) - '0';
  20.         if (number > 0 && number < 10) count[number] ++;
  21.     }
  22.  
  23.     int i = 1;
  24.     for (i; i <= 9; i++)
  25.         if (count[i] % 3 != 0) break;
  26.         else count[i] /= 3;
  27.  
  28.     if (i < 10) cout << "NO";
  29.     else {
  30.         string result;
  31.         for (int i = 1; i <= 9; i++) result += NumbersToString(i, count[i]);
  32.         for (int i = 0; i < 3; i++) cout << result;
  33.     }
  34.  
  35.     system("pause");
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement