PAT | 算法笔记 | 查找元素

A1006

//
// Created by 22385 on 2022/1/18.
//

//                  1006 Sign In and Sign Out

#include<stdio.h>
#include<string.h>


int main(){
    int n;
    scanf("%d",&n);

    char ID[20],openID[20],closeID[20];
    int time_in,time_out;

    int h,m,s;
    int max=-1,min=24*3600;

    for(int i=0;i<n;i++){
        scanf("%s",ID);
        scanf("%d:%d:%d",&h,&m,&s);
        time_in=h*3600+m*60+s;
        if(time_in<min){
            strcpy(openID,ID);
            min=time_in;
        }
        scanf("%d:%d:%d",&h,&m,&s);
        time_out=h*3600+m*60+s;
        if(time_out>max){
            strcpy(closeID,ID);
            max=time_out;
        }
    }

    printf("%s %s",openID,closeID);

    return 0;
}

A1011

//
// Created by 22385 on 2022/1/18.
//
#include<stdio.h>
double max(double a,double b,double c,char &tag);

int main(){
    int n=3;
    double result=1;
    char tag;
    double a,b,c;
    for(int i=0;i<n;i++){
        scanf("%lf %lf %lf",&a,&b,&c);
        result*=max(a,b,c,tag);
        printf("%c ",tag);
    }
    printf("%.2f",(result*0.65-1)*2);
    return 0;
}

double max(double a,double b,double c,char &tag){
    if(a>=b){
        if(a>=c){
            tag='W';
            return a;
        }else{
            tag='L';
            return c;
        }
    }else{
        if(b>=c){
            tag='T';
            return b;

        }else{
            tag='L';
            return c;
        }
    }
}

A1036

//
// Created by 22385 on 2022/1/18.
//

//                          1036 Boys vs Girls (25 分)

#include<stdio.h>
#include<string.h>

int main(){

    int n;
    scanf("%d",&n);
    char gender;
    char ID[15],gID[15]="",bID[15]="";
    char name[15],gname[15]="Absent",bname[15]= "Absent";
    int score,max_g=-1,min_b=101;
    int gflag=0,bflag=0;
    for(int i=0;i<n;i++){
        scanf("%s %c %s %d",name,&gender,ID,&score);
        if(gender=='F'){
            gflag=1;
            if(score>max_g){
                max_g=score;
                strcpy(gname,name);
                strcpy(gID,ID);
            }
        }else{
            bflag=1;
            if(score<min_b){
                min_b=score;
                strcpy(bname,name);
                strcpy(bID,ID);
            }
        }
    }
    if(gflag){
        printf("%s %s\n",gname,gID);
    }else{
        printf("Absent\n");
    }
    if(bflag){
        printf("%s %s\n",bname,bID);
    }else{
        printf("Absent\n");
    }
    if(gflag&&bflag){
        printf("%d",max_g-min_b);
    }else{
        printf("NA");
    }

    return 0;
}

B1004

//
// Created by 22385 on 2022/1/18.
//

#include<stdio.h>
#include <string.h>

typedef struct stuInfo{
    char name[11];
    char ID[11];
    int score;
};

int main(){
    int n;
    scanf("%d",&n);
    stuInfo stuList[n];
    for(int i=0;i<n;i++){
        scanf("%s %s %d",stuList[i].name,stuList[i].ID,&stuList[i].score);
    }
    int max_score=-1,max_id;
    int min_score=101,min_id;
    for(int i=0;i<n;i++){
        if(stuList[i].score>max_score){
            max_score=stuList[i].score;
            max_id=i;
        }
        if(stuList[i].score<min_score){
            min_score=stuList[i].score;
            min_id=i;
        }
    }
    printf("%s %s\n",stuList[max_id].name,stuList[max_id].ID);
    printf("%s %s",stuList[min_id].name,stuList[min_id].ID);
}

B1028

//
// Created by 22385 on 2022/1/18.
//

//题目告知:给出的日期合法但不一定合理,不合理的数据要被过滤

/*
    测试点3:
        所有人不合格,输出0且无空格
 */

#include<stdio.h>
#include<string.h>

typedef struct date{
    int y;
    int m;
    int d;
};

//判断日期
bool isMore(date a,date b);
bool isLess(date a,date b);
//结构体复制
void copy(date &a,date b);      //引用

int main(){
    int n;
    scanf("%d",&n);
    date MIN={1814,9,6};
    date MAX={2014,9,6};
    date max={1814,9,6},min={2014,9,6};
    int count=0;
    char max_name[10],min_name[10];
    for(int i=0;i<n;i++){
        date test;
        char name[10];
        scanf("%s %d/%d/%d",name,&test.y,&test.m,&test.d);
        if(!isMore(test,MAX)&&!isLess(test,MIN)){
            count++;
            if(isMore(test,max)){
                copy(max,test);
                strcpy(min_name,name);
            }
            if(isLess(test,min)){
                copy(min,test);
                strcpy(max_name,name);
            }
        }
    }
    if(count==0){
        printf("0");
    }else{
        printf("%d %s %s",count,max_name,min_name);
    }

    return 0;
}

bool isMore(date a,date b){
    if(a.y>b.y){
        return true;
    }else if(a.y==b.y && a.m>b.m){
        return true;
    }else if(a.y==b.y && a.m== b.m && a.d>b.d){
        return true;
    }
    return false;
}

bool isLess(date a,date b){
    if(a.y<b.y){
        return true;
    }else if(a.y==b.y && a.m<b.m){
        return true;
    }else if(a.y==b.y && a.m== b.m && a.d<b.d){
        return true;
    }
    return false;
}

void copy(date &a,date b){
    a.y=b.y;
    a.m=b.m;
    a.d=b.d;
}

B1032

//
// Created by 22385 on 2022/1/18.
//

//学校编号可能很大
/*
    最后一个测试点:段错误
    数组不够大
 */
#include<stdio.h>
const int MAX=100005;
int main(){
    int n;
    scanf("%d",&n);
    int info[MAX]={0};
    int id,score;
    for(int i=0;i<n;i++){
        scanf("%d %d",&id,&score);
        info[id]+=score;
    }
    int max=-1,max_id;
    for(int i=1;i<=MAX;i++){
        if(info[i]>max){
            max=info[i];
            max_id=i;
        }
    }
    printf("%d %d",max_id,max);
    return 0;
}

B1041

//
// Created by 22385 on 2022/1/18.
//

/*
    给出:准考证号 试机座位号 考试座位号
    用试机座位号查询准考证号和考试座位号
*/

#include<stdio.h>
#include <string.h>
typedef struct stuInfo{
    char ID[20];
    int site;
};

int main(){
    int n;
    scanf("%d",&n);
    stuInfo stuList[n];
    for(int i=0;i<n;i++){
        char id[20];
        int site,num;
        scanf("%s %d %d",id,&num,&site);
        strcpy(stuList[num-1].ID,id);
        stuList[num-1].site=site;
    }
    int test_num;
    scanf("%d",&test_num);
    int x;
    for(int i=0;i<test_num;i++){
        scanf("%d",&x);
        printf("%s %d\n",stuList[x-1].ID,stuList[x-1].site);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值