回复 4楼 TonyDeng
多谢大神的回复 感激不尽 但是你这个程序是适用于我给出的那五个数字呀 如果这个五个数字是1-9之间random的呢
我写的那两组就是举个例子~
EE苦逼学渣女屌一枚
//A program which does the scoring for game CSEzee //CSEzee is played by rolling five 9-sided(1-9) dice. //The program will give the score of the input by following CSEzee rules. // //20/04/2013 #include <stdio.h> #define N_DICE 5 #define NUMBER 9 int main(void) { int x[N_DICE],number_table[9] = {0}; int n[NUMBER]={1,2,3,4,5,6,7,8,9}; int i,j, score = 0, score2 = 0; //storage of five input i = 0; for (i = 0;i < N_DICE; i++) { scanf("%d", &x[i]); } for (i = 0;i < N_DICE; i++) { //5 interger from 1 to five must be supplied if (1 <= x[i]&&x[i] <=9) { //sum of any throw for (i = 0;i < N_DICE;i++) { score = score + x[i]; } //the number_table is used to memorize the number //of times of the appearance of interger 1..9 for (i = 0;i < N_DICE;i++) { for (j = 0;j < NUMBER;j++) { if (x[i]==n[j]) number_table[j] = number_table[j] + 1; } } for (j = 0;j < NUMBER;j++) { if (number_table[j] == 2) { score2 = 14 + 2 * n[j]; }else if (number_table[j] == 3) { score2 = 15 + 3 * n[j]; }else if (number_table[j] == 4) { score2 = 16 + 4 * n[j]; }else if (number_table[j] == 5) { score2 = 17 + 5 * n[j]; } } //the hihgest score will be printed for (j = 0;j < NUMBER;j++) { if (score > score2) { printf("CSEzee score is %d: sum.\n",score); }else if (number_table[j] == 2) { printf("CSEzee score is %d: pair of %d's\n",score2,n[j]); }else if (number_table[j] == 3) { printf("CSEzee score is %d: three %d's\n",score2,n[j]); }else if (number_table[j] == 4) { printf("CSEzee score is %d: four %d's\n",score2,n[j]); }else if (number_table[j] == 5) { printf("CSEzee score is %d: five %d's\n",score2,n[j]); } } }else{ printf("Invalid input: 5 integers 1..9 must be supplied.\n"); } } return 0; }