#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
static unsigned long long _count = 0;
uint32_t T;
static unsigned long long _curr, _prev = 0;
std::vector<int> vectorize(unsigned long long x)
{
std::vector<int> numbers;
while (x>0)
{
numbers.push_back(x % 10);
x /= 10;
}
std::reverse(std::begin(numbers), std::end(numbers));
return numbers;
}
unsigned long long compare(unsigned long long x, unsigned long long y)
{
std::vector<int> xx = vectorize(x);
std::vector<int> yy = vectorize(y);
int xx_s = xx.size();
int yy_s = yy.size();
if (xx_s == yy_s)
{
if (x<y)
return y;
else
{
_count++;
return y * 10;
}
}
else if (xx_s > yy_s)
{
while (xx_s > yy.size())
{
yy.push_back(0);
y = y * 10;
_count++;
}
if (!std::lexicographical_compare(xx.begin(), xx.end(), yy.begin(), yy.end()))
{
if (xx_s >= 2)
{
for (int ii = 1; ii <= yy.size() - 1; ii++)
{
if (yy[ii - 1] < xx[ii - 1])
{
_count++;
y = y * 10;
return y;
}
else if (xx[xx_s - ii] < 9)
return y + (xx[xx_s - ii]) * ((pow(10, ii - 1))) + 1;
}
_count++;
return y * 10;
}
}
return y;
}
return y;
}
int main()
{
uint32_t T;
cin>>T;
for (size_t i = 0; i < T; ++i)
{
cin>>_curr;
_prev = compare(_prev, _curr);
}
cout << _count << endl;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include <bits/stdc++.h> #include <iostream> #include <string> #include <vector> using namespace std; static unsigned long long _count = 0; uint32_t T; static unsigned long long _curr, _prev = 0; std::vector<int> vectorize(unsigned long long x) { std::vector<int> numbers; while (x>0) { numbers.push_back(x % 10); x /= 10; } std::reverse(std::begin(numbers), std::end(numbers)); return numbers; } unsigned long long compare(unsigned long long x, unsigned long long y) { std::vector<int> xx = vectorize(x); std::vector<int> yy = vectorize(y); int xx_s = xx.size(); int yy_s = yy.size(); if (xx_s == yy_s) { if (x<y) return y; else { _count++; return y * 10; } } else if (xx_s > yy_s) { while (xx_s > yy.size()) { yy.push_back(0); y = y * 10; _count++; } if (!std::lexicographical_compare(xx.begin(), xx.end(), yy.begin(), yy.end())) { if (xx_s >= 2) { for (int ii = 1; ii <= yy.size() - 1; ii++) { if (yy[ii - 1] < xx[ii - 1]) { _count++; y = y * 10; return y; } else if (xx[xx_s - ii] < 9) return y + (xx[xx_s - ii]) * ((pow(10, ii - 1))) + 1; } _count++; return y * 10; } } return y; } return y; } int main() { uint32_t T; cin>>T; for (size_t i = 0; i < T; ++i) { cin>>_curr; _prev = compare(_prev, _curr); } cout << _count << endl; return 0; } |
English