题目链接
坑点
测试点1的输入不正确,第一个测试点在输入N 与M时,应该是末尾多了一个空格
所以当采用cin输入完N与M后,使用两次getchar()则测试点1是正确的,而另外
的测试点是错误的,当采用一个getchar()时,则反之。
所以改变N 与M的获取方式。
实现
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
struct node {
int score;
int chooseNum;
int correctNum;
string answer;
};
int main()
{
int N, M,i,j;
string inp;
stringstream ss;
getline(cin, inp);
ss.str(inp);
ss >> N >> M;
vector<node> question(M);
vector<int> countWrong(M);
for (i = 0; i < M; i++) countWrong[i] = 0;
vector<int> getScore(N);
for (i = 0; i < N; i++) getScore[i] = 0;
string str;
for (i = 0; i < M; i++)
{
getline(cin, str);
str.erase(remove(str.begin(), str.end(), ' '), str.end());
question[i].score = str[0]-'0';
question[i].chooseNum = str[1] - '0';
question[i].correctNum = str[2] - '0';
question[i].answer = str.substr(3, str[2] - '0');
}
int questionIndex = 0,choosenum;
string temp;
for (i = 0; i < N; i++)
{
questionIndex = 0;
getline(cin, str);
str.erase(remove(str.begin(), str.end(), ' '), str.end());
str.erase(remove(str.begin(), str.end(), '('), str.end());
str.erase(remove(str.begin(), str.end(), ')'), str.end());
for (j = 0; j < str.size()&& questionIndex<M;)
{
if (str[j] >= '0' && str[j] <= '9')
{
choosenum = str[j] - '0';
temp = str.substr(j + 1, choosenum);
if (choosenum == question[questionIndex].correctNum && temp == question[questionIndex].answer)
getScore[i] += question[questionIndex].score;
else
countWrong[questionIndex] += 1;
j = j + choosenum + 1;
questionIndex++;
}
}
}
for (i = 0; i < N; i++)
cout << getScore[i] << endl;
int maxWrong = *max_element(countWrong.begin(), countWrong.end());
if (!maxWrong)
cout << "Too simple";
else
{
cout << maxWrong;
for (i = 0; i < M; i++)
{
if (countWrong[i] == maxWrong)
cout << " " << i + 1;
}
}
return 0;
}