作者:yunjinqi 类别:
日期:2023-05-29 16:13:39
阅读:444 次 消耗积分:0 分
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int is_same_digits(int *arr1, int *arr2) {
int arr_d_1[10]={0};
int arr_d_2[10]={0};
int d1=0,d2=0;
int i;
int v1,v2;
for (i=0;i<21;i++){
v1 = arr1[i];
v2 = arr2[i];
if (v1!=0){d1=1;}
if (v2!=0){d2=1;}
if (d1==1){arr_d_1[v1] = arr_d_1[v1]+1;}
if (d2==1){arr_d_2[v2] = arr_d_2[v2]+1;}
}
// printf("arr_d_1=");
// for (i=0;i<10;i++){
// printf("%d",arr_d_1[i]);
// }
// printf("\n");
// printf("arr_d_2=");
// for (i=0;i<10;i++){
// printf("%d",arr_d_2[i]);
// }
// printf("\n");
for (i=0;i<10;i++){
if (arr_d_1[i]!=arr_d_2[i]){return 0;}
}
return 1;
}
int main() {
char str[21]; // 20 位数字 + 换行符 + 结尾符
int n1[21]={0};
int i;
int j=20;
int res;
//fgets(str, 22, stdin);
res = scanf("%s",str);
if (res==EOF){printf("input str wrong");}
for (i = 19; i >=0; i--) {
n1[i+1] = 0;
char c = str[i];
sscanf(&str[i], "%1d", &n1[j]); // 将字符串中的一个字符转换为整数
//printf("i=%d j=%d v=%c\n",i,j,str[i]);
if (c >= '0' && c <= '9'){j=j-1;}
}
// printf("n1=");
// for (i=0;i<21;i++){
// printf("%d",n1[i]);
// }
// printf("\n");
int n2[21];
// 根据数组计算n2的值
int j1=0,j2=0;
int m1,m2;
for (i=20;i>=0;i--){
j1=n1[i];
m1 = j1*2;
m2 = m1%10;
n2[i] = j2+m2;
j2 = m1/10;
}
// printf("n2=");
// for (i=0;i<21;i++){
// printf("%d",n2[i]);
// }
// printf("\n");
//printf("%lld %lld\n",n1,n2);
if (is_same_digits(n1, n2)) {
//printf("%lld and %lld have the same digits.\n", n1, n2);
printf("Yes\n");
int s=0;
for (i=0;i<=20;i++){
if (n2[i]!=0){
s = 1;}
if (s==1){printf("%d",n2[i]);}
}
printf("\n");
} else {
//printf("%lld and %lld don't have the same digits.\n", n1, n2);
printf("No\n");
int s=0;
for (i=0;i<=20;i++){
if (n2[i]!=0){
s = 1;}
if (s==1){printf("%d",n2[i]);}
}
printf("\n");
}
return 0;
}