2026/4/13 数据结构课后练习G题
注意到:0出现6次,1出现2次,2出现1次,6出现1次,否则均不符合。
//author:kzssCCC
#include <stdio.h>
int a[15],cnt[100005],res[15];
int main(){
for (int i=0;i<10;i++){
scanf("%d",a+i);
cnt[a[i]]++;
}
if (cnt[0]==0 || cnt[1]==0 || cnt[2]==0 || cnt[6]==0){
printf("No answer!\n");
return 0;
}
for (int i=0;i<10;i++){
if (a[i]==0){
res[i] = 6;
}
else if (a[i]==1){
res[i] = 2;
}
else if (a[i]==2){
res[i] = 1;
}
else if (a[i]==6){
res[i] = 1;
}
printf("%d",res[i]);
if (i==9){
putchar('\n');
}
else{
putchar(' ');
}
}
return 0;
}

浙公网安备 33010602011771号