PAT甲级1035,1036解题报告

1035 Password (20 分)

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1(one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @0 (zero) by %l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N (≤1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.

Output Specification:

For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line There are N accounts and no account is modified where Nis the total number of accounts. However, if N is one, you must print There is 1 account and no account is modified instead.

Sample Input 1:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

Sample Output 1:

2
Team000002 RLsp%dfa
Team000001 R@spodfa

Sample Input 2:

1
team110 abcdefg332

Sample Output 2:

There is 1 account and no account is modified

Sample Input 3:

2
team110 abcdefg222
team220 abcdefg333

Sample Output 3:

There are 2 accounts and no account is modified

题目大意:给一堆用户名和密码,把密码里的l,1,O,0依次换成相应字符,然后考虑没有修改的情况输出一下。

解题思路:水题,因为要按照原来的顺序输出,所以在结构体里加个属性来判断是否进行修改,最后统计一下有几个是修改过的就没有问题了。代码如下:

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<list>
#include<climits>
#include<queue>
#include<cstring>
using namespace std;
struct person{
	string id;
	string password;
	bool mod;
};
person cur[1005];
int main()
{
	int n;
	cin >> n;
	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> cur[i].id >> cur[i].password;
		cur[i].mod = false;
		for (int j = 0; j < cur[i].password.size(); j++) {
			if (cur[i].password[j] == '1') {
				cur[i].password[j] = '@';
				cur[i].mod = true;
				continue;
			}else if (cur[i].password[j] == '0') {
				cur[i].password[j] = '%';
				cur[i].mod = true;
				continue;
			}else if (cur[i].password[j] == 'l') {
				cur[i].password[j] = 'L';
				cur[i].mod = true;
				continue;
			}else if (cur[i].password[j] == 'O') {
				cur[i].password[j] = 'o';
				cur[i].mod = true;
				continue;
			}
			else {
				continue;
			}
		}
		if (cur[i].mod)count++;
	}
	if (n == 0)return 0;
	if (count == 0 && n == 1)cout << "There is 1 account and no account is modified" << endl;
	else if (count == 0 && n > 1)cout << "There are " << n << " accounts and no account is modified" << endl;
	 if (count != 0) {
		cout << count << endl;
		for (int i = 0; i < n; i++) {
			if (cur[i].mod) {
				cout << cur[i].id << " " << cur[i].password << endl;
			}
		}
	}
	return 0;
}

1036 Boys vs Girls (25 分)

This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N, followed by N lines of student information. Each line contains a student's namegenderID and grade, separated by a space, where name and ID are strings of no more than 10 characters with no space, gender is either F (female) or M (male), and grade is an integer between 0 and 100. It is guaranteed that all the grades are distinct.

Output Specification:

For each test case, output in 3 lines. The first line gives the name and ID of the female student with the highest grade, and the second line gives that of the male student with the lowest grade. The third line gives the difference grade​F​​−grade​M​​. If one such kind of student is missing, output Absent in the corresponding line, and output NA in the third line instead.

Sample Input 1:

3
Joe M Math990112 89
Mike M CS991301 100
Mary F EE990830 95

Sample Output 1:

Mary EE990830
Joe Math990112
6

Sample Input 2:

1
Jean M AA980920 60

Sample Output 2:

Absent
Jean AA980920
NA

题目大意:就是给一堆学生列表,输出Male里的成绩最小值和Fmale里的成绩最大值,如果有一个没有就输出Absent,然后最后一行输出F-M,如果有一个没有就输出NA

解题思路:水题,分开存一下,分别排序,因为没说N的范围,所以建议用Vector来。

代码如下:

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<list>
#include<climits>
#include<queue>
#include<cstring>
using namespace std;
struct stu {
	string name;
	string course;
	int grade;
};
bool cmp(stu a, stu b) {
	return a.grade < b.grade;
}
vector<stu> male;
vector<stu> fmale;
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		stu cur;
		char sex;
		cin >> cur.name >> sex >> cur.course >> cur.grade;
		if (sex == 'F') {
			fmale.push_back(cur);
		}
		else {
			male.push_back(cur);
		}
	}
	sort(male.begin(), male.end(), cmp);
	sort(fmale.begin(), fmale.end(), cmp);
	if (fmale.size() == 0 && male.size() != 0) {
		cout << "Absent" << endl;
		cout << male[0].name << " " << male[0].course << endl;
		cout << "NA" << endl;
	}
	else if (fmale.size() != 0 && male.size() == 0) {
		cout << fmale[fmale.size() - 1].name << " " << fmale[fmale.size() - 1].course << endl;
		cout << "Absent" << endl;
		cout << "NA" << endl;
	}
	else if (fmale.size() != 0 && male.size() != 0) {
		cout << fmale[fmale.size() - 1].name << " " << fmale[fmale.size() - 1].course << endl;
		cout << male[0].name << " " << male[0].course << endl;
		cout << fmale[fmale.size() - 1].grade - male[0].grade<< endl;
	}
	else if (fmale.size() == 0 && male.size() == 0) {
		cout << "Absent" << endl;
		cout << "Absent" << endl;
		cout << "NA" << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/TateBrwonJava/article/details/83026008