PAT乙级 C++ 选择题 (20分) the operator +- between string and char

将每道题目按照序号打表,然后将学生的选择和表对比。

#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

struct problem{
	int score;
	int totalnum;
	int correnum;
	int beicuocishu;
}p;
struct student{
	int score;
}s;
map<int, string> numtostr;

int main(){
	int N, M, k,maxncishu=0;
	char a;
	int mark;
	scanf("%d %d",&N,&M);
	vector<problem> vec;
	vector <student> stu;
	string str;
	string str2;
	string str3;
	for(int i=0; i<N;i++){
		s.score=0;
		stu.push_back(s);
	}
	for(int i=0; i<M;i++){
		str.clear();
		scanf("%d %d %d",&p.score,&p.totalnum,&p.correnum);
		k=0;
		str2=p.correnum+'0';		//将数字保存为string格式
		str=str+str2;				//operator+- string with string
		while(scanf("%c",&a),a!='\n'){
			if(a!=' '){
				str=str+a;			//operator+- string with char or char[];	
			}
		}p.beicuocishu=0;
		vec.push_back(p);
		numtostr[i]=str;
	//	cout << str <<"\n";
	}
	str2.clear();
	for(int i=0; i<N; i++){
//		str.clear();
		getline(cin,str);		//string里的字符会被清空,不需要提前clear
		int k=0;
		for(int j=0; j< M; j++){	
			for(k++; str[k]!=')';k++){
				if(str[k]!='(' && str[k]!=' '){
					str2=str2+str[k];		//operator+- str with str[]
				}
			}
		//	cout << str2 <<"\n";
			if(str2 != numtostr[j])	{
				vec[j].beicuocishu++;
				maxncishu=vec[j].beicuocishu>maxncishu?vec[j].beicuocishu:maxncishu;
			}else{
				stu[i].score+=vec[j].score;
			}			
			str2.clear();
		}
	}
	for(int i=0; i<N; i++){
		printf("%d\n",stu[i].score);
	}
	if(maxncishu==0) printf("Too simple");
	else{
		printf("%d",maxncishu);
		for(int j=0;j<M; j++){
			if(vec[j].beicuocishu==maxncishu) printf(" %d",j+1);
		}
	}
	return 0;
}

转载须注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值