PAT Basic 1073. 多选题常见计分法

0
0
0
1. 云栖社区>
2. 博客>
3. 正文

## PAT Basic 1073. 多选题常见计分法

lovedan 2017-11-09 12:26:00 浏览593

## 题目内容

1. 多选题常见计分法(20)

400 ms

65536 kB

8000 B

Standard

CHEN, Yue

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) (3 b d e) (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) (1 c) (4 a b c d)

3.5
6.0
2.5
2 2-e
2 3-a
2 3-b

2 2
3 4 2 a c
2 5 1 b
(2 a c) (1 b)
(2 a c) (1 b)

5.0
5.0
Too simple

## AC代码

``````#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <iomanip>
#include <sstream>
#include <unordered_map>

using namespace std;

struct Timu {
int score;
int ans[5];
int wrong_num[5];
int num_of_choice;
int num_of_ans;
Timu(const string& s) {
memset(ans, 0, sizeof(ans));
memset(wrong_num, 0, sizeof(wrong_num));
istringstream sin(s);
sin >> score >> num_of_choice >> num_of_ans;
char op;
for (int i = 0; i < num_of_ans; i++) {
sin >> op;
ans[op - 'a'] = 1;
}
}
};

struct Stu {
vector<vector<int> > ans;
double score;
Stu(const string& s) {
for (int i = 0; i < s.length(); i++) {
if (s[i] == '(' || s[i] == ')' || s[i] == ' ') {
continue;
}
else if (isdigit(s[i])) {
int num_of_choice = s[i] - '0';
vector<char> cc;
i += 2;
vector<int> t_ans(5, 0);
for (int j = 0; j < num_of_choice; j++, i += 2) {
t_ans[s[i] - 'a'] = 1;
}
ans.push_back(t_ans);
}
}
}
};

void do_calc(vector<Timu>& vtimu, vector<Stu>& vstu) {
for (int i = 0; i < vstu.size(); i++) {
vstu[i].score = 0;
for (int j = 0; j < vtimu.size(); j++) {
int right_cnt = 0;
bool wuxuan = false;

// 标记误选和漏选
for (int k = 0; k < vtimu[j].num_of_choice; k++) {
if (vtimu[j].ans[k]==vstu[i].ans[j][k]) {
right_cnt++;
}
else {
vtimu[j].wrong_num[k]++;
if (vtimu[j].ans[k] == 0) {
wuxuan = true;
}
}
}

double t_score = 0;
if (right_cnt == vtimu[j].num_of_choice) {
t_score = vtimu[j].score;
}
else if (!wuxuan) { //部分正确，有漏选
t_score = 0.5 * vtimu[j].score;
}
vstu[i].score += t_score;
//cout << "student[" << i << "] has: right_cnt=" << right_cnt << ", wrong_cnt=" << wrong_cnt << ", get score=" << t_score << endl;
}
}
}

string int2str(int a) {
stringstream ss;
string res;
ss << a;
ss >> res;
return res;
}

vector<string> do_stat(const vector<Timu>& vtimu) {
int max_val = 0;
for (int i = 0; i < vtimu.size(); i++) {
for (int j = 0; j < vtimu[i].num_of_choice; j++) {
if (vtimu[i].wrong_num[j] > max_val) {
max_val = vtimu[i].wrong_num[j];
}
}
}
vector<string> res;
string rr = "";
if (max_val == 0) {
rr = "Too simple";
res.push_back(rr);
return res;
}
else {
for (int i = 0; i < vtimu.size(); i++) {
//cout << ">> vtimu[" << i << "].num_of_wrong_select are: ";
for (int j = 0; j < vtimu[i].num_of_choice; j++) {
//cout << vtimu[i].num_of_wrong_select[j] << " ";
if (vtimu[i].wrong_num[j] == max_val) {
rr = int2str(vtimu[i].wrong_num[j]) + " " + int2str(i + 1) + "-" + char(j + 'a');
res.push_back(rr);
}
}
//cout << endl;
}
return res;
}
}

int main() {
string line;
int n, m;
// 这里读取n和m，我用cin+一个getchar()，能过3，4，5组测试用例
// 用cin+两个getchar()，能过1,2组测试用例
getline(cin, line);
istringstream sin(line);
sin >> n >> m;

vector<Timu> vtimu;
for (int i = 0; i < m; i++) {
getline(cin, line);
vtimu.push_back(Timu(line));
//cout << "timu: " << line << endl;
}
vector<Stu> vstu;
for (int i = 0; i < n; i++) {
getline(cin, line);
vstu.push_back(Stu(line));
//cout << "student: " << line << endl;
}
do_calc(vtimu, vstu);
for (int i = 0; i < vstu.size(); i++) {
printf("%.1lf\n", vstu[i].score);
}
vector<string> res = do_stat(vtimu);
for (int i = 0; i < res.size(); i++) {
cout << res[i] << endl;
}

return 0;
}``````

lovedan
+ 关注

corcosa 12351人浏览