CDUT_ITA 第一周 Level3

戳这里看Level3

总结:难度不高,Level3侧重于对STL的考察和对码力的考察,推荐用Level3学习一些基本STL(比如E可以用set),然后练练码力。

A

建立两个人名到得分的映射就好,第一个用来统计最大值,第二个用来统计出现的先后。

AC code
#include<bits/stdc++.h>
using namespace std;
int n, ans=-0x3f;
string ans_name;
map<string, int>a, b;
int c[1005]; string d[1005];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> d[i] >> c[i];
		a[d[i]] += c[i];
	}
	for (int i = 1; i <= n; i++) {
		if (a[d[i]] > ans)ans = a[d[i]];
	}
	for (int i = 1; i <= n; i++) {
		b[d[i]] += c[i];
		if (b[d[i]] >= ans && a[d[i]] >= ans) {
			cout << d[i];
			return 0;
		}
	}
	return 0;
}

B

贪心考虑:首先我们每一天都要学最少时间,最多学最多时间。

这不是废话嘛

设sum为总时间,于是我们就知道了NO的条件:

\(\sum_{i=1}^{n}time_{min}>sum\) or \(\sum_{i=1}^{n}time_{max}<sum\)

在此基础上,我们考虑:能贪就贪。
首先用总时间减去每一天学习的最少时间,然后处理出每一天可以学习的时间time,只要\(time_{i} \leqslant sum_{now}\)就可以学,一直到学不了了处理最后一天就可以。

AC code
#include<bits/stdc++.h>
using namespace std;
int n, sum, mina, maxa;
int a[35], b[35], c[35];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> sum;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		c[i] = b[i] - a[i];
		mina += a[i]; maxa += b[i];
	}
	if (mina > sum || maxa < sum) {
		cout << "NO";
		return 0;
	}
	cout << "YES" << endl;
	if (mina == sum) {
		for (int i = 1; i <= n; i++) {
			cout << a[i] << " ";
		}
	}
	else {
		int now = 1;
		for (now; now <= n; now++) {
			if (mina + c[now] <= sum) {
				mina += c[now];
				a[now] = b[now];
			}
			else break;
		}
		a[now] = a[now] + sum - mina;
		for (int i = 1; i <= n; i++) {
			cout << a[i] << " ";
		}
	}
	return 0;
}

C

依旧是映射问题,对于每个用户名都映射到它的出现次数,如果是0次就ok,出现过后面就跟着输出一个出现次数-1就好。

AC Code
#include<bits/stdc++.h>
using namespace std;
int n; string s;
map<string, int>a;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s;
		a[s]++;
		if (a[s] == 1) {
			cout << "OK" << endl;
		}
		else {
			cout << s << a[s]-1 << endl;
		}
	}
	return 0;
}

D

大模拟题,不解释。
朋友,记住字符串从0开始处理,不然你会像我一样爆0

AC Code
#include<bits/stdc++.h>
using namespace std;
char s[1005][1005];
int sum, maxx = -1;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	while (gets(s[sum++]));
	for (int i = 0; i < sum; i++) {
		int len = strlen(s[i]);
		maxx = max(maxx, len);
	}
	for (int i = 0; i < maxx + 2; i++) {
		cout << "*";
	}
	cout << endl;
	bool flag = 1;
	for (int i = 0; i < sum - 1; i++) {
		int len = strlen(s[i]);
		int now1 = (maxx - len) / 2; int now2 = maxx - now1 - len;
		if (now1 != now2) {
			if (!flag) {
				now1++, now2--;
			}
			flag = !flag;
		}
		cout << "*";
		for (int i = 0; i < now1; i++) {
			cout << " ";
		}
		cout << s[i];
		for (int i = 0; i < now2; i++) {
			cout << " ";
		}
		cout << "*";
		cout << endl;
	}
	for (int i = 0; i < maxx + 2; i++) {
		cout << "*";
	}
	return 0;
}

E

关键字符:+ - :

只要找到这些字符就知道该怎么处理了。记录一下当前人数,算一下字符串长度,ok。

AC Code
#include<bits/stdc++.h>
using namespace std;
char s[205];
int now, ans;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	while (gets(s)) {
		if (s[0] == '+')now++;
		else if (s[0] == '-')now--;
		else {
			int i = 0;
			while (s[i] != ':')i++;
			int len = strlen(s);
			ans += (len - i - 1) * now;
		}
	}
	cout << ans;
	return 0;
}
posted @ 2022-11-28 13:59  Linsa_qwq  阅读(131)  评论(0)    收藏  举报