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 file 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:1234567899Sample Output:
Yes 2469135798
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <memory.h>
- #include <cstdio>
- #include <cstdlib>
- #include <vector>
- using namespace std;
- #define MAX 0Xfffffff
- char s[25];
- int a[10];
- int b[30];
- string multi(){
- string res;
- int len = strlen(s);
- memset(b, 0, sizeof(b));
- int k = 0;
- for(int i=len-1;i>=0;i--){
- b[k++] = (s[i]-'0')*2;
- }
- for(int i=0;i<k;++i){
- if(b[i]>=10){
- b[i+1] += b[i]/10;
- b[i] %= 10;
- }
- }
- if(b[k]!=0)
- k++;
- for(int i=k-1;i>=0;--i)
- res += (b[i]+'0');
- return res;
- }
- bool assert(string str){
- for(int i=0;i<str.length();i++){
- a[str[i]-'0']--;
- }
- for(int i=0;i<10;++i)
- if(a[i]!=0)
- return false;
- return true;
- }
- int main(){
- //freopen("in.txt", "r", stdin);
- cin>>s;
- memset(a, 0, sizeof(a));
- int len = strlen(s);
- for(int i=0;i<len;++i){
- a[s[i]-'0']++;
- }
- string s = multi();
- if(assert(s)){
- printf("Yes\n");
- }else{
- printf("No\n");
- }
- cout<<s<<endl;
- //fclose(stdin);
- }