Day48: [PAT甲级] 1023 Have Fun with Numbers (20分)

Day48: [PAT甲级] 1023 Have Fun with Numbers (20分)

题源:

来自PAT真题库:

https://pintia.cn/problem-sets/994805342720868352/problems/994805478658260992

代码:

dirty code凑合看吧

#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<algorithm>
using namespace std;
string s,res;
int main() {
	cin >> s;
	unordered_set<char> se1, se2;
	int jinwei = 0;
	for (int i=s.size()-1;i>=0;i--) {
		se1.insert(s[i]);
		int x = (s[i] - '0') * 2+jinwei;
		if (x >= 10) {
			jinwei = 1;
			x -= 10;
		}
		else jinwei = 0;
		res.append(1, '0' + x);
		se2.insert('0'+x);
	}
	if (jinwei != 0) {
		res.append(1, '0' + jinwei);
		se2.insert('0' + jinwei);
	}
	reverse(res.begin(), res.end());
	if (se1 == se2) cout << "Yes" << endl;
	else cout << "No" << endl;
	cout << res << endl;
	
	system("pause");
}
发布了49 篇原创文章 · 获赞 13 · 访问量 495

猜你喜欢

转载自blog.csdn.net/qq2215459786/article/details/104045911
今日推荐