pat-advanced(1035-1038)

1035. Password (20)

时间限制

400 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

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 N is 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 [email protected]

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
//1035
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

struct member {
	char name[11];
	char passw[11];
};

member mems[1005];

int main()
{
	int N;
	scanf("%d", &N);
	int n = 0;
	vector<int> order;
	getchar();

	int i;
	for(i = 0; i < N; i++)
	{
		scanf("%s %s",mems[i].name, mems[i].passw);
		getchar();

		int len = strlen(mems[i].passw);
		int j;
		int m = 0;
		for(j = 0; j < len; j++)
		{
			switch(mems[i].passw[j])
			{
				case '1':
					mems[i].passw[j] = '@';
					m = 1;
					break;
				case '0':
					mems[i].passw[j] = '%';
					m = 1;
					break;
				case 'l':
					mems[i].passw[j] = 'L';
					m = 1;
					break;
				case 'O':
					mems[i].passw[j] = 'o';
					m = 1;
					break;
				default:
					break;
			}
		}
		if(m == 1)
			order.push_back(i);
	}

	if(order.empty())
	{
		if(N == 1)
			printf("There is %d account and no account is modified\n", N);
		else
			printf("There are %d accounts and no account is modified\n", N);
	}
	else
	{
		printf("%d\n", order.size());
		for(i = 0; i < order.size(); i++)
		{
			int j = order[i];
			printf("%s %s\n", mems[j].name, mems[j].passw);
		}
	}

	return 0;
}

1036. Boys vs Girls (25)

时间限制

400 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

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 name, gender, ID 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 gradeF-gradeM.
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
//1036
#include <cstring>
#include <cstdio>
#include <vector>

using namespace std;

struct stu {
	char name[11];
	char gender;
	char id[11];
	int grade;
};

stu stus[100001];

int main()
{
	int N;
	scanf("%d", &N);
	getchar();

	int i;
	for(i = 0; i < N; i++)
	{
		scanf("%s %c %s %d", stus[i].name, &stus[i].gender, stus[i].id, &stus[i].grade);
		getchar();
	}

	int lowest_m = 101;
	int highest_f = -1;
	int x = -1, y = -1;

	for(i = 0; i < N; i++)
	{
		if(stus[i].gender == 'M')
		{
			if(stus[i].grade < lowest_m)
			{
				lowest_m = stus[i].grade;
				x = i;
			}
		}
		else
		{
			if(stus[i].grade > highest_f)
			{
				highest_f = stus[i].grade;
				y = i;
			}
		}
	}

	if(y != -1)
		printf("%s %s\n", stus[y].name, stus[y].id);
	else
		printf("Absent\n");

	if(x != -1)
		printf("%s %s\n", stus[x].name, stus[x].id);
	else
		printf("Absent\n");

	if(x != -1 && y != -1)
		printf("%d\n", stus[y].grade - stus[x].grade);
	else
		printf("NA\n");

	return 0;
}

1037. Magic Coupon (25)

时间限制

100 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value of that product back! What is more, the shop also offers some bonus product
for free. However, if you apply a coupon with a positive N to this bonus product, you will have to pay the shop N times the value of the bonus product... but hey, magically, they have some coupons with negative N‘s!

For example, given a set of coupons {1 2 4 -1}, and a set of product values {7 6 -2 -3} (in Mars dollars M$) where a negative value corresponds to a bonus product. You can apply coupon 3 (with N being 4) to product 1 (with value M$7) to get M$28 back; coupon
2 to product 2 to get M$12 back; and coupon 4 to product 4 to get M$3 back. On the other hand, if you apply coupon 3 to product 4, you will have to pay M$12 to the shop.

Each coupon and each product may be selected at most once. Your task is to get as much money back as possible.

Input Specification:

Each input file contains one test case. For each case, the first line contains the number of coupons NC, followed by a line with NC coupon integers. Then the next line contains the number of products NP, followed by a line with NP product values. Here 1<= NC,
NP <= 105, and it is guaranteed that all the numbers will not exceed 230.

