题解 | #小乐乐改数字#
小乐乐改数字
https://www.nowcoder.com/practice/fcd30aac9c4f4028b23919a0c649824d
#include <iostream>
#include<stack>
#include<vector>
using namespace std;
stack<char> sta;
vector<char> arr;
int main() {
string s;
cin >> s;
int i = 0;
int c = 0;
while (s[i] != '\0') {
c++;
i++;
}
for (int i = 0; i < c; ++i) {
if (s[i] % 2 == 0) {
s[i] = '0';
} else {
s[i] = '1';
}
}
for (int i = 0; i < c; ++i) {
sta.push(s[i]);
}
for (int i = 0; i < c; ++i) {
arr.push_back(sta.top());
sta.pop();
}
int j = 0;
int count = 0;
for (int i = 0; i < c; ++i) {
if (arr[i] == '0') {
count++;
} else {
break;
}
}
int countt = 0;
for (int i = 0; i < c; ++i) {
if (s[i] == '0') {
countt++;
} else {
break;
}
}
//cout <<count<<endl;
if (count == c) {
cout << '0';
} else {
for (int i = countt; i < c; ++i) {
cout << s[i];
}
}
return 0;
}
海康威视公司福利 1161人发布