帮帮忙。。。。。解决了给他充50块话费。。。
以1到16随机输出5个数字的且不 重复的数组(位置不 论),若和下列每组数组中有4个或以上数字相同的数组不输出。。。。。{1,2,3,4,5}{3,4,6,7,}{4,5,8,9,10}(这列数组不是固定的,应该是我输入的)
谢谢
#include <stdio.h> #include <stdlib.h> void main() { int buffer[3][5] = {0}; int target[5] = {0}; int flag[3] = {0}; int isexit = 0; int i = 0; int j = 0; int k = 0; int p = 0; int tmp; for (; i<3; i++) { printf("请输入目标数组:\n"); for (j=0; j<5; j++) { scanf("%d",&tmp); buffer[i][j] = tmp; } } for (i=0; i<3; i++) { printf("您的数组为:\n"); for (j=0; j<5; j++) { printf("%d ",buffer[i][j]); } printf("\n==============================\n"); } while (p<5) { if((tmp=rand()%17)==0) { continue; } for (i=0; i<3; i++) { for (j=0; j<5; j++) { if (tmp==buffer[i][j]) { flag[k] += 1; } } k++; } k = 0; for (i=0; i<5; i++) { if (tmp==target[i]) { isexit = 1; break; } } if ((isexit==0)&&(flag[0]<=3)&&(flag[1]<=3)&&(flag[2]<=3)) { target[p++] = tmp; } isexit = 0; for (i=0; i<3; i++) { if (flag[i]>3) { flag[i] -=1; } } } printf("得出的数组为:\n"); for (i=0; i<5; i++) { printf("%d ",target[i]); } printf("\n"); }
#include <stdio.h> #include <stdlib.h> int result[5] = {0}; int *line = result; int flag[3] = {0}; int buffer[3][5] = {0}; void is_illegal() { int m,i,j,k; for (m=0; m<3; m++) { flag[m] = 0; } for (i=0; i<5; i++) { for (j=0; j<3; j++) { for (k=0; k<5; k++) { if (buffer[j][k]==result[i]) { flag[j]++; } } } } if (flag[0]<4&&flag[1]<4&&flag[2]<4) { for (i=0; i<5; i++) { printf("%d ",result[i]); } printf("\n"); } } void getallsolotion() { int i = 1, j = 1, k = 1, m = 1, n = 1; int row = 0; while (i<17) { for (j=1; j<17; j++) { if (j==i) { continue; } for (k=1; k<17; k++) { if ((k==i)||(k==j)) { continue; } for (n=1; n<17; n++) { if ((n==i)||(n==j)||(n==k)) { continue; } for (m=1; m<17; m++) { if ((m==i)||(m==j)||(m==k)||(m==n)) { continue; } *(line+row++) = i; *(line+row++) = j; *(line+row++) = k; *(line+row++) = n; *(line+row) = m; is_illegal(); row = 0; } } } } i++; } } void main() { int i = 0; int j = 0; int tmp; for (; i<3; i++) { printf("请输入目标数组:\n"); for (j=0; j<5; j++) { scanf("%d",&tmp); buffer[i][j] = tmp; } } for (i=0; i<3; i++) { printf("您的数组为:\n"); for (j=0; j<5; j++) { printf("%d ",buffer[i][j]); } printf("\n==============================\n"); } getallsolotion(); }