特别注意一点,最后一个测试点给出的学生回答中会有非法字符!!!
所以只有用switch语句(仅限我的方法)。
代码实现:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct
{
int score, choice_number, right_number, wrong_choice[5];
char answer[15];
}question;
int main()
{
int N, M;
question *array;
scanf("%d %d", &N, &M);
array = (question*)malloc(sizeof(question)*M);
for (int i = 0; i < M; i++)
{
scanf("%d %d %d", &array[i].score, &array[i].choice_number, &array[i].right_number);
getchar(); gets(array[i].answer);
for (int j = 0; j < 5; j++)
array[i].wrong_choice[j] = 0;
}
for (int i = 0; i < N; i++)
{
double score = 0;
for (int j = 0; j < M; j++)
{
int num, count = 0;
char answer[15], ch;
scanf("(%d", &num); getchar();
if (i != 0 || j != 0)
getchar(), getchar(), getchar();
while ((ch = getchar()) != ')')
answer[count++] = ch;
answer[count] = 0;
if (strcmp(array[j].answer, answer) == 0)
score += array[j].score;
else
{
int flag1, flag2 = 0;
for (int k = 0; answer[k] != 0; k++)
{
flag1 = 0;
for (int p = 0; array[j].answer[p] != 0; p++)
if (array[j].answer[p] == answer[k])
{
flag1 = 1; break;
}
if (flag1 == 0)
{
flag2 = 1;
switch (answer[k])
{
case 'a':array[j].wrong_choice[0]++; break;
case 'b':array[j].wrong_choice[1]++; break;
case 'c':array[j].wrong_choice[2]++; break;
case 'd':array[j].wrong_choice[3]++; break;
case 'e':array[j].wrong_choice[4]++; break;
}
}
}
for (int k = 0; array[j].answer[k] != 0; k++)
{
flag1 = 0;
for (int p = 0; answer[p] != 0; p++)
if (array[j].answer[k] == answer[p])
flag1 = 1;
if (flag1 == 0)
switch (array[j].answer[k])
{
case 'a':array[j].wrong_choice[0]++; break;
case 'b':array[j].wrong_choice[1]++; break;
case 'c':array[j].wrong_choice[2]++; break;
case 'd':array[j].wrong_choice[3]++; break;
case 'e':array[j].wrong_choice[4]++; break;
}
}
if (flag2 == 0)
score += (double)array[j].score / 2;
}
}
printf("%.1f\n", score);
}
int max = array[0].wrong_choice[0];
for (int i = 0; i < M; i++)
for (int j = 0; j < 5; j++)
if (max < array[i].wrong_choice[j])
max = array[i].wrong_choice[j];
if (max == 0)
printf("Too simple");
else
for(int i=0;i<M;i++)
for(int j=0;j<5;j++)
if (array[i].wrong_choice[j] == max)
printf("%d %d-%c\n", max, i + 1, 'a' + j);
return 0;
}