题解 | #小乐乐改数字#
小乐乐改数字
https://www.nowcoder.com/practice/fcd30aac9c4f4028b23919a0c649824d
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
long long a,c;
cin>>a;
string b,d;
b = to_string(a);
d = b;
for (int i=0; i<b.length(); i++) {
if((int)b[i]%2==0){
d[i]= '0';
}
else {
d[i]= '1';
}
}
cout<<stoi(d);
}
// 64 位输出请用 printf("%lld")
熟练使用int转string 与 string转int。stoi可以将string转int。to_string 可以直接将int转string。另外给string赋值的时候记住:要赋字符的值。