Advertisement
Korotkodul

гирлянда_v1

Mar 28th, 2023
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <algorithm>
  5. #define pb push_back
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int f(string s)
  11. {
  12.     set <char> all;
  13.     vector <char> v;
  14.     for (int i = 0; i < 4; ++i) {
  15.         char k = s[i];
  16.         all.insert(k);
  17.         v.pb(k);
  18.     }
  19.     if (all.size() == 1) {
  20.         return -1;
  21.     }
  22.     if (all.size() == 2) {
  23.         int x = count(v.begin(), v.end(), v[0]);
  24.         if (x == 1 || x == 3) {
  25.             return 6;
  26.         }
  27.     }
  28.     return 4;
  29. }
  30.  
  31. int sol(string s) {
  32.     vector<int> cnt(10);
  33.     for (auto c : s) ++cnt[c - '0'];
  34.     int mx = *max_element(cnt.begin(), cnt.end());
  35.     if (mx == 4) return -1;
  36.     else if (mx == 3) return 6;
  37.     else return 4;
  38. }
  39.  
  40. /*
  41. 3
  42. 9546
  43. 0000
  44. 3313
  45. */
  46. int main()
  47. {
  48.     int t; cin >> t;
  49.     ios::sync_with_stdio(0);
  50.     cin.tie(0);
  51.     cout.tie(0);
  52.     for (int i = 0; i < t; ++i) {
  53.         string s; cin >> s;
  54.         int my = f(s);
  55.         int he = sol(s);
  56.         if (he != my) {
  57.             cout << "WA\n";
  58.             cout << "my = " << my << "\n";
  59.             cout << "he = " << he << "\n";
  60.         }
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement