题目地址

Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!

Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

Input Specification:
Each input contains one test case. Each case contains one positive integer with no more than 20 digits.

Output Specification:
For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.

Sample Input:
1234567899

Sample Output:
Yes
2469135798

作者: CHEN, Yue
单位: 浙江大学
时间限制: 400 ms
内存限制: 64 MB

#include <iostream>
#include <vector>
#include<algorithm>
#include <cmath>
#include<map>
#include<cstring>
#include<queue>
#include<string>
#include<set>
using namespace std;
typedef long long ll;
const int maxn=10010;
map<char,int>mp,mp2;
string dou(string n){
    string m=n;int flag=0;
    for(int i=n.length()-1;i>=0;i--){
        int t=(n[i]-'0')*2+flag;
        if(t>9) {
            t-=10;flag=1;
        }
        else flag=0;
        m[i]=t+'0';
    }
    if(flag==1) m="1"+m;
    return m;                                   //一定一定不要忘了函数返回;
}
int main(){
    string n;
    cin>>n;
    for(int i=0;i<n.length();i++) mp[n[i]]++;
    string m=dou(n);
    if(m.length()<n.length()) {
        cout<<"No"<<endl;
        cout<<m;return 0;
    }
    for(int i=0;i<m.length();i++){
        mp2[m[i]]++;
    }
    if(mp!=mp2) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    cout<<m;
}