T3000

Untitled

Sep 25th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5. using ld = long double;
  6.  
  7. int main()
  8. {
  9.     ll s, n;
  10.     cin >> s >> n;
  11.     vector<ll> a(s + 1);
  12.     ll ax;
  13.     for (int i = 0; i < n; i++)
  14.     {
  15.  
  16.         cin >> ax;
  17.         a.at(ax) = 1;
  18.     }
  19.     vector<pair<ll, ll>> er;
  20.     vector<pair<ll, ll>> cr;
  21.     ax = 1;
  22.     for (int i = 1; i <= s; i++)
  23.     {
  24.         if (i == s || a.at(i) != a.at(i + 1))
  25.         {
  26.             if (a.at(i) == 1)
  27.             {
  28.                 er.push_back({ax, i});
  29.             }
  30.             else
  31.             {
  32.                 cr.push_back({ax, i});
  33.             }
  34.             ax = i + 1;
  35.         }
  36.     }
  37.  
  38.     cout << "Errors: ";
  39.     if (er.size() == 1)
  40.     {
  41.         if (er.at(0).first == er.at(0).second)
  42.         {
  43.             cout << er.at(0).first << endl;
  44.         }
  45.         else
  46.         {
  47.             cout << er.at(0).first << "-" << er.at(0).second << endl;
  48.         }
  49.     }
  50.     else
  51.     {
  52.         if (er.at(0).first == er.at(0).second)
  53.         {
  54.             cout << er.at(0).first;
  55.         }
  56.         else
  57.         {
  58.             cout << er.at(0).first << "-" << er.at(0).second;
  59.         }
  60.         for (int i = 1; i < er.size() - 1; i++)
  61.         {
  62.             cout << ", ";
  63.             if (er.at(i).first == er.at(i).second)
  64.             {
  65.                 cout << er.at(i).first;
  66.             }
  67.             else
  68.             {
  69.                 cout << er.at(i).first << "-" << er.at(i).second;
  70.             }
  71.         }
  72.         cout << " and ";
  73.         if (er.at(er.size() - 1).first == er.at(er.size() - 1).second)
  74.         {
  75.             cout << er.at(er.size() - 1).first;
  76.         }
  77.         else
  78.         {
  79.             cout << er.at(er.size() - 1).first << "-" << er.at(er.size() - 1).second;
  80.         }
  81.         cout << endl;
  82.     }
  83.     cout << "Correct: ";
  84.     if (cr.size() == 1)
  85.     {
  86.         if (cr.at(0).first == cr.at(0).second)
  87.         {
  88.             cout << cr.at(0).first << endl;
  89.         }
  90.         else
  91.         {
  92.             cout << cr.at(0).first << "-" << cr.at(0).second << endl;
  93.         }
  94.     }
  95.     else
  96.     {
  97.         if (cr.at(0).first == cr.at(0).second)
  98.         {
  99.             cout << cr.at(0).first;
  100.         }
  101.         else
  102.         {
  103.             cout << cr.at(0).first << "-" << cr.at(0).second;
  104.         }
  105.         for (int i = 1; i < cr.size() - 1; i++)
  106.         {
  107.             cout << ", ";
  108.             if (cr.at(i).first == cr.at(i).second)
  109.             {
  110.                 cout << cr.at(i).first;
  111.             }
  112.             else
  113.             {
  114.                 cout << cr.at(i).first << "-" << cr.at(i).second;
  115.             }
  116.         }
  117.         cout << " and ";
  118.         if (cr.at(cr.size() - 1).first == cr.at(cr.size() - 1).second)
  119.         {
  120.             cout << cr.at(cr.size() - 1).first;
  121.         }
  122.         else
  123.         {
  124.             cout << cr.at(cr.size() - 1).first << "-" << cr.at(cr.size() - 1).second;
  125.         }
  126.         cout << endl;
  127.     }
  128.     return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment