C++版浙大PAT乙级1073(20分)

https://pintia.cn/problem-sets/994805260223102976/problems/994805263624683520

 繁杂的题。先是没看清题意,后面要注意好多细节。

#include<iostream>
#include<string.h>
using namespace std;

struct{
	int score;
	int right_opt[5]={0};
	int wrong_opt[5]={0};
	int right=0;
}ques[100];

int main() {
	char ch;
	int n, m, nouse, start=0, k, flag, len, length;
	int cmp[5]={0,0,0,0,0}, options[5], max=0, p=0;
	string str;
	float score;
	cin >> n >> m;
	// 正确答案
	for(int i=0; i<m; i++){
		cin >> ques[i].score >> nouse >> len;
		for(int j=0; j<len; j++){
			cin >> ch;
			ques[i].right_opt[ch-97]=1;
			ques[i].right++;
		}
	}
	// 每个学生答案
	for(int i=0; i<n; i++){
		cin.clear();
		cin.ignore();
		k = 0;
		score = 0;
		while(cin.peek()!='\n'){
			cin >> ch;
			if(ch == '(' && start == 0){
				start = 1;
				flag = 1;
				memcpy(options, cmp, sizeof(cmp));
			}else if(ch >= '0' && ch <= '5' && start == 1){
				length = ch - '0';
			}else if(ch >= 'a' && ch <= 'e' && start == 1){
				options[ch-97] = 1;
				if(ques[k].right_opt[ch-97] == 0)
					flag = 0;
			}else if(ch == ')' && start == 1){
				start = 0;
				// 计算得分
				if(flag == 1 && ques[k].right == length){// 全对
					score += ques[k].score*1.0;
				}else if(flag == 1 && ques[k].right != length){// 半对
					score += ques[k].score*1.0/2;
				}
				// 最多错误选项
				for(int j=0; j<5; j++){
					if(ques[k].right_opt[j] != options[j]){
						ques[k].wrong_opt[j]++;
						if(ques[k].wrong_opt[j] > max){
							max = ques[k].wrong_opt[j];
						}
					}
				}
				k ++;
			}
		}
		printf("%.1f\n", score);
	}
	if(max==0){
		cout << "Too simple" << endl;
	}
	for(int i=0; i<m && max>0; i++){
		for(int j=0; j<5; j++){
			if(ques[i].wrong_opt[j]==max){
				cout << max << " " << i+1 << "-" << char(j+97) << endl;
			}
		}
	}
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值