PAT1023. Have Fun with Numbers (20)
#include <iostream> #include <map> #include <algorithm> using namespace std; string a; string b; bool cmp(char a,char b){ return a<b; } int main() { cin>>a; b=a; int num;int c=0; for(int i=a.length()-1;i>=0;i--){ num=(a[i]-'0')*2+c; c=num/10; b[i]=num%10+'0'; } if(c!=0){cout<<"No"<<endl;cout<<c<<b;} else{ sort(a.begin(),a.end(),cmp); string c=b; sort(b.begin(),b.end(),cmp); if(a.compare(b)==0){cout<<"Yes"<<endl;} else {cout<<"No"<<endl;} cout<<c; } return 0; }