Advertisement
shimulxx

CF sample 2

May 17th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4.     //freopen("input.txt", "r", stdin);
  5.     ios::sync_with_stdio(0);
  6.     cin.tie(0), cout.tie(0);
  7.     string s;
  8.     int one = 0, two = 0, three = 0, i;
  9.     cin >> s;
  10.     for (i = 0; i < s.length(); i = i + 2) {
  11.         switch (s[i]) {
  12.         case '1':
  13.             ++one;
  14.             break;
  15.         case '2':
  16.             ++two;
  17.             break;
  18.         case '3':
  19.             ++three;
  20.             break;
  21.         default:
  22.             break;
  23.         }
  24.     }
  25.     i = 0;
  26.     while (one) {
  27.         s[i] = '1';
  28.         i += 2;
  29.         --one;
  30.     }
  31.     while (two) {
  32.         s[i] = '2';
  33.         i += 2;
  34.         --two;
  35.     }
  36.     while (three) {
  37.         s[i] = '3';
  38.         i += 2;
  39.         --three;
  40.     }
  41.     cout << s << "\n";
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement