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; }
版权声明:本文为博主原创文章,未经博主允许不得转载。