PAT乙级1058 选择题
#include <bits/stdc++.h>
using namespace std;
class Options{
public:
int score;
int n;
int right;
vector<char> option;
public:
Options(int score, int n, int right):score(score), n(n), right(right){}
void push(char &s){
option.push_back(s);
}
void show(){
cout<<score<<n<<right<<endl;
for(int i = 0; i < right; i++){
cout<<option[i]<<endl;
}
}
bool compare(char a, int i){
if(a == option[i])
return true;
return false;
}
};
class errn{
public:
int tm;
int time;
public:
errn(int tm, int time):tm(tm), time(time){}
};
bool cmp_time(const errn& a, const errn &b){
return a.time > b.time;
}
int main()
{
vector<Options> choose;
int sc, no, rt;
int n, m;
cin>>n>>m;
if(n == 0 || m == 0){
cout<<"Too simple"<<endl;
return 0;
}
vector<errn> brr;
for(int i = 0; i < m; i++){
cin>>sc>>no>>rt;
errn item(i, 0);
brr.push_back(item);
Options in(sc, no, rt);
for(int j = 0; j < rt; j++){
char ss;
cin>>ss;
in.push(ss);
}
choose.push_back(in);
}
char kh;
vector<int> arr;
for(int i = 0; i < n; i++){
arr.push_back(0);
for(int j = 0; j < m; j++){
sc = 0;
cin>>kh>>rt;
for(int k = 0; k < rt; k++){
cin>>kh;
if(k < choose[j].right && choose[j].compare(kh, k))
sc+=1;
}
if(sc == rt) arr[i]+=choose[j].score;
else
brr[j].time++;
cin>>kh;
}
cout<<arr[i]<<endl;
}
sort(brr.begin(),brr.end(),cmp_time);
if(brr[0].time == 0){
cout<<"Too simple"<<endl;
return 0;
}
cout<<brr[0].time;
for(int i = 0; i < m; i++){
if(brr[i].time == brr[0].time)
cout<<" "<<brr[i].tm+1;
}
return 0;
}
运行结果及报错内容
测试点3始终通不过
我的解答思路和尝试过的方法
一开始是 0 0 的时候会有段错误,后来添加 0 0 的时候直接输出任然通不过测试点3