練習,練習!心態要好。。。
int型最大值:2147483648
生詞:
duplication n.重複; permutation n.排列; double vt.雙倍 ;
#include<cstring>
#include<cstdio>
//22:20。思路清楚,希望20分鐘內初稿,40分鐘內調試完
//實際22:57初稿,走運的是一遍就過了。不對,不是運氣,是實力 (。-`ω´-)
struct bign{
int b[25];
int len;
bign(){
len=0;
memset(b,0,sizeof(b));
}
};
bign change(char s[]){
bign d;
d.len=strlen(s);
for(int i=0;i<strlen(s);i++){
d.b[d.len-i-1]=s[i]-'0';
}
return d;
}
bign mutiDouble(bign a){
bign d;
int carry=0,temp=0;
for(int i=0;i<a.len;i++){
temp=2*a.b[i]+carry;
d.b[d.len++]=temp%10;
carry=temp/10;
}
while(carry!=0){
d.b[d.len++]=carry%10;
carry=carry/10;
}
return d;
}
void printBign(bign a){
for(int i=a.len-1;i>=0;i--){
printf("%d",a.b[i]);
}
}
int check(bign a,bign b){
if(a.len!=b.len){
return 0;
}else{
int hasha[10]={},hashb[10]={};
for(int i=0;i<a.len;i++){
hasha[a.b[i]]++;
}
for(int i=0;i<b.len;i++){
hashb[b.b[i]]++;
}
for(int i=0;i<10;i++){
if(hasha[i]!=hashb[i]){
return 0;
}
}
}
return 1;
}
/*
bool judge(bign a,bign b){
if(a.len!=b.len)return false;
int count[10]={};
for(int i=0;i<a.len;i++){
count[a.d[i]]++;
count[b.d[i]]--;
}
for(int i=0;i<10;i++){
if(count[i]!=0){
return false;
}
}
return true;
}
*/
int main(){
char A[25]={};
scanf("%s",A);
bign a=change(A);
bign doua=mutiDouble(a);
if(check(a,doua)){
printf("Yes\n");
}else{
printf("No\n");
}
printBign(doua);
return 0;
}