Output Specification:

For each test case, simply print in a line the maximum amount of money you can get back.

Sample Input:

4
1 2 4 -1
4
7 6 -2 -3

Sample Output:

43
//1037
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

long long couple[100001];
long long product[100001];

int main()
{
	int NC, NP;
	scanf("%d", &NC);

	int i;
	for(i = 0; i< NC; i++)
		scanf("%lld", &couple[i]);
	scanf("%d", &NP);
	for(i = 0; i< NP; i++)
		scanf("%lld", &product[i]);

	long long max_v = 0;

	sort(couple, couple + NC);

	sort(product, product + NP);
	int i1 = 0, i2 = NC - 1;
	int j1 = 0, j2 = NP - 1;

	while(i1 <= i2 && j1 <= j2)
	{
		if(couple[i1]<0 && product[j1]<0)
			max_v += couple[i1] * product[j1];
		else
			break;
		i1++;j1++;
	}

	while(i2>=0 && j2>=0)
	{
		if(couple[i2]>0 && product[j2]>0)
			max_v += couple[i2] * product[j2];
		else
			break;
		i2--;j2--;
	}

	printf("%lld\n", max_v);
	return 0;
}

1038. Recover the Smallest Number (30)

时间限制

400 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different orders
of combinations of these segments, and the smallest number is 0229-321-3214-32-87.

Input Specification:

Each input file contains one test case. Each case gives a positive integer N (<=10000) followed by N number segments. Each segment contains a non-negative integer of no more than 8 digits. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the smallest number in one line. Do not output leading zeros.

Sample Input:

5 32 321 3214 0229 87

Sample Output:

22932132143287
//1038
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
using namespace std;

bool cmp(string a, string b)
{
	return (a+b) < (b+a);
}

int main()
{
	int N;
	cin>> N;
	vector<string> input(N);

	int i;
	for(i = 0; i< N;i++)
	{
		cin>> input[i];
	}

	sort(input.begin(), input.end(), cmp);
	int flag = 0;
	for(i = 0; i < N; i++)
	{
		if(flag == 0)
		{
			int j = 0;
			while(j < input[i].size() &&input[i][j] == '0')
				j++;

			if(j < input[i].size())
			{
				cout<<input[i].substr(j, input[i].size()-j);
				flag = 1;
			}
		}
		else
			cout<< input[i];
	}

	if(flag == 0)
		cout<< "0";
	cout<< endl;
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-09 03:38:31

pat-advanced(1035-1038)的相关文章

PAT Advanced Level 1038

1038 Recover the Smallest Number (30)(30 分) Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or 0

PAT Advanced 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)

PAT (Advanced Level) 1038. Recover the Smallest Number (30)

注意前导零的消去. #include <iostream> #include <string> #include <sstream> #include <algorithm> using namespace std; string s[10000+10]; int n; bool cmp(const string &a, const string &b) { return a+b<b+a; } int main() { cin>&

Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)

Pat1043代码 题目描述: A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes

Pat(Advanced Level)Practice--1044(Shopping in Mars)

Pat1044代码 题目描述: Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diam

PAT (Advanced Level) 1093. Count PAT&#39;s (25)

预处理每个位置之前有多少个P,每个位置之后有多少个T. 对于每个A,贡献的答案是这个A之前的P个数*这个A之后T个数. #include<cstdio> #include<cstring> long long MOD=1e9+7; const int maxn=1e5+10; long long dp1[maxn],dp2[maxn]; char s[maxn]; int main() { scanf("%s",s); memset(dp1,0,sizeof d

PAT (Advanced Level) 1055. The World&#39;s Richest (25)

排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using names

Pat(Advanced Level)Practice--1018(Public Bike Management)

Pat1018代码 题目描述: There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city. The Public Bike Management C

Pat(Advanced Level)Practice--1076(Forwards on Weibo)

Pat1076代码 题目描述: Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all hi

Pat(Advanced Level)Practice--1016(Phone Bills)

Pat1016代码 题目描述: A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a lon