1023 Have Fun with Numbers
1023 Have Fun with Numbers
分数 20
全屏浏览
切换布局
作者 CHEN, Yue
单位 浙江大学
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
1.分析
1.20位数字,用字符串进行运算。
2.数字标记出现数字的次数,a中出现加一,b中出现减一。最后判断是否为0即可。
2.代码
#include<iostream>
#include<vector>
using namespace std;
string a,b;
vector<int> v;
int idx[12],t;
bool check(){ //判断for(int i=0;i<10;i++){if(idx[i]!=0) return false;}return true;
}
int main(){cin>>a;for(int i=0;i<a.size();i++){ //标记aidx[a[i]-'0']++;}for(int i=a.size()-1;~i;i--){ //计数bt+=(a[i]-'0')*2; //进位加法idx[t%10]--;v.push_back(t%10); //存储t/=10;}if(t!=0) idx[t]--,v.push_back(t);if(check()) cout<<"Yes"<<endl;else cout<<"No"<<endl;for(int i=v.size()-1;i>=0;i--){ //输出cout<<v[i];}return 0;
}