PAT (Basic Level) 1058 multiple-choice questions (analog)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_45458915/article/details/102738000

Topic links: Click here

Subject to the effect: given the rules, modify the simulation of multiple-choice questions, each question during the record about how much personal fault, note that multiple choice questions in the title, only to get all the answers entirely correct scores, scores were other cases 0 is calculated

Topic analysis: is a more fun simulation questions, the difficulty is the simple partial right, recently was originally in the brush pat Serie B title, and found that this simple simulation fell in love, I feel really good fun doing this the main topic I feel very good input and output deal with it, I am the first record with a map about the correct answer to each topic and play with the string class with stringstream easily solve student answers the following input and processing, to total reported feeling write the code is still pretty good, hang look at it:

By the way, wanted the answer to each question and then integrated into a string class thrown directly in the map, then I fear the answer will be chaos given the title sequence, a bit on the row order, and afterwards discovered that in fact does not require sorting, illustrate this topic or listen to conscience, not the kind of mess of data deliberately deceptive

Code:

#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#include<unordered_map>
using namespace std;
 
typedef long long LL;
 
const int inf=0x3f3f3f3f;
 
const int N=110;

unordered_map<string,int>mp[N];//正确答案 格式:mp[题号][答案]=分数

int cnt[N]={0};//错题 格式:cnt[题号]=个数

int ans[N*10]={0};//分数 格式:ans[学生序号]=分数
 
int main()
{
//  freopen("input.txt","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
   	for(int i=1;i<=m;i++)
   	{
   		int score;
   		int num;
   		scanf("%d%*d%d",&score,&num);
   		char ch[5];
   		string s;
   		for(int j=0;j<num;j++)
   		{
   			scanf("%s",ch);
   			s+=ch[0];
		}
		mp[i][s]=score;
	}
	getchar();//注意!!!在cin或scanf与getline或gets连用时,已经记住要用getchar吃掉回车
   	for(int i=1;i<=n;i++)
   	{
   		string s;
   		getline(cin,s);//直接读一行,即当前学生的所有答案
   		for(int i=0;i<s.size();i++)//去掉所有的括号
   			if(s[i]=='('||s[i]==')')
   				s.erase(s.begin()+i);
   		stringstream ss(s);
   		int num;
   		char ch[5];
   		int pos=1;//题号 
   		while(ss>>num)
   		{
   			string res;
   			while(num--)
   			{
   				ss>>ch;
   				res+=ch[0];
			}
			if(mp[pos][res])
				ans[i]+=mp[pos][res];
			else
				cnt[pos]++;
			pos++;
		}
	}
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
	int mmax=0;
	for(int i=1;i<=m;i++)
   		mmax=max(mmax,cnt[i]);
   	if(mmax==0)
   		cout<<"Too simple"<<endl;
   	else
   	{
   		vector<int>ans;
   		for(int i=1;i<=m;i++)
   			if(mmax==cnt[i])
   				ans.push_back(i);
   		printf("%d",mmax);
   		for(int i=0;i<ans.size();i++)
   			printf(" %d",ans[i]);
   		printf("\n");
	}
   	
   	
   	
   	
   	
   	
     
     
     
     
     
     
     
    return 0;
}

 

Guess you like

Origin blog.csdn.net/qq_45458915/article/details/102738000