B1004. 成绩排名 (20)

Description:

读入n名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。

Input:

每个测试输入包含1个测试用例,格式为:

第1行:正整数n
第2行:第1个学生的姓名 学号 成绩
第3行:第2个学生的姓名 学号 成绩
... ... ...
第n+1行:第n个学生的姓名 学号 成绩

其中姓名和学号均为不超过10个字符的字符串,成绩为0到100之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。

Output:

对每个测试用例输出2行,第1行是成绩最高学生的姓名和学号,第2行是成绩最低学生的姓名和学号,字符串间有1空格。

Sample Input:

3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95

Sample Output:

Mike CS991301
Joe Math990112

 #include <cstdio>

 struct Student{
char name[];
char id[];
int score;
}temp, ans_max, ans_min; int main()
{
int n;
scanf("%d", &n);
ans_max.score = -;
ans_min.score = ;
for(int i=; i<n; ++i) {
scanf("%s%s%d", temp.name, temp.id, &temp.score);
if(temp.score > ans_max.score) ans_max = temp;
if(temp.score < ans_min.score) ans_min = temp;
} printf("%s %s\n%s %s\n", ans_max.name, ans_max.id, ans_min.name, ans_min.id); return ;
}

B1028. 人口普查 (20)

Description:

某城镇进行人口普查,得到了全体居民的生日。现请你写个程序,找出镇上最年长和最年轻的人。

这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过200岁的老人,而今天是2014年9月6日,所以超过200岁的生日和未出生的生日都是不合理的,应该被过滤掉。

Input:

输入在第一行给出正整数N,取值在(0, 105];随后N行,每行给出1个人的姓名(由不超过5个英文字母组成的字符串)、以及按“yyyy/mm/dd”(即年/月/日)格式给出的生日。题目保证最年长和最年轻的人没有并列。

Output:

在一行中顺序输出有效生日的个数、最年长人和最年轻人的姓名,其间以空格分隔。

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

 #include <cstdio>
#include <cstring> #define MaxSize 11
struct birthday {
char name[MaxSize];
char date[MaxSize];
}temp, maxn, minn;
char floor[MaxSize] = "1814/09/06", upper[MaxSize] = "2014/09/06"; int main()
{
//freopen("E:\\Temp\\input.txt", "r", stdin); for(int i=; i<MaxSize; ++i) {
maxn.date[i] = floor[i];
minn.date[i] = upper[i];
}
int N;
scanf("%d", &N);
int counter = N;
for(int i=; i<N; ++i) {
scanf("%s %s", temp.name, temp.date);
if(strcmp(temp.date, floor)< || strcmp(temp.date, upper)>)
--counter;
else {
if(strcmp(temp.date, maxn.date) >= ) maxn = temp;
if(strcmp(temp.date, minn.date) <= ) minn = temp;
}
} if(counter != )
printf("%d %s %s\n", counter, minn.name, maxn.name);
else
printf("0\n"); return ;
}
 #include <cstdio>

 struct person {
char name[];
int yy, mm, dd;
}oldest, youngest, left, right, temp; bool LessEqu(person a, person b)
{
if(a.yy != b. yy) return a.yy <= b.yy;
else if(a.mm != b.mm) return a.mm <= b.mm;
else return a.dd <= b.dd;
}
bool MoreEqu(person a, person b)
{
if(a.yy != b. yy) return a.yy >= b.yy;
else if(a.mm != b.mm) return a.mm >= b.mm;
else return a.dd >= b.dd;
}
void init()
{
youngest.yy = left.yy = ;
oldest.yy = right.yy = ;
youngest.mm = oldest.mm = left.mm = right.mm = ;
youngest.dd = oldest.dd = left.dd = right.dd = ;
} int main()
{
init();
int n, num = ;
scanf("%d", &n);
for(int i=; i<n; ++i) {
scanf("%s %d/%d/%d", temp.name, &temp.yy, &temp.mm, &temp.dd);
if(MoreEqu(temp, left) && LessEqu(temp, right)) {
num++;
if(LessEqu(temp, oldest)) oldest = temp;
if(MoreEqu(temp, youngest)) youngest = temp;
}
} if(num == ) printf("0\n");
else printf("%d %s %s\n", num, oldest.name, youngest.name); return ;
}

B1032. 挖掘机技术哪家强 (20)

Description:

为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。

Input:

输入在第1行给出不超过105的正整数N,即参赛人数。随后N行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从1开始连续编号)、及其比赛成绩(百分制),中间以空格分隔。

Output:

在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。

Sample Input:

6
3 65
2 80
1 100
2 70
3 40
3 0

Sample Output:

2 150

 #include <cstdio>

 const int maxn = ;
int school[maxn]; int main()
{
int n, schID, score;
scanf("%d", &n);
for(int i=; i<n; ++i) {
scanf("%d%d", &schID, &score);
school[schID] += score;
} int k = , MAX = -;
for(int i=; i<=n; ++i) {
if(school[i] > MAX) {
MAX = school[i];
k = i;
}
} printf("%d %d\n", k, MAX); return ;
}

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 would be the product of the three odds times 65%.

For example, 3 games' odds are given as the following:

 W    T    L
1.1 2.5 1.7
1.2 3.0 1.6
4.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 would 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 T W 37.98

 #include <cstdio>

 char S[] = {'W', 'T', 'L'};

 int main()
{
double ans = , temp, a;
int idx;
for(int i=; i<; ++i) {
temp = ;
for(int j=; j<; ++j) {
scanf("%lf", &a);
if(a > temp) {
temp = a;
idx = j;
}
}
ans *= temp;
printf("%c ", S[idx]);
} printf("%.2f\n", (ans*0.65-)*); return ;
}

A1006. Sign In and Sign Out (25)

Description:

At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.

Input:

Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:

ID_number Sign_in_time Sign_out_time

where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.

Output:

For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.

Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.

Sample Input:

3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40

Sample Output:

SC3021234 CS301133

 #include <cstdio>
#include <cstring> #define MaxSize 20
struct Person {
char id[MaxSize];
char in[MaxSize];
char out[MaxSize];
}temp, In, Out; int main()
{
//freopen("E:\\Temp\\input.txt", "r", stdin); char a[] = "00:00:00", b[] = "23:59:59";
for(int i=; i<; ++i) {
In.in[i] = Out.in[i] = b[i];
In.out[i] = Out.out[i] = a[i];
}
int N;
scanf("%d", &N);
for(int i=; i<N; ++i) {
scanf("%s %s %s", temp.id, temp.in, temp.out);
if(strcmp(temp.in, In.in) < ) In = temp;
if(strcmp(temp.out, Out.out) > ) Out = temp;
} printf("%s %s\n", In.id, Out.id); return ;
}
 #include <cstdio>

 struct pNode {
char id[];
int hh, mm, ss;
}temp, ans1, ans2; bool great(pNode node1, pNode node2) {
if(node1.hh != node2.hh) return node1.hh > node2.hh;
if(node1.mm != node2.mm) return node1.mm > node2.mm;
return node1.ss > node2.ss;
} int main()
{
int n;
scanf("%d", &n);
ans1.hh = , ans1.mm = , ans1.ss = ;
ans2.hh = , ans2.mm = , ans2.ss = ;
for(int i=; i<n; ++i) {
scanf("%s %d:%d:%d", temp.id, &temp.hh, &temp.mm, &temp.ss);
if(great(temp, ans1) == false) ans1 = temp;
scanf("%d:%d:%d", &temp.hh, &temp.mm, &temp.ss);
if(great(temp, ans2) == true) ans2 = temp;
} printf("%s %s\n", ans1.id, ans2.id); return ;
}

A1036. Boys vs Girls (25)

Description:

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:

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:

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 Input1:

3

Joe M Math990112 89

Mike M CS991301 100

Mary F EE990830 95

Sample Output1:

Mary EE990830

Joe Math990112

6

Sample Input 2:

1

Jean M AA980920 60

Sample Output 2:

Absent

Jean AA980920

NA

 #include <cstdio>

 struct person {
char name[];
char id[];
int score;
}M, F, temp; void init()
{
M.score = ;
F.score = -;
} int main()
{
init();
int n;
char gender;
scanf("%d", &n);
for(int i=; i<n; ++i) {
scanf("%s %c %s %d", temp.name, &gender, temp.id, &temp.score);
if(gender=='M' && temp.score<M.score) M = temp;
else if(gender=='F' && temp.score>F.score) F = temp;
} if(F.score == -) printf("Absent\n");
else printf("%s %s\n", F.name, F.id);
if(M.score == ) printf("Absent\n");
else printf("%s %s\n", M.name, M.id);
if(F.score==- || M.score==) printf("NA\n");
else printf("%d\n", F.score-M.score); return ;
}

PAT/查找元素习题集的更多相关文章

  1. C++泛型编程(2)--通过排序和查找元素理解迭代器

    许多C++开源库(stl,opencv,ros和blas等)都使用了大量的泛型编程的思想,如果不理解这些思想,将很难看懂代码,而<泛型编程与STL>一书对理解泛型编程思想非常的有帮助,这里 ...

  2. DOM查找元素

    1. 查找元素5种: 1. 按id查找1个元素对象: var elem=document.getElementById("id值"); 何时使用:1. 元素必须有id 2. 精确查 ...

  3. Appium查找元素

    记录一些需要记忆的查找元素的内容: 1. driver.findElement(By.name("DELETE");   //We can use the DELETE text ...

  4. jsoup使用选择器语法来查找元素

    问题 你想使用类似于CSS或jQuery的语法来查找和操作元素. 方法 可以使用Element.select(String selector) 和 Elements.select(String sel ...

  5. javascript中通过className灵活查找元素 例如我们要把根据class来进行修改样式

    一.背景:一个表单中,要修改一些li中有class=box的样式,将它的background设置为red红色.一般的做法是我们可以先找到父级元素 ,然后由父级元素找到所有相关tagName,最后,来一 ...

  6. DOM 之 document 查找元素方法

    DOM 之 document 查找元素方法 getElementById("idName"); // 始终取得第一个 idName 的元素 getElementsByTagName ...

  7. crawler_jsoup HTML解析器_使用选择器语法来查找元素

    参照:http://www.open-open.com/jsoup/selector-syntax.htm 使用选择器语法来查找元素 问题 你想使用类似于CSS或jQuery的语法来查找和操作元素. ...

  8. Javascript 查找元素

    DOM定义了多种查找元素的方法,除了我们常用的getElementById(),还有getElementsByTagName()和getElementsByName().使用这几种方法方法我们可以查找 ...

  9. jquery查找元素

    一:查找元素 * 所有元素 element 该名称的所有元素(p,input) #id 拥有指定id属性的元素 .class 拥有所有指定class属性的元素 selector1,selector2 ...

随机推荐

  1. MyEclipse +Flex 整合

         最近想利用red5开发一个流媒体的程序,在网上找了半天没有一个可用的代码,要么是下载需要多少币,要么是没有.纠结了半天,最后决定自检看着文字版本的教程,自己编写一个.         看着一 ...

  2. Android.mk 基本应用

    如果是在android源码里面编译我们自己的应用,就需要这个android.mk文件,这个文件就告诉android系统应用如何来编译这个应用以及这个应用它所依赖哪些文件等等信息.我对android.m ...

  3. NC 单据保存时间过长,判断数据库锁表解决办法

    SELECT s.sid, s.serial# FROM gv$locked_object l, dba_objects o, gv$session s WHERE l.object_id = o.o ...

  4. notepad++ 配置Python 调试环境 实用版

    一. 安装python 1. 下载python 2.7版本并安装: 2. 在安装到自定义python的时候选择 add python to ptah项:

  5. POJ 3469 Dual Core CPU 最大流

    划分成两个集合使费用最小,可以转成最小割,既最大流. //#pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...

  6. CSS浏览器兼容问题总结

    为什么会出现浏览器兼容问题? 由于各大主流浏览器是不同的厂家开发的,所以使用的核心也不相同,架构代码很难重合,就会产生各种各样的bug. IE6中常见的css解析bug 1)默认高度(IE6)部分块元 ...

  7. Windows 环境下配置 git bash 的 HOME 默认路径

    0.引 在 windows 下安装 git 之后, git 默认的HOME和~路径一般都是C:\Users\用户名,每次得用命令切换到常用的Repository下,此操作重复而没有意义.为了修改默认路 ...

  8. 1.1使用内置的Camara应用程序捕捉图像

    一: Camara应用程序包含的意图过滤器 <intent-filter> <action android:name="android.media.action.IMAGE ...

  9. C# 京东模拟登录小结

    最近有需要模拟京东登录,在解决过程中遇到了一些问题,因此这里记录下来避免以后遇到同样的问题. 首先第一步需要做的是找到登录请求网址和关于请求所需的一些信息.这里可以用抓取工具或者直接用firebug或 ...

  10. tomcat 性能优化

    tomcat 性能优化tomcat默认参数是为开发环境制定,而非适合生产环境,尤其是内存和线程的配置,默认都很低,容易成为性能瓶颈. tomcat内存优化linux修改TOMCAT_HOME/bin/ ...