PAT/search for element question sets and pat element question sets
B1004. score ranking (20)
Description:
The name, student ID, and score of n students are read, and the names and student IDs of the students with the highest and lowest scores are output respectively.
Input:
Each test input contains one test case in the following format:
Row 1st: positive integer n row 2nd: 1st Student name score row 3rd: 2nd Student name score ......... row n + 1: score of student n
The name and student ID are strings of no more than 10 characters, and the score is an integer between 0 and 100. Here we ensure that no two students in a group of test cases have the same score.
Output:
Two lines are output for each test case. Row 1st is the name and student ID of the top student with the highest score, row 2nd is the name and student ID of the top student with the lowest score, and there is a space between the strings.
Sample Input:
3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95
Sample Output:
Mike CS991301
Joe Math990112
1 #include <cstdio> 2 3 struct Student{ 4 char name[15]; 5 char id[15]; 6 int score; 7 }temp, ans_max, ans_min; 8 9 int main()10 {11 int n;12 scanf("%d", &n);13 ans_max.score = -1;14 ans_min.score = 101;15 for(int i=0; i<n; ++i) {16 scanf("%s%s%d", temp.name, temp.id, &temp.score);17 if(temp.score > ans_max.score) ans_max = temp;18 if(temp.score < ans_min.score) ans_min = temp;19 }20 21 printf("%s %s\n%s %s\n", ans_max.name, ans_max.id, ans_min.name, ans_min.id);22 23 return 0;24 }
B1028. census (20)
Description:
A town made a census and got the birthday of all the residents. Please write a program to find the youngest person in the town.
Make sure that every input date is valid, but not necessarily reasonable-assume that there are no more than 200 elderly people in the town, and today is September 6, 2014, therefore, the 200-year-old birthday and the birthdate are unreasonable and should be filtered out.
Input:
The input value is a positive integer N in the first line and the value is (0,105]. In the next N rows, each line is given a name of one person (a string consisting of no more than five English letters) and the birthday in the format of yyyy/mm/dd (year/month/day. The topic must be separated by the youngest and longest people.
Output:
Output The number of valid birthdays, names of the oldest and the youngest in a row in sequence, separated by spaces.
Sample Input:
5
John 2001/05/12
Tom 1814/09/06
Ann 2121/01/30
James 1814/09/05
Steve 1967/11/20
Sample Output:
3 Tom John
1 #include <cstdio> 2 #include <cstring> 3 4 #define MaxSize 11 5 struct birthday { 6 char name[MaxSize]; 7 char date[MaxSize]; 8 }temp, maxn, minn; 9 char floor[MaxSize] = "1814/09/06", upper[MaxSize] = "2014/09/06";10 11 int main()12 {13 //freopen("E:\\Temp\\input.txt", "r", stdin);14 15 for(int i=0; i<MaxSize; ++i) {16 maxn.date[i] = floor[i];17 minn.date[i] = upper[i];18 }19 int N;20 scanf("%d", &N);21 int counter = N;22 for(int i=0; i<N; ++i) {23 scanf("%s %s", temp.name, temp.date);24 if(strcmp(temp.date, floor)<0 || strcmp(temp.date, upper)>0)25 --counter;26 else {27 if(strcmp(temp.date, maxn.date) >= 0) maxn = temp;28 if(strcmp(temp.date, minn.date) <= 0) minn = temp;29 }30 }31 32 if(counter != 0)33 printf("%d %s %s\n", counter, minn.name, maxn.name);34 else35 printf("0\n");36 37 return 0;38 }
1 #include <cstdio> 2 3 struct person { 4 char name[10]; 5 int yy, mm, dd; 6 }oldest, youngest, left, right, temp; 7 8 bool LessEqu(person a, person b) 9 {10 if(a.yy != b. yy) return a.yy <= b.yy;11 else if(a.mm != b.mm) return a.mm <= b.mm;12 else return a.dd <= b.dd;13 }14 bool MoreEqu(person a, person b)15 {16 if(a.yy != b. yy) return a.yy >= b.yy;17 else if(a.mm != b.mm) return a.mm >= b.mm;18 else return a.dd >= b.dd;19 }20 void init()21 {22 youngest.yy = left.yy = 1814;23 oldest.yy = right.yy = 2014;24 youngest.mm = oldest.mm = left.mm = right.mm = 9;25 youngest.dd = oldest.dd = left.dd = right.dd = 6;26 }27 28 int main()29 {30 init();31 int n, num = 0;32 scanf("%d", &n);33 for(int i=0; i<n; ++i) {34 scanf("%s %d/%d/%d", temp.name, &temp.yy, &temp.mm, &temp.dd);35 if(MoreEqu(temp, left) && LessEqu(temp, right)) {36 num++;37 if(LessEqu(temp, oldest)) oldest = temp;38 if(MoreEqu(temp, youngest)) youngest = temp;39 }40 }41 42 if(num == 0) printf("0\n");43 else printf("%d %s %s\n", num, oldest.name, youngest.name);44 45 return 0;46 }
B1032. which excavator technology is strong (20)
Description:
PAT organized an excavator Skill Competition to show which excavator technology is strong. Please calculate the most technically competent school based on the competition results.
Input:
Enter a positive integer N of no more than 1st in row 105, that is, the number of participants. In the next N rows, each row provides information and scores of a contestant, including the number of the school it represents (from 1), and the score of the competition (percentage ), separated by spaces.
Output:
The number and total score of the school with the highest total score are given in a row, separated by spaces. The answer to the question must be unique.
Sample Input:
6
3 65
2 80
1 100
2 70
3 40
3 0
Sample Output:
2 150
1 #include <cstdio> 2 3 const int maxn = 100010; 4 int school[maxn]; 5 6 int main() 7 { 8 int n, schID, score; 9 scanf("%d", &n);10 for(int i=0; i<n; ++i) {11 scanf("%d%d", &schID, &score);12 school[schID] += score;13 }14 15 int k = 1, MAX = -1;16 for(int i=1; i<=n; ++i) {17 if(school[i] > MAX) {18 MAX = school[i];19 k = i;20 }21 }22 23 printf("%d %d\n", k, MAX);24 25 return 0;26 }
A1011. World Cup Betting (20)
Description:
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.
Chinese Football Lottery provided a "Triple Winning" game. the rule of winning was simple: first select any three of the games. then for each selected game, bet on one of the three possible results -- namely W for win, T for tie, and L for lose. there was an odd assigned to each result. the winner's odd wocould be the product of the three odds times 65%.
For example, 3 games 'odds are given as the following:
W T L1.1 2.5 1.71.2 3.0 1.64.1 1.2 1.1
To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd game, and T for the 1st game. if each bet takes 2 yuans, then the maximum profit wocould be (4.1*3.0*2.5 * 65%-1) * 2 = 37.98 yuans (accurate up to 2 decimal places ).
Input:
Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to W, T and L.
Output:
For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.
Sample Input:
1.1 2.5 1.7
1.2 3.0 1.6
4.1 1.2 1.1
Sample Output:
T w 37.98
1 #include <cstdio> 2 3 char S[3] = {'W', 'T', 'L'}; 4 5 int main() 6 { 7 double ans = 1, temp, a; 8 int idx; 9 for(int i=0; i<3; ++i) {10 temp = 0;11 for(int j=0; j<3; ++j) {12 scanf("%lf", &a);13 if(a > temp) {14 temp = a;15 idx = j;16 }17 }18 ans *= temp;19 printf("%c ", S[idx]);20 }21 22 printf("%.2f\n", (ans*0.65-1)*2);23 24 return 0;25 }