problemscpp
A collection of my answers to algorithm problems in c++.
| 函数
pat::b::b1058 命名空间参考

1058 选择题 更多...

struct  Problem
 

函数

int main (istream &cin, ostream &cout)
 
 TEST (b1058, case1)
 

详细描述

1058 选择题

函数说明

◆ main()

int pat::b::b1058::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp2012 行定义.

2012 {
2013 int n;
2014 int m;
2015 cin >> n >> m;
2016 int max_error = 0;
2017 vector<Problem> problems(m);
2018 for(int i = 0; i < m; i++) {
2019 Problem p;
2020 cin >> p.score;
2021 cin >> p.num;
2022 cin >> p.correct_num;
2023 p.correct_choices = unordered_set<char>();
2024 for(int j = 0; j < p.correct_num; j++) {
2025 char choice;
2026 cin >> choice;
2027 p.correct_choices.insert(choice);
2028 }
2029 p.error_count = 0;
2030 problems[i] = p;
2031 }
2032 for(int i = 0; i < n; i++) {
2033 int score = 0;
2034 for(int j = 0; j < m; j++) {
2035 char ch;
2036 cin >> ch;
2037 int num;
2038 cin >> num;
2039 unordered_set<char> answer;
2040 for(int k = 0; k < num; k++) {
2041 char choice;
2042 cin >> choice;
2043 answer.insert(choice);
2044 }
2045 if(answer == problems[j].correct_choices) {
2046 score += problems[j].score;
2047 } else {
2048 problems[j].error_count++;
2049 max_error = max(max_error, problems[j].error_count);
2050 }
2051 cin >> ch;
2052 }
2053 cout << score << endl;
2054 }
2055 if(max_error == 0) {
2056 cout << "Too simple";
2057 } else {
2058 vector<int> max_problems;
2059 cout << max_error << ' ';
2060 for(int i = 0; i < m; i++) {
2061 if(problems[i].error_count == max_error) {
2062 max_problems.push_back(i + 1);
2063 }
2064 }
2065 for(int i = 0; i < max_problems.size(); i++) {
2066 cout << max_problems[i];
2067 if(i != max_problems.size() - 1) {
2068 cout << ' ';
2069 }
2070 }
2071 }
2072 return 0;
2073 }
unordered_set< char > correct_choices
Definition: pat.h:359

引用了 pat::b::b1058::Problem::correct_choices, pat::b::b1058::Problem::correct_num, pat::b::b1058::Problem::error_count, pat::b::b1058::Problem::num , 以及 pat::b::b1058::Problem::score.

被这些函数引用 TEST().

◆ TEST()

pat::b::b1058::TEST ( b1058  ,
case1   
)

在文件 pat_test.cpp881 行定义.

881 {
882 istringstream in("3 4 \n"
883 "3 4 2 a c\n"
884 "2 5 1 b\n"
885 "5 3 2 b c\n"
886 "1 5 4 a b d e\n"
887 "(2 a c) (2 b d) (2 a c) (3 a b e)\n"
888 "(2 a c) (1 b) (2 a b) (4 a b d e)\n"
889 "(2 b d) (1 e) (2 b c) (4 a b c d)");
890 auto out = ostringstream();
891 main(in, out);
892 const auto ans = out.str();
893 ASSERT_EQ("3\n"
894 "6\n"
895 "5\n"
896 "2 2 3 4",
897 out.str());
898 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().