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

这题不难,一遍AC

代码

  1. #include<cstdio>
  2. #include<string>
  3. #include<vector>
  4. #include<iostream>
  5. using namespace std;
  6. int main(){
  7. string input, twice;
  8. vector<int> hash(10, 0);
  9. cin>>input;
  10. for(int i = 0; i < input.size(); i++){
  11. hash[input[i] - '0']++;
  12. }
  13. int carry = 0;
  14. for(int i = input.size() - 1; i >= 0; i--){
  15. int temp = (input[i] - '0') * 2 + carry;
  16. carry = temp / 10;
  17. temp = temp % 10;
  18. twice.insert(0, to_string((long long)temp));
  19. }
  20. if(carry != 0) twice.insert(0, to_string((long long)carry));
  21. for(int i = 0; i < twice.size(); i++){
  22. hash[twice[i] - '0']--;
  23. }
  24. int flag = 0;
  25. for(int i = 0; i < hash.size(); i++){
  26. if(hash[i] != 0){
  27. flag = 1;
  28. break;
  29. }
  30. }
  31. flag == 0 ? printf("Yes\n") : printf("No\n");
  32. cout<<twice;
  33. }