会一直更新的,略略略
PAT (Basic Level) Practice (中文)
B1004
/*
pat B4004
time:2017/7/26 22:22
*/
#include<cstdio>
#include<algorithm>
using namespace std;
struct student{
char name[11];
char id[11];
int score;
}tmp,ans_max,ans_min;
int main(){
int n;
scanf("%d",&n);
ans_max.score = -1;
ans_min.score = 101;
for(int i = 0;i<n;i++){
char name[11],id[11];
int socre;
scanf("%s%s%d",tmp.name,tmp.id,&tmp.score);
if(tmp.score>ans_max.score){
ans_max = tmp;
}
if(tmp.score<ans_min.score){
ans_min = tmp;
}
}
printf("%s %s\n",ans_max.name,ans_max.id,ans_max.score);
printf("%s %s\n",ans_min.name,ans_min.id,ans_min.score);
return 0;
}
/*
const int N = 10000000;
struct student{
char name[11];
char id[11];
int score;
}stu[N];
bool cmp(student a,student b){
return a.score<b.score;
}
int main(){
int n;
scanf("%d",&n);
for(int i = 0;i<n;i++){
scanf("%s%s%d",stu[i].name,stu[i].id,&stu[i].score);
}
sort(stu,stu+n,cmp);
printf("%s %s\n",stu[n-1].name,stu[n-1].id,stu[n-1].score);
printf("%s %s\n",stu[0].name,stu[0].id,stu[0].score);
return 0;
}
*/
B1028
/*
pat b1028
time:2017/7/26 22:47
*/
#include<cstdio>
#include<cstring>
int y,m,d;
void change(char str[]){
y = 0,m = 0,d = 0;
//printf("%s\n",str);
for(int i = 0;i<4;i++){
y=y*10+(str[i]-'0');
}
for(int i = 5;i<7;i++){
m=m*10+(str[i]-'0');
}
for(int i = 8;i<10;i++){
d=d*10+(str[i]-'0');
}
}
int main(){
int date1 = 18140906;
int date2 = 20140906;
int max = -1;
int min = 20140907;
char nameMax[6];
char nameMin[6];
int tmp;
int count = 0;
int n;
scanf("%d",&n);
char str1[6],str2[11];
for(int i = 0;i<n;i++){
getchar();
scanf("%s%s",str1,str2);
change(str2);
tmp = y*10000+m*100+d;
//printf("%d %d %d %d\n\n\n\n\n",y,m,d,tmp);
if(tmp>=date1 && tmp<=date2){
count++;
if(tmp>max){
max = tmp;
strcpy(nameMax,str1);
}
if(tmp<min){
min = tmp;
strcpy(nameMin,str1);
}
}
}
if(count == 0){
printf("0\n");
return 0;
}
printf("%d %s %s\n",count,nameMin,nameMax);
return 0;
}
B1032
/*
pat b1032
time:2017/7/26 23:39
*/
#include<cstdio>
const int N = 100000+10;
int score[N];
int main(){
int n;
scanf("%d",&n);
for(int i = 0;i<n;i++){
int a,b;
scanf("%d%d",&a,&b);
score[a] += b;
}
int flag = -1,max = -1;
for(int i = 1;i<=n;i++){
if(score[i] > max){
flag = i;
max = score[i];
}
}
printf("%d %d\n",flag,score[flag]);
return 0;
}
B1036
/*
pat b1036
time:2017/7/17 21:11
*/
#include<cstdio>
#include<cmath>
int main(){
int n;
char c;
scanf("%d %c",&n,&c);
int cow = (int)round(n*1.0/2);
//printf("%d\n",cow);
if(cow == 2){
for(int i = 0;i<2;i++){
for(int j = 0;j<n;j++){
printf("%c",c);
}
printf("\n");
}
return 0;
}
for(int i = 0;i<n;i++){
printf("%c",c);
}
printf("\n");
for(int i = 0;i<cow-2;i++){
for(int j = 0;j<n;j++){
if(j == 0) printf("%c",c);
else if(j == n-1) printf("%c",c);
else printf(" ");
}
printf("\n");
}
for(int i = 0;i<n;i++){
printf("%c",c);
}
printf("\n");
return 0;
}
B1041
/*
pat b1041
time:2017/7/26 21:16
*/
#include<cstdio>
#include<cstring>
struct student{
char id[17];
int s;
int c;
}stu[1000];
int main(){
int n;
scanf("%d",&n);
for(int i = 0;i<n;i++){
char tmp[17];
int s1,c1;
//getchar();
scanf("%s%d%d",tmp,&s1,&c1);
//printf("%s\n",tmp);
strcpy(stu[i].id,tmp);
//printf("%s\n",stu[i].id);
stu[i].s = s1;
stu[i].c = c1;
}
int m;
scanf("%d",&m);
for(int i = 0;i<m;i++){
int t;
scanf("%d",&t);
for(int i = 0;i<n;i++){
if(stu[i].s == t){
printf("%s %d\n",stu[i].id,stu[i].c);
}
}
}
return 0;
}
PAT (Advanced Level) Practice
A1006
/*
pat b1012
time:2017/7/17 19:53
*/
#include<cstdio>
#include<cstring>
int charge(int h,int m,int s){
return h*10000+m*100+s;
}
int main(){
int n;
scanf("%d",&n);
char name[16];
int h1,m1,s1;
int h2,m2,s2;
int min=250000;
char minname[16];
int max=-1;
char maxname[16];
for(int i = 0;i<n;i++){
scanf("%s %d:%d:%d %d:%d:%d",name,&h1,&m1,&s1,&h2,&m2,&s2);
int start = charge(h1,m1,s1);
int end = charge(h2,m2,s2);
if(start<min){
min = start;
strcpy(minname,name);
}
if(end>max){
max = end;
strcpy(maxname,name);
}
}
printf("%s %s\n",minname,maxname);
return 0;
}
A1009
/*
pat a1002
time:2017/7/26 2019/7/26
*/
#include<cstdio>
int main(){
double a[1000+ 10]= {0};
double b[1000+10] = {0};
int k;
scanf("%d",&k);
for(int j = 0;j<k;j++){
int e;
double c;
scanf("%d%lf",&e,&c);
a[e] = c;
}
scanf("%d",&k);
for(int j = 0;j<k;j++){
int e;
double c;
scanf("%d%lf",&e,&c);
b[e] = c;
}
int count = 0;
for(int i = 1000;i>=0;i--){
a[i]+=b[i];
if(a[i]!=0){
count++;
}
}
if(count != 0)
printf("%d ",count);
else {
printf("0\n");
return 0;
}
for(int i = 1000;i>=0;i--){
if(a[i]!= 0){
printf("%d %.1f",i,a[i]);
count--;
if(count != 0){
printf(" ");
}
}
}
return 0;
}
A1011
/*
pat a1011
time:2017/7/17 19:53
*/
#include<cstdio>
int main(){
char s[]={'W','T','L'};
double ans = 1;
for(int i = 0;i<3;i++){
double tmp = 0.0;
int index = 0;
for(int j = 0;j<3;j++){
double a;
scanf("%lf",&a);
if(a>tmp){
tmp = a;
index = j;
}
}
ans *= tmp;
printf("%c ",s[index]);
}
printf("%.2f\n",(ans*0.65-1)*2);
return 0;
}
A1036
/*
pat a1036
time:2017/7/17 20:55
*/
#include<cstdio>
#include<cstring>
int main(){
int min = 101,flagm=-1;
int max = -1,flagf=-1;
char namem[11],idm[11];
char namef[11],idf[11];
int n;
scanf("%d",&n);
char name[11],id[11],c;
int score;
for(int i = 0;i<n;i++){
scanf("%s %c %s %d",name,&c,id,&score);
if(c-'M' == 0){
flagm = 1;
if(score<min){
min = score;
strcpy(namem,name);
strcpy(idm,id);
}
}else{
flagf = 1;
if(score>max){
max = score;
strcpy(namef,name);
strcpy(idf,id);
}
}
}
if(flagf == -1){
printf("Absent\n");
}else{
printf("%s %s\n",namef,idf);
}
if(flagm == -1){
printf("Absent\n");
}else{
printf("%s %s\n",namem,idm);
}
if(flagm == -1 || flagf == -1){
printf("NA\n");
}else{
printf("%d\n",max-min);
}
return 0;
}