题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805478658260992
代码
#include<cstdio>#include<string>#include<vector>#include<iostream>using namespace std;int main(){string input, twice;vector<int> hash(10, 0);cin>>input;for(int i = 0; i < input.size(); i++){hash[input[i] - '0']++;}int carry = 0;for(int i = input.size() - 1; i >= 0; i--){int temp = (input[i] - '0') * 2 + carry;carry = temp / 10;temp = temp % 10;twice.insert(0, to_string((long long)temp));}if(carry != 0) twice.insert(0, to_string((long long)carry));for(int i = 0; i < twice.size(); i++){hash[twice[i] - '0']--;}int flag = 0;for(int i = 0; i < hash.size(); i++){if(hash[i] != 0){flag = 1;break;}}flag == 0 ? printf("Yes\n") : printf("No\n");cout<<twice;}
