1023. Have Fun with Numbers (20)
2017-02-06 17:01
267 查看
比较水的一道题,用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; }
相关文章推荐
- 【PAT甲级】1023. Have Fun with Numbers (20)
- PAT (Advanced Level) Practise 1023. Have Fun with Numbers (20)
- 浙江大学PAT_甲级_1023. Have Fun with Numbers (20)
- PAT甲级 1023. Have Fun with Numbers (20)
- PAT (Advanced Level) Practise 1023. Have Fun with Numbers (20)
- 【PAT】1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT-1023 Have Fun with Numbers (20)
- PAT_A 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT1023. Have Fun with Numbers (20)
- PAT甲级 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT: 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20) 模拟大数乘法
- PAT (Advanced Level) 1023. Have Fun with Numbers (20) 字符串翻倍,哈希