4. Find the element

1.A1006

#include<stdio.h> 
#include<iostream>
#include<string.h>
using namespace std;
struct pNode{
	char id[20];
	int hh,mm,ss;
}temp,ans1,ans2;
bool great(pNode a,pNode b){
	if(a.hh != b.hh)	return a.hh>b.hh;
	else if(a.mm != b.mm)	return a.mm>b.mm;
	return a.ss>b.ss; 
}
int main(){
	int n;
	scanf("%d",&n);
	ans1.hh = 24,ans1.mm = 60,ans1.ss = 60;
	ans2.hh = 0,ans2.mm = 0,ans2.ss = 0;
	for(int i = 0;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 0;
}

2.A1011

#include<stdio.h>
char S[3] = {'W','T','L'}; 
int main(){
	double ans = 1.0,tmp,a;
	int idx;
	for(int i = 0;i<3;i++){
		tmp = 0.0;
		for(int j = 0;j<3;j++){
			scanf("%lf",&a);
			if(a>tmp){
				tmp = a;
				idx = j;
			}
		}
		ans *= tmp;
		printf("%c ",S[idx]);
	}
	printf("%.2f",(ans*0.65-1)*2);
	return 0;
}

3.A1036

#include<stdio.h> 
struct person{
	char name[15];
	char id[15];
	int score;
}M,F,temp;
void init(){
	M.score = 101;
	F.score = -1;
}
int main(){
	init();
	int n;
	char gender;
	scanf("%d",&n);
	while(n--){
		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 == -1)	printf("Absent\n");
	else	printf("%s %s\n",F.name,F.id);
	if(M.score == 101)	printf("Absent\n");
	else	printf("%s %s\n",M.name,M.id);
	if(F.score == -1 || M.score == 101)	printf("NA\n");
	else	printf("%d\n",F.score-M.score);
	return 0;
}

4.B1004

#include<stdio.h>
struct Student{
	char name[15];
	char id[15];
	int score;
}temp,Max,Min; 
int main(){
	int n;
	scanf("%d",&n);
	Max.score = -1;
	Min.score = 101;
	while(n--){
		scanf("%s%s%d",&temp.name,&temp.id,&temp.score);
		if(temp.score>Max.score)	Max = temp;
		if(temp.score<Min.score)	Min = temp;
	}
	printf("%s %s\n",Max.name,Max.id);
	printf("%s %s\n",Min.name,Min.id);
	return 0;
}

5.B1028

#include<stdio.h>
struct person{
	char name[10];
	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 = 1814;
	oldest.yy = right.yy = 2014;
	youngest.mm = oldest.mm = left.mm = right.mm = 9; 
	youngest.dd = oldest.dd = left.dd = right.dd = 6; 
}
int main(){
	init();
	int n,num = 0;
	scanf("%d",&n);
	while(n--){
		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==0)	printf("0\n");
	else	printf("%d %s %s\n",num,oldest.name,youngest.name);
	return 0;
}

6.B1032

#include<stdio.h>
const int max = 100010;
int school[max] = {0};
int main(){
	int n,num,score;
	scanf("%d",&n);
	for(int i = 0;i<n;i++){
		scanf("%d%d",&num,&score);
		school[num]+=score;
	}
	int k = 1,MAX = -1; 
	for(int i = 1;i<=n;i++){
		if(MAX<school[i]){
			MAX = school[i];
			k = i;
		}
	}		
	printf("%d %d",k,MAX);
	return 0;
}

7.B1041

#include<stdio.h>
const int maxn = 1010; 
struct Student{
	long long id;
	int examSeat;
}testSeat[maxn];
int main(){
	int n,m,seat,examSeat;
	long long id;
	scanf("%d",&n);
	while(n--){
		scanf("%lld %d %d",&id,&seat,&examSeat);
		testSeat[seat].id = id;
		testSeat[seat].examSeat = examSeat;
	}
	scanf("%d",&m);
	for(int i = 0;i<m;i++){
		scanf("%d",&seat);
		printf("%lld %d\n",testSeat[seat].id,testSeat[seat].examSeat);
	}
	return 0;
}
Published 26 original articles · won praise 3 · Views 193

Guess you like

Origin blog.csdn.net/qq_41898248/article/details/104051599