有如下一组数字,其中每个数字都在 1 ~ 63 之间,
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63
2 3 6 7 10 11 14 15 18 19 22 23 26 27 30 31 34 35 38 39 42 43 46 47 50 51 54 55 58 59 62 63
4 5 6 7 12 13 14 15 20 21 22 23 28 29 30 31 36 37 38 39 44 45 46 47 52 53 54 55 60 61 62 63
8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31 40 41 42 43 44 45 46 47 56 57 58 59 60 61 62 63
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
现在需要编写一个程序,当从键盘输入某数字在且仅在哪几行出现了,该程序可以“猜”出这个数字是几。
输入 | 输出 |
1 2 0↵ | 3 |
2 1 0↵ | 3 |
2 4 0↵ | 10 |
# include<stdio.h>
# include<conio.h>
int main(){
int arr[6][32] = {{1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63},
{2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31,34,35,38,39,42,43,46,47,50,51,54,55,58,59,62,63},
{4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31,36,37,38,39,44,45,46,47,52,53,54,55,60,61,62,63},
{8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31,40,41,42,43,44,45,46,47,56,57,58,59,60,61,62,63},
{16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63},
{32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63}};
int count[64]={0};\\计算所有数出现次数
int find[64]={0};\\标记所指定行的所有数出现次数
for (int i=1;i<=6;i++){
for(int j=0;j<=31;j++){
int digit1=arr[i-1][j];
count[digit1]++;
}
}
char c;
int digit3=0;\\标记有几行
while((c=getchar())!=48){
char a=c-48;\\通过asc2表将输入的c换为整型数大小相同的asc2码即a
if (a>=1&&a<=6){
digit3++;
for (int j=0;j<=31;j++){
int digit2=arr[a-1][j];
find[digit2]++;
}
}
else {continue;}
}
for(int i=1;i<=63;i++){
if(count[i]==find[i]&&count[i]!=0&&count[i]==digit3){
printf("%d\n",i);
}
}
return 0;
}