paranid5

Vsesib1

Oct 18th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <deque>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     string input;
  10.     cin >> input;
  11.  
  12.     if (input[0] == '0')
  13.         putchar('0');
  14.  
  15.     else
  16.     {
  17.         uint64_t cnt = 0;
  18.         deque<char> first(1);
  19.  
  20.         int ind = 1;
  21.         first[0] = input[0];
  22.  
  23.         while (input[ind] == '0')
  24.             first.push_back(input[ind++]);
  25.  
  26.         deque<char> second(input.size() - ind);
  27.  
  28.         for (int i = ind; i < input.size(); i++)
  29.             second[i - ind] = input[i];
  30.  
  31.         auto test = [&first, &second] () {
  32.             if (first.size() == second.size())
  33.                 return (lexicographical_compare(first.begin(), first.end(), second.begin(), second.end())
  34.                 || equal(first.begin(), first.end(), second.begin(), second.end()));
  35.             else return first.size() <= second.size();
  36.         };
  37.  
  38.         if (test())
  39.             cnt++;
  40.  
  41.         while (test())
  42.         {
  43.             first.push_back(second.front());
  44.             second.pop_front();
  45.  
  46.             while (second.front() == '0')
  47.             {
  48.                 first.push_back(second.front());
  49.                 second.pop_front();
  50.             }
  51.  
  52.             if (test())
  53.                 cnt++;
  54.         }
  55.  
  56.         printf("%lld", cnt);
  57.     }
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment