PAT-2022年冬季考试-乙级满分答案

1
#include <bits/stdc++.h>

using namespace std;

const string aim = "(zhangsheng)";

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	cin.ignore(1, '\n');
	
	int cnt = 0;
	for (string s; getline(cin, s, '\n');) {
		const int m = s.size();
		for (int i = 0; i < m; ++i) {
			if (s[i] == '#') {
				goto out;
			}
			if (s.substr(i, aim.size()) == aim) {
				++cnt;
			}
		}
	}
	out:;
	cout << cnt << ' ' << (cnt >= n ? "True" : "False");
	
	return 0;
}
2
#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;
	
	int ansm = 0, ansn = 0;
	for (int m = a; m <= b; ++m) {
		for (int n = a; n <= b; ++n) {
			if ((n * n - m * n - m * m) * (n * n - m * n - m * m) == 1 && \
				ansm * ansm + ansn * ansn < m * m + n * n) {
				ansm = m, ansn = n;
			}
		}
	}
	int res = ansm * ansm + ansn * ansn;
	printf("max( %d^2 + %d^2 ) = %d\n", ansm, ansn, res);
	
	return 0;
}
3
#include <bits/stdc++.h>

using namespace std;

int main() {
	// cin.tie(nullptr)->sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	set<int> has;
	for (int i = 0; i < n; ++i) {
		int id, op;
		cin >> id >> op;
		if (!op) has.erase(id);
		else has.insert(id);
	}
	
	vector<int> res;
	for (int id : has) {
		res.push_back(id);
	}
	const int m = res.size();
	for (int i = 0; i < m; ++i) {
		cout << right << setw(4) << setfill('0') \
			<< res[i] << " \n"[i == m - 1];
	}
	
	if (m == 1) {
		cout << "Da Ben Zhong is found!\n";
	} else {
		printf("There are %d suspects.\n", m);
	}
	
	return 0;
}
4
#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;
	
	string sa = to_string(a), sb = to_string(b);
	for (int i = 0; i < (int)sa.size(); ++i) {
		size_t pb = sb.find(sa[i]);
		if (pb == string::npos) continue;
		sa[i] = ' ', sb[pb] = ' ';
	}
	string ta, tb;
	for (char c : sa) {
		if (c == ' ') continue;
		ta += c;
	}
	for (char c : sb) {
		if (c == ' ') continue;
		tb += c;
	}
	int c = ta.empty() ? 0 : stoi(ta);
	int d = tb.empty() ? 0 : stoi(tb);
	
	int lv = a * d, rv = b * c;
	printf("%d/%d %s %d/%d\n", a, b, (lv != rv || (c == 0 && d == 0) ? "!=" : "="), c, d);
	
	return 0;
}
5
#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	queue<int> Q;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		
		Q.push(x);
	}
	
	int cur = 0;
	vector<int> cnt(n + 1);
	for (int i = 1; i <= n; ++i) {
		while (true) {
			++cur;
			int x = Q.front(); Q.pop();
			if (x != i) Q.push(x);
			else {
				cnt[x] = cur;
				break;
			}
		}
	}
	int time = *max_element(cnt.begin() + 1, cnt.end());
	int sum = accumulate(cnt.begin() + 1, cnt.end(), 0);
	printf("%d %.1lf\n", time, 1.0 * sum / n);
	
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值