Advertisement
Korotkodul

гирлянда_WA_debug

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