1041 考试座位号
分数 15
作者 CHEN, Yue
单位 浙江大学
每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。
输入格式:
输入第一行给出一个正整数 N(≤1000),随后 N 行,每行给出一个考生的信息:
准考证号 试机座位号 考试座位号。其中准考证号由 16 位数字组成,座位从 1 到 N 编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。考生信息之后,给出一个正整数 M(≤N),随后一行中给出 M 个待查询的试机座位号码,以空格分隔。
输出格式:
对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用 1 个空格分隔。
输入样例:
4 3310120150912233 2 4 3310120150912119 4 1 3310120150912126 1 3 3310120150912002 3 2 2 3 4输出样例:
3310120150912002 2 3310120150912119 1
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
struct r {
string sno;
int seat;
};
int main() {
int n;
cin >> n;
map<int, r> arr;
for (int i = 0; i < n; i++) {
string s;
int a, b;
cin >> s >> a >> b;
arr[a].sno = s;
arr[a].seat = b;
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int t;
cin >> t;
cout << arr[t].sno << " " << arr[t].seat << endl;
}
return 0;
}
1042 字符统计
分数 20
作者 CHEN, Yue
单位 浙江大学
请编写程序,找出一段给定文字中出现最频繁的那个英文字母。
输入格式:
输入在一行中给出一个长度不超过 1000 的字符串。字符串由 ASCII 码表中任意可见字符及空格组成,至少包含 1 个英文字母,以回车结束(回车不算在内)。
输出格式:
在一行中输出出现频率最高的那个英文字母及其出现次数,其间以空格分隔。如果有并列,则输出按字母序最小的那个字母。统计时不区分大小写,输出小写字母。
输入样例:
This is a simple TEST. There ARE numbers and other symbols 1&2&3...........输出样例:
e 7
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
string s;
getline(cin, s);
vector<int> arr(26);
for (char c : s) {
// 不可直接写c>='A'&&c<='z'
if (c >= 'A' && c <= 'Z') {
arr[c - 'A']++;
}
else if (c >= 'a' && c <= 'z') {
arr[c - 'a']++;
}
}
int max = 0;
int ind = 0;
for (int i = 0; i < 26; i++) {
if (arr[i] > max) {
max = arr[i];
ind = i;
}
}
char r = ind + 'a';
cout << r<< " " << max << endl;
return 0;
}
1043 输出PATest
分数 20
作者 CHEN, Yue
单位 浙江大学
给定一个长度不超过 104 的、仅由英文字母构成的字符串。请将字符重新调整顺序,按
PATestPATest....这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按 PATest 的顺序打印,直到所有字符都被输出。输入格式:
输入在一行中给出一个长度不超过 104 的、仅由英文字母构成的非空字符串。
输出格式:
在一行中按题目要求输出排序后的字符串。题目保证输出非空。
输入样例:
redlesPayBestPATTopTeePHPereatitAPPT输出样例:
PATestPATestPTetPTePePee
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
string s;
getline(cin, s);
vector<int> arr(6,0);
for (char c : s) {
if (c == 'P') {
arr[0]++;
}
else if (c == 'A') {
arr[1]++;
}
else if (c == 'T') {
arr[2]++;
}
else if (c == 'e') {
arr[3]++;
}
else if (c == 's') {
arr[4]++;
}
else if (c == 't') {
arr[5]++;
}
}
int t = *max_element(arr.begin(), arr.end());
while (t--) {
if (arr[0] > 0) {
cout << "P";
arr[0]--;
}
if (arr[1] > 0) {
cout << "A";
arr[1]--;
}
if (arr[2] > 0) {
cout << "T";
arr[2]--;
}
if (arr[3] > 0) {
cout << "e";
arr[3]--;
}
if (arr[4] > 0) {
cout << "s";
arr[4]--;
}
if (arr[5] > 0) {
cout << "t";
arr[5]--;
}
}
return 0;
}
207

被折叠的 条评论
为什么被折叠?



