比较水的一道题,用string存储输入,然后*2成另一个string,通过sort后比较是否一样来判断Y/N
#include<iostream>#include<string>#include<algorithm>using namespace std;string double_str(string str){ int temp=0; for (auto it = str.rbegin();it != str.rend();it++) { if ((*it - '0') * 2 + temp > 9) { *it = (*it - '0') * 2 + temp - 10 + '0'; temp = 1; } else { *it=(*it - '0') * 2 + temp + '0'; temp = 0; } } if (temp == 1) str.insert(str.begin(), '1'); return str;}int main(){ string str1, str2,str3; cin >> str1; str2 = double_str(str1); str3 = str2; sort(str1.begin(), str1.end()); sort(str2.begin(), str2.end()); if (str1 == str2) cout << "Yes" << endl<<str3 << endl; else cout << "No" << endl << str3 << endl;}新闻热点
疑难解答