forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAC_simulation_n.cpp
48 lines (43 loc) · 969 Bytes
/
AC_simulation_n.cpp
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
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_n.cpp
* Create Date: 2014-12-20 10:07:27
* Descripton:
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
int len = digits.size();
bool carry = true;
for (int i = len - 1; i >= 0; i--) {
carry = ((digits[i] + 1) % 10 == 0);
if (carry) {
digits[i] = 0;
} else {
digits[i]++;
return digits;
}
}
vector<int> res(len + 1, 0);
res[0] = 1;
return res;
}
};
int main() {
vector<int> v;
Solution s;
string str;
while (cin >> str) {
v.clear();
for (char i : str)
v.push_back(i - '0');
v = s.plusOne(v);
for (int i : v)
cout << i;
cout << endl;
}
return 0;
}