1.比较简单的一道题
#include
#include
using namespace std;
vector PlusOne(vector &vec)
{
int n = vec.size();
for (int i = n - 1; i >= 0; i–)
{
if (vec[i] == 9) vec[i] = 0;
else
{
vec[i] = vec[i] + 1;
return vec;
}
}
if (vec.front() == 0) vec.insert(vec.begin(), 1);
return vec;
}
int main()
{
vector vec{ 9,9,9 };
auto veci = PlusOne(vec);
for (auto x : veci)
{
cout << x << " ";
}
cout << endl;
system(“pause”);
return 0;
}