1058. 选择题(20)
时间限制
300 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。
输入格式:
输入在第一行给出两个正整数N(<=1000)和M(<=100),分别是学生人数和多选题的个数。随后M行,每行顺次给出一道题的满分值(不超过5的正整数)、选项个数(不少于2且不超过5的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母a开始顺次排列。各项间以1个空格分隔。最后N行,每行给出一个学生的答题情况,其每题答案格式为“(选中的选项个数 选项1 ……)”,按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。
输出格式:
按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从1开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出“Too simple”。
输入样例:
3 4
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (2 b d) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (2 b c) (4 a b c d)
输出样例:
3
6
5
2 2 3 4
这个题目坑的是,测试点输入不规范,当cin>>n>>m后,如果我一次cin.get(),4个测试点后3个就错,如果两次cin.get(),第一个测试点就错,意味着第一个测试点第一行后面可能跟了个空格,我不知道只有我碰到了这个问题还是怎么的,总之我改成用stringstream流输入就没有问题直接AC了
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
struct duoxuan {
int max;
int chooses;
int rig;
string right;
};
int main() {
int n, m;
string inp;
stringstream ss;
getline(cin, inp);
ss.str(inp);
ss >> n >> m;
vector<duoxuan> timu(m);
for (int i = 0; i < m; i++) { //input stream
inp.clear();
getline(cin, inp);
timu[i].max = inp[0] - '0';
timu[i].chooses = inp[2] - '0';
timu[i].rig = inp[4] - '0';
unsigned j = 6;
for (; j < inp.size(); j++) {
if (inp[j] == ' ')
continue;
timu[i].right.push_back(inp[j]);
}
}
vector< vector<int> > wrong(n+1, vector<int>(m, 0));
for (int i = 0; i < n; i++) {
inp.clear();
getline(cin, inp);
int count = 0, total = 0;
for (string::const_iterator it = inp.begin(); it != inp.end(); it++) {
if (*it == '(') {
string comp;
int p = *(++it) - '0';
if (p != timu[count].rig) {
while (*it != ')')
it++;
wrong[i][count] = 1;
count++;
continue;
}
it++;
for (; *it != ')'; it++) {
if (*it == ' ')
continue;
comp.push_back(*it);
}
if (comp == timu[count].right)
total += timu[count].max;
else wrong[i][count] = 1;
count++;
}
}
cout << total << endl;
}
int max = 0;
for (int j = 0; j < m; j++) {
int w = 0;
for (int i = 0; i < n; i++) {
if (wrong[i][j])
w++;
}
wrong[n][j] = w;
if (wrong[n][j] > max)
max = wrong[n][j];
}
if (max == 0)
cout << "Too simple";
else {
cout << max << ' ';
int count = 0;
for (int i = 0; i < m; i++)
if (wrong[n][i] == max)
count++;
for (int i = 0; i < m; i++) {
if (wrong[n][i] == max) {
cout << i+1;
count--;
if (count != 0)
cout << ' ';
else break;
}
}
}
return 0;
}