2020/11/29 全国计算机能力挑战赛

今日考完,感慨良多,我还需要不断提高个人能力T T

*原题待后补。

【模仿Excel表】

我的思路是将字符串转换成数字,再相减,注意题目要求是两列中间有多少列,所以应再减1。

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

int change(string a) {
	int r = 0;
	for (int i = 0; i < a.length(); i++) {
		r += r * 26 + a[i] - 'A';
	}

	return r;
}

int main() {
	string s1, s2;
	cin >> s1 >> s2;
	int res = 0;
	int len1 = s1.length();
	int len2 = s2.length();
	int d = abs(change(s1) - change(s2)) - 1;
	cout << d << endl;

	system("PAUSE");
	return 0;
}

【学生分数排序】

记一次惨痛的教训,变量名一定不能记错!!考试时将res错写成下面的stu,导致结果测试错误,痛失60元。

for(int i = 0; i < cnt; i++) {
		cout << stu[i].xuehao << " ";
		cout << stu[i].sum << endl;
	}

修改代码如下:

#include <cstdio> 
#include <cstdlib> 
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;
#define MAX 1000

typedef struct student{
	string xuehao;
	int score[5] = {0};
	int sum = 0;
}student;

int cmp(student a, student b){
	if(a.sum != b.sum)
		return a.sum > b.sum; 
	else {
		if(a.score[2] != b.score[2])
			return a.score[2] > b.score[2];
		else if(a.score[1] != b.score[1])
			return a.score[1] > b.score[1];
		else if(a.score[0] != b.score[0])
			return a.score[0] > b.score[0];
		else 
			return a.xuehao < b.xuehao;
	}
}

int main() {
	int n;
	cin >> n;
	student stu[MAX];
	student res[MAX];
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> stu[i].xuehao;
		bool flag = true;
		for(int j = 0; j < 3; j++) {
			cin >> stu[i].score[j];
			stu[i].sum += stu[i].score[j];
			if(stu[i].score[j] < 80) {
				flag = false;
			}
		}
		if (flag == true){
			res[cnt] = stu[i];
			cnt++;
		}
	}
	
	sort(res, res + cnt, cmp);
	
	if(cnt == 0)
		cout << "NULL" << endl;
	for(int i = 0; i < cnt; i++) {
		cout << res[i].xuehao << " ";
		cout << res[i].sum << endl;
	}
	
	return 0;
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值