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.
intmain() { string s; cin >> s; int c = 0; for (int i = s.length() - 1; i >= 0; i--) { st[s[i] - '0']++; }
for (int i = s.length() - 1; i >= 0; i--) { int k = (s[i] - '0') * 2 + c; s[i] = char('0' + k % 10); c = k / 10; } if (c) s.insert(0,to_string(c)); // cout << s; bool flag = false; for(int i = 0; i <= 9; i++) { if (st[i]) { int k = 1; for (int j = 0; j < s.length(); j++){ if (s[j] == (i + '0')) { k++; } } if (st[i] == k){ cout << "No\n"; for (int i = 0; i < s.length(); i++) cout << s[i]; return0; } } else { for (int j = 0; j < s.length(); j++){ if (s[j] == (i + '0')) { cout << "No\n"; for (int i = 0; i < s.length(); i++) cout << s[i]; return0; } } }
}
cout << "Yes\n"; for (int i = 0; i < s.length(); i++) cout << s[i];