PAT 1023
输入
1234567899
  输出
Yes
2469135798
  #include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;
int main()
{
    string s1,s2="";
    cin>>s1;
    reverse(s1.begin(),s1.end());
    auto it=s1.begin();
    int carry=0;
    while(it!=s1.end())
    {
        int temp=( *it -'0')*2+carry;
        carry=temp/10;
        char c=temp%10 + '0';
        s2.push_back(c);
        it++;
    } 
//这里没有必要,因为,如果最终多出一个进位,也就e
//二者的长度不同了,这样一定是no 
//这里之前错了,直接写的是s2.push_back(carry)
//要注意carry是int型 0/1, 需要push进去字符型 ‘1’ 
    if( carry!=0)
    {
        s2.push_back('1');
    } 
    reverse(s2.begin(),s2.end());
    string s3=s2;
    sort(s1.begin(),s1.end());
    sort(s3.begin(),s3.end());
    if(s1==s3 )
    {
        cout<<"Yes"<<endl;  
    }
    else
    {
        cout<<"No"<<endl;   
    }
    cout<<s2;
    return 0;
}

京公网安备 11010502036488号