标签:clu ios define ice out 需要 specific last sts
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:
1234567899
Sample Output:
Yes
2469135798
#include<iostream>
#include<set>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
string a, da;
int na[22], nda[22];
void GetNum(string t, int *n){
if(t == "0") {
n[0]++;
return ;
}
for(int i = 0; i < t.size(); i++){
// s.insert(t[i]-‘0‘);
n[t[i]-‘0‘]++;
}
return ;
}
string Double(string t){
string tt = "";
reverse(t.begin(), t.end());
int last = 0, th = 0;
for(int i = 0; i < t.size(); i++){
th = 2*(t[i]-‘0‘) + last;
tt.push_back(th%10 + ‘0‘);
last = th/10;
}
if(last != 0) tt.push_back(last+‘0‘);
// cout<<tt<<endl;
return tt;
}
void PrintStatus(int *a){
for(int i = 0; i < 10; i++){
printf("%d ", a[i]);
}
printf("\n");
}
int main(){
// freopen("test.txt", "r", stdin);
cin>>a;
da = Double(a);
memset(na, 0, sizeof(na));
memset(nda, 0, sizeof(nda));
GetNum(a, na);
GetNum(da, nda);
// PrintStatus(na);
// PrintStatus(nda);
bool flag = true;
for(int i = 0; i < 10; i++){
if(na[i] != nda[i]) flag = false;
}
if(flag) puts("Yes");
else puts("No");
reverse(da.begin(), da.end());
cout<<da;
return 0;
}
1023 Have Fun with Numbers (20)(20 point(s))
标签:clu ios define ice out 需要 specific last sts
原文地址:https://www.cnblogs.com/yoyo-sincerely/p/9326425.html