PAT甲级题

Posted liuxbo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT甲级题相关的知识,希望对你有一定的参考价值。

A 1001

#include<cstdio>
int main(){
    int a,b,res[10];
    long long sum;
    scanf("%d%d",&a,&b);
    sum=a+b;
    if(sum<0){
        sum=-sum;
        printf("-");
    }
    int i=0;
    if(sum==0) printf("0");
    while(sum>0){
        res[i++]=sum%10;
        sum=sum/10;
    }
    for(int j=i-1;j>=0;j--){
        printf("%d",res[j]);
        if(j%3==0&&j!=0) printf(",");
    }
    return 0;
}

A1002(多项式求和)

#include<cstdio>
#include<string.h>
const int maxn=1001;
int count1,count2;
double coe[maxn]={},a;
int number=0;
int main(){
    scanf("%d",&count1);
    while(count1--){
        int i;
        scanf("%d%lf",&i,&a);
        coe[i]=coe[i]+a;
    }
    scanf("%d",&count2);
    while(count2--){
        int k;
        scanf("%d%lf",&k,&a);
        coe[k]=coe[k]+a;
    }
    for(int k=maxn-1;k>=0;k--){
        if(coe[k]!=0){
            number++;
        }
    }
    printf("%d",number);
    for(int k=maxn-1;k>=0;k--){
        if(coe[k]!=0) printf(" %d %.1f",k,coe[k]);
    }
    return 0;
} 

A1005

#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main(){
    int res[3],sum[110],i,result=0;
    char number[110];
    string english[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    scanf("%s",number);
    int len=strlen(number);
    for(i=0;i<len;i++){
        sum[i]=number[i]-'0';
        result+=sum[i];
    }
    int j=0;
    if(result==0) printf("zero");
    while(result){
        res[j++]=result%10;
        result/=10;
    }
    for(int x=j-1;x>=0;x--){
        printf("%s",english[res[x]].c_str());
        if(x!=0) printf(" ");
    }
    return 0;
}

A1006

#include<cstdio> 

struct person {
    char id[16];
    int hh, mm, ss;
}temp,first,last;
bool great(person node1, person node2) {
    if (node1.hh != node2.hh) return node1.hh > node2.hh;
    if (node2.mm != node2.mm) return node1.mm > node2.mm;
    return node1.ss > node2.ss;
}
int main() {
    int n;
    scanf("%d", &n);
    first.hh = 24, first.mm = 60, first.ss = 60;
    last.hh = 0, last.mm = 0, last.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, first) == false)  first = temp;
        scanf("%d:%d:%d", &temp.hh, &temp.mm, &temp.ss);
        if (great(temp, last))   last = temp;
    }
    printf("%s %s", first.id, last.id);
    return 0;
}

A1009 多项式相乘

#include<cstdio>
#include<string.h>
const int maxn=2001;
int count1,count2;
struct poly{
    int exp;
    double coef;
}coe[1001];
double result[maxn];
int number=0;
int main(){
    scanf("%d",&count1);
for(int i =0;i<count1;i++){
    scanf("%d%lf",&coe[i].exp,&coe[i].coef);
    }
    scanf("%d",&count2);
for(int i=0;i<count2;i++){
    int k;
    double a;
        scanf("%d%lf",&k,&a);
        for(int i=0;i<count1;i++){
            result[k+coe[i].exp]+=(a*coe[i].coef);
        }
    }
    for(int k=maxn-1;k>=0;k--){
        if(result[k]!=0){
            number++;
        }
    }
    printf("%d",number);
    for(int k=maxn-1;k>=0;k--){
        if(result[k]!=0) printf(" %d %.1f",k,result[k]);
    }
    return 0;
} 

A1011

#include<cstdio> 
char s[4] = "WTL";
double a,res=1;
int main() {
    for (int i = 0; i < 3; i++) {
        int imax;
        double temp = 0;
        for (int i = 0; i < 3; i++) {
            scanf_s("%lf", &a);
            if (a > temp) {
                temp = a;
                imax = i;
            }
        }
        res *= temp;
        printf("%c ", s[imax]);
    }
    printf("%.2f", (res * 0.65 - 1) * 2);
    return 0;
}

A1012

#include<cstdio>
#include<algorithm>
using namespace std;
struct node {
    int id;
    int grade[4];
}stu[2100];
int now;
bool cmp(node a, node b) {return a.grade[now] > b.grade[now];}
int rank_stu[1000000][4] = { 0 };
char course[4] = { 'A','C','M','E' };
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d%d", &stu[i].id, &stu[i].grade[1], &stu[i].grade[2], &stu[i].grade[3]);
        stu[i].grade[0] = stu[i].grade[1] + stu[i].grade[2] + stu[i].grade[3];
    }
    for (now = 0; now < 4; now++) {
        sort(stu, stu + n, cmp);
        rank_stu[stu[0].id][now] = 1;
        for (int i = 1; i < n; i++) {
            if (stu[i].grade[now] == stu[i - 1].grade[now]) rank_stu[stu[i].id][now] = rank_stu[stu[i - 1].id][now];
            else rank_stu[stu[i].id][now] = i+1;
        }
    }
    int query;
    for (int i = 0; i < m; i++) {
        scanf("%d", &query);
        if (rank_stu[query][0] == 0) printf("N/A
");
        else {
            int best=0;
            for (int j = 0; j < 4; j++) {
                if (rank_stu[query][j] < rank_stu[query][best])
                    best = j;
            }
            printf("%d %c
", rank_stu[query][best], course[best]);
        }
    }
    return 0;
}

A1016

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1010;
int toll[24];
struct Record {
    char name[21];
    int mon, dd, hh, mm;
    bool status;
}rec[maxn],temp;
bool cmp(Record a, Record b) {
    if (strcmp(a.name, b.name) != 0) return strcmp(a.name, b.name) < 0;
    else if (a.mon != b.mon) return a.mon < b.mon;
    else if (a.dd != b.dd) return a.dd < b.dd;
    else if (a.hh != b.hh) return a.hh < b.hh;
    else return a.mm < b.mm;
}
void get_ans(int on, int off, int& time, int& money) {
    temp = rec[on];
    while (temp.dd < rec[off].dd || temp.hh < rec[off].hh || temp.mm < rec[off].mm) {
        time++;
        money += toll[temp.hh];
        temp.mm++;
        if (temp.mm >= 60) {
            temp.mm = 0;
            temp.hh++;
        }
        if (temp.hh >= 24) {
            temp.hh = 0;
            temp.dd++;
        }
    }
}
int main() {
    char line_status[10];
    int n;
    for (int i = 0; i < 24; i++) scanf("%d", &toll[i]);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s %d:%d:%d:%d %s", rec[i].name, &rec[i].mon, &rec[i].dd, &rec[i].hh, &rec[i].mm,line_status);
        if (strcmp(line_status, "on-line") == 0) rec[i].status = true;
        if (strcmp(line_status, "off-line") == 0) rec[i].status = false;
    }
    sort(rec, rec + n, cmp);
    int on = 0, off, next;
    while (on < n) {//每次处理一个用户的所有记录
        int needprint = 0;
        next = on;
        while (next < n && strcmp(rec[next].name, rec[on].name) == 0) {//判断是否有配对项
            if (rec[next].status == true && needprint == 0) needprint = 1;
            else if (rec[next].status == false && needprint == 1) needprint = 2;
            next++;
        }
        if (needprint < 2) {
            on = next;
            continue;
        }
        int allmoney = 0;
        printf("%s %02d
", rec[on].name, rec[on].mon);
        while (on < next) {
            while (on < next - 1 && !(rec[on].status == true && rec[on + 1].status == false)) on++;
            off = on + 1;
            if (off == next) {
                on = next;
                break;
            }
            int time = 0;
            int  money = 0;
            get_ans(on, off, time, money);
            allmoney += money;
            printf("%02d:%02d:%02d ", rec[on].dd, rec[on].hh, rec[on].mm);
            printf("%02d:%02d:%02d ", rec[off].dd, rec[off].hh, rec[off].mm);
            printf("%d $%.2f
", time, money / 100.0);
            on=off+1;
        }
        printf("Total amount:$%.2f
", double(allmoney) / 100);
    }
    return 0;
}

A1019

#include<cstdio>
#include<vector>
using namespace std;
vector<int> a,c;
void change(int n,int b){
    if(n>0){
        int i=0;
        change(n/b,b);
        a.push_back(n%b);
    }
    else return;
}
bool judge(vector<int> a,vector<int> b){
    for(int i=0;i<a.size();i++){
        if (a[i]==b[i]) continue;
        else return false;
    }
    return true;
}
int main(){
    int n,b;
    scanf("%d %d",&n,&b);
    change(n,b);
    for(int i=0;i<a.size();i++){
        c.push_back(a[i]);
    }
    for (int min = 0, max = a.size()-1; min <= max; min++, max--) {
        int temp = a[min];
        a[min] = a[max];
        a[max] = temp;
    }
    if(judge(a,c)==true){
        printf("Yes
");
        for(int i=0;i<c.size();i++){
            printf("%d",c[i]);
            if(i!=c.size()-1) printf(" ");
        }
    }
    if(judge(a,c)==false) {
        printf("No
");
        for(int i=0;i<c.size();i++){
            printf("%d",c[i]);
            if(i!=c.size()-1) printf(" ");
        }
    }
    return 0;
}

A1025

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct student{
    char id[15];
    int grade;
    int lrank,frank;
    int local_num;
}testee[30010];
bool cmp1(student a,student b){ 
     return a.grade>b.grade;
}
bool cmp2(student a,student b){
    if(a.frank!=b.frank) return a.frank<b.frank;
    else if(strcmp(a.id,b.id)!=0) return strcmp(a.id,b.id)<0;
}
int main(){
    int n;
    int total=0;
    int localnum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int temp;
        localnum++;
        int on,off;
        on=total;
        off=on;
        scanf("%d",&temp);
        for(int j=0;j<temp;j++){
            scanf("%s%d",testee[total].id,&testee[total].grade);
            testee[total].local_num=localnum;
            total++;
            off++;
        }
        sort(testee+on,testee+off,cmp1);
        testee[on].lrank=1;
        for(int k=on+1;k<off;k++){
            if(testee[k].grade==testee[k-1].grade) testee[k].lrank=testee[k-1].lrank;
            else testee[k].lrank=k-on+1;
        }
    }
    sort(testee,testee+total,cmp1);
    testee[0].frank=1;
    for(int k=1;k<total;k++){
        if(testee[k].grade==testee[k-1].grade) testee[k].frank=testee[k-1].frank;
        else testee[k].frank=k+1;
    }
    sort(testee,testee+total,cmp2);
    printf("%d
",total);
    for(int i=0;i<total;i++){
        printf("%s %d %d %d
",testee[i].id,testee[i].frank,testee[i].local_num,testee[i].lrank);
    }
    return 0;
}

A1027

#include<cstdio>
int a[2],b[2],c[2];
    void change(int x,int a[]){
        if(x==0) {
            a[0]=0;
            a[1]=0;
        }
        else{
            a[0]=x%13;
            if((x/13)==0) a[1]=0;
            else a[1]=(x/13)%13;
        }
    }
int main(){
    int red,green,blue;
    scanf("%d %d %d",&red,&green,&blue);
    char str[15]={'0','1','2','3','4','5','6','7','8','9','A','B','C'};
    change(red,a);
    printf("#%c%c",str[a[1]],str[a[0]]);
    change(green,b);
    printf("%c%c",str[b[1]],str[b[0]]);
    change(blue,c);
    printf("%c%c",str[c[1]],str[c[0]]);
    return 0;
} 

A1028

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100010;
struct node {
    char id[10];
    char name[10];
    int grade;
}student[100010];
int c;
bool cmp(node a, node b) {
    if (c == 1) return strcmp(a.id, b.id) < 0;
    if (c == 2) {
        if (strcmp(a.name, b.name) != 0) return strcmp(a.name, b.name) < 0;
        else return strcmp(a.id, b.id) < 0;
    }
    if (c == 3) {
        if (a.grade != b.grade) return a.grade < b.grade;
        else return strcmp(a.id, b.id) < 0;
    }
}
int main() {
        int n;
        scanf("%d", &n);
        scanf("%d", &c);
        for (int i = 0; i < n; i++) scanf("%s%s%d", student[i].id, student[i].name, &student[i].grade);
        sort(student, student + n, cmp);
        for (int i = 0; i < n; i++) printf("%s%s%d
", student[i].id, student[i].name, student[i].grade);
        return 0;
}

A1031

#include<cstdio> 
#include<cstring>
int main() {
    char str[100], uu[40][40];
    scanf("%s",str); 
    int N = strlen(str);
    int n1=(N+2)/3;
    int n3=(N+2)/3;
    int n2=N-n1-n3+2;
    int pos=0;
    memset(uu,' ',sizeof(uu));
    for(int i=0;i<n1-1;i++){
        uu[i][0]=str[pos++];
    } 
    for(int j=0;j<n2;j++){
        uu[n1-1][j]=str[pos++];
    }
    for(int k=n3-2;k>=0;k--){
        uu[k][n2-1]=str[pos++];
    }
    for(int i=0;i<n1;i++){
        for(int j=0;j<n2;j++){
            printf("%c",uu[i][j]);
        }
        printf("
");
    }
    return 0;
}

A1036

#include<cstdio> 
#include<algorithm>
using namespace std;
struct student {
    char name[11];
    char gender;
    char id[11];
    int score;
}male,female,temp;
int main() {
    int n;
    scanf("%d", &n);
    female.score = -1;
    male.score = 101;
    for (int i = 0; i < n; i++) {
        scanf("%s %c %s %d", temp.name, &temp.gender, temp.id, &temp.score);
        if (temp.gender == 'F') {
            if (temp.score > female.score) {
                female = temp;
            }
        }
        if (temp.gender == 'M') {
            if (temp.score < male.score) {
                male = temp;
            }
        }
    }
    if (female.score == -1) printf("Absent
");
    if (female.score > -1) printf("%s %s
", female.name, female.id);
    if (male.score == 101) printf("Absent
");
    if (male.score <101) printf("%s %s
", male.name, male.id);
    if (female.score == -1 || male.score == 101) printf("NA");
    if (female.score > -1 && male.score < 101) printf("%d", female.score - male.score);
    return 0;
}

A1039

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 26 * 26 * 26 * 10 + 10;
vector<int> stu[maxn];
int getid(char name[]) {
    int id=0;
    for (int i = 0; i < 3; i++) 
        id = id * 26 + (name[i] - 'A');
    id = id * 10 + (name[3] - '0');
    return id;
}
int main() {
    int n, k, no, num;
    char name[5];
    scanf("%d%d", &n, &k);
    for (int i = 0; i < k; i++) {
        scanf("%d%d", &no, &num);
        for (int j = 0; j < num; j++) {
            scanf("%s", name);
            stu[getid(name)].push_back(no);
        }
    }
    for (int i = 0; i < n; i++) {
        scanf("%s", name);
        printf("%s ", name);
        printf("%d", stu[getid(name)].size());
        sort(stu[getid(name)].begin(), stu[getid(name)].end());
        for (int j = 0; j < stu[getid(name)].size(); j++) {
            printf(" %d", stu[getid(name)][j]);
        }
        printf("
");
    }
    return 0;
}

A1042

#include<cstdio>
const int N = 55;
int main()
{
    char mp[5] = { 'S','H','C','D','J' };
    int start[N], next[N], end[N];
    int times;
    scanf("%d", &times);
    for (int i = 1; i <= 54; i++) {
        scanf("%d", &next[i]);
    }
    for (int i = 1; i <= 54; i++) {
        start[i] = i;
    }
    for (int step = 0; step < times; step++) {
        for (int i = 1; i <= 54; i++) {
            end[next[i]] = start[i];
        }
        for (int i = 1; i <= 54; i++) {
            start[i] = end[i];
        }
    }
    for (int i = 1; i <= 54; i++) {
        if (i != 1) printf(" ");
        start[i]--;
        printf("%c%d", mp[start[i] / 13], start[i] % 13+1);
    }
    return 0;
}

A1046

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 100010;
int dis[maxn], A[maxn];
int main() {
    int n,times,left,right,sum=0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &A[i]);
        sum += A[i];
        dis[i] = sum;
    }
    scanf("%d", &times);
    for (int i = 0; i < times; i++) {
        scanf("%d%d", &left, &right);
        if (left > right)  swap(left, right);
        int distance = dis[right - 1] - dis[left - 1];
            printf("%d
", min(distance,sum-distance));
    }
    return 0;
}

A1047

#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
vector<int> course[2510];
char stu[40010][5];
bool cmp(int a, int  b) {  return strcmp(stu[a], stu[b]) < 0; }
int main() {
    int n,k,m;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%s", stu[i]);
        scanf("%d", &m);
        for (int j = 0; j < m; j++) {
            int id;
            scanf("%d",&id);
            course[id].push_back(i);
        }   
    }
    for (int i = 1; i <= k; i++) {
        printf("%d %d
", i, course[i].size());
        sort(course[i].begin(), course[i].end(), cmp);
        for (int j = 0; j < course[i].size(); j++) {
            printf("%s
", stu[course[i][j]]);
        }
    }
    return 0;
}

A1051 栈

#include<cstdio>
#include<stack>
using namespace std;
const int maxn = 1010;
int out[maxn];
stack<int> st;
int main() {
    int m, n, k;
    scanf("%d%d%d", &m, &n, &k);
    while (k--) {
        while (!st.empty()) {
            st.pop();
        }
        bool flag=true;
        for (int i = 1; i <= n; i++) {
            scanf("%d", &out[i]);
        }
        int current = 1;
        for (int i = 1; i <= n; i++) {
            st.push(i);
            if (st.size() > m) {
                flag = false;
                break;
            }
            while(!st.empty()&&st.top() == out[current]) {
                    st.pop();
                    current++;
            }
        }
        if (st.empty()&& flag == true) printf("YES
");
        else printf("NO
");
    }
    return 0;
}

A1055

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
struct node{
    char name[10];
    int age,money;
}; 
bool cmp(node a,node b){
    if(a.money!=b.money) return a.money>b.money;
    else if(a.age!=b.age) return a.age<b.age;
    else return strcmp(a.name,b.name)<0;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    vector<node> total(n),elect;
    vector<int> mark(210,0);
    for(int i=0;i<n;i++) scanf("%s%d%d",total[i].name,&total[i].age,&total[i].money);
    sort(total.begin(),total.end(),cmp);
    for(int i=0;i<n;i++){
        if(mark[total[i].age]<=100){
            mark[total[i].age]++;
            elect.push_back(total[i]);
        }
    }
    int query,minage,maxage;
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&query,&minage,&maxage);
        vector<node> t;
        for(int j=0;j<elect.size();j++){
            if(elect[j].age<=maxage&&elect[j].age>=minage)
                t.push_back(elect[j]);
        }
        printf("Case #%d:
",i+1);
        int needprintf=0;
        for(int k=0;k<query&&k<t.size();k++){
            needprintf++;
            printf("%s %d %d
",t[k].name,t[k].age,t[k].money);
        }
        if(needprintf==0) printf("None
");
    } 
    return 0;
}

A1056(队列)

#include<queue>
#include<cstdio>
using namespace std;
const int maxn = 1010;
struct node{
    int rank;
    int weight;
}mouse[maxn];
int main() {
    queue<int> q;
    int np, ng, order;
    scanf("%d%d", &np, &ng);
    for (int i = 0; i < np; i++) {
        scanf("%d", &mouse[i].weight);
    }
    int t=np;
    while(t--){
        scanf("%d", &order);
        q.push(order);
    }
    int temp = np, group;
    while (q.size() != 1) {
        if (temp % ng == 0) group = temp / ng;
        else group = temp / ng + 1;
        for (int i = 0; i < group; i++) {
            int k = q.front();
            for (int j = 0; j < ng; j++) {
                if (i * ng + j >= temp) break;
                int front = q.front();
                if (mouse[front].weight > mouse[k].weight) {
                    k = front;
                }
                mouse[front].rank = group + 1;
                q.pop();
            }
            q.push(k);
        }
        temp = group;
    }
    mouse[q.front()].rank = 1;
    for (int i = 0; i < np; i++) {
        printf("%d", mouse[i].rank);
        if (i < np - 1) printf(" ");
    }
    return 0;
}

A1058

#include<cstdio>
int main() {
    int sum[3], m1[3], m2[3];
    int  temp_sick, temp_knut;
    scanf("%d.%d.%d", &m1[0], &m1[1], &m1[2]);
    scanf("%d.%d.%d", &m2[0], &m2[1], &m2[2]);
    sum[2] = (m1[2] + m2[2]) % 29;
    temp_knut = (m1[2] + m2[2])/ 29;
    sum[1] = (m1[1] + m2[1] + temp_knut)%17;
    temp_sick = (m1[1] + m2[1] + temp_knut) / 17;
    sum[0] = m1[0] + m2[0] + temp_sick;
    printf("%d.%d.%d", sum[0], sum[1], sum[2]);
    return 0;
}

A1060

#include<iostream> 
#include<string>
using namespace std;
int n;
string deal(string s, int& e) {
    int k = 0;
    
    while (s.length() > 0 && s[0] == '0') {
        s.erase(s.begin());
    }
    if (s[0] == '.') {
        s.erase(s.begin());
        while (s.length() > 0 && s[0] == '0') {
            s.erase(s.begin());
            e--;
        }
    }
    else {
        while (s.length() > k && s[k] != '.') {
            e++;
            k++;
        }
        if(k<s.length()) s.erase(s.begin() + k);
    }
    if (s.length() == 0) e = 0;
    string ans;
    k=0;
    int num=0;
    while(num<n){
        if(k<s.length()) ans+=s[k++];
        else ans+='0';
        num++;
    }
    return ans;
}
int main() {
    string s1, s2, ans1, ans2;
    int e1=0, e2=0;
    cin >> n >> s1 >> s2;
    ans1 = deal(s1, e1);
    ans2 = deal(s2, e2);
    if (ans1 == ans2 && e1 == e2)
        cout << "YES " << "0." << ans1 << "*10^" << e1;
    else
        cout << "NO " << "0." << ans1 << "*10^" << e1 << " " << "0." << ans2 << "*10^" << e2;
    return 0;
}

A1061

#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main() {
    char s1[70], s2[70], s3[70], s4[70];
    string days[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
    scanf("%s%s%s%s", s1, s2, s3, s4);
    int len1 = strlen(s1);
    int len2 = strlen(s2);
    int len3 = strlen(s3);
    int len4 = strlen(s4);
    int i;
    for (i = 0; i < len1 && i < len2; i++) {
        if (s1[i] == s2[i] && s1[i] >= 'A' && s1[i] <= 'G') {
            printf("%s ", days[s1[i] - 'A'].c_str());
            break;
        }
    }
    for (i++; i < len2 && i < len1; i++) {
        if (s1[i] == s2[i]) {
            if (s1[i] >= '0' && s1[i] <= '9') {
                printf("%02d:", s1[i] - '0');
                break;
            }
            else if (s1[i] >= 'A' && s1[i] <= 'N') {
                printf("%02d:", s1[i] - 'A' + 10);
                break;
            }
        }
    }
    for (int j = 0; j < len3 && j < len4; j++) {
        if (s3[j] == s4[j]) {
            if ((s3[j] >= 'a' && s3[j] <= 'z') || (s3[j] >= 'A' && s3[j] <= 'Z')) {
                printf("%02d", j);
                break;
            }
        }
    }
    return 0;
}

A1062

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct test {
    char id[20];
    int de, cai, sum;
    int flag;
}student[100010];
bool cmp(test a, test b) {
    if (a.flag != b.flag) return a.flag < b.flag;
    else if (a.sum != b.sum) return a.sum > b.sum;
    else if (a.de != b.de) return a.de > b.de;
    else return strcmp(a.id, b.id) < 0;
}
int main() {
    int total, low, high;
    scanf("%d%d%d", &total, &low, &high);
    int pass = total;
    for (int i = 0; i < total; i++) {
        scanf("%s%d%d", student[i].id, &student[i].de, &student[i].cai);
        student[i].sum = student[i].de + student[i].cai;
        if (student[i].de < low || student[i].cai < low) {
            student[i].flag = 5;
            pass--;
        }
        else if (student[i].cai >= high && student[i].de >= high) student[i].flag = 1;
        else if (student[i].cai >= low && student[i].cai < high && student[i].de >= high) student[i].flag = 2;
        else if (student[i].cai >= low && student[i].cai <= student[i].de && student[i].de<high) student[i].flag = 3;
        else  student[i].flag = 4;
    }
    sort(student, student + total, cmp);
    printf("%d
", pass);
    for (int i = 0; i < pass; i++) {
        printf("%s %d %d
", student[i].id, student[i].de, student[i].cai);
    }
    return 0;
}

A1063

#include<cstdio>
#include<set>
using namespace std;
const int maxn = 51;
set<int> v[maxn];
int main() {
    int n,m,temp,k;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &m);
        for (int j = 0; j < m; j++) {
            scanf("%d", &temp);
            v[i].insert(temp);
        }
    }
    int a, b;
    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
        scanf("%d%d", &a, &b);
        int nc=0, nt=v[b-1].size();
        for (auto it = v[a - 1].begin(); it != v[a - 1].end(); it++) {
            if (v[b - 1].find(*it) != v[b - 1].end())  nc++;
            else nt++;
        }
        printf("%.1f%%
", (nc * 100.0) / nt);
    }
}

A1065

#include<cstdio>
int main() {
    long long a, b, c;
    int n,times=1;
    scanf("%d", &n);
    while (n--) {
        scanf("%lld%lld%lld", &a, &b, &c);
        bool flag;
        long long sum = a + b;
        if (a > 0 && b > 0 && sum < 0)
            flag = true;
        else if (a < 0 && b < 0 && sum >= 0)
            flag = false;
        else if (sum > c)
            flag = true;
        else flag = false;
        if (flag == true)
            printf("Case #%d:true", times++);
        if (flag == false)
            printf("Case #%d:false", times++);
    }
    return 0;
}

A1069

#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
bool cmp(int a, int b) {
    return a > b;
}
int a[4];
int to_number(int a[]) {
    int res = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3] * 1;
    return res;
}
void to_arry(int num) {
    for (int j = 0; j < 4; j++) {
        a[j] = num % 10;
        num = num / 10;
    }
}
int main() {
    int big, small, ans;
    scanf("%d", &ans);
    do {
        to_arry(ans);
        sort(a, a + 4);
        small = to_number(a);
        sort(a, a + 4, cmp);
        big = to_number(a);
        ans = big - small;
        printf("%04d - %04d = %04d
", big, small, ans);
        
    } while (ans > 0 && ans != 6174);
    return 0;
}

A1073 科学计数法

#include<cstdio> 
#include<cstring>
int main(){
    char str[10010];
    scanf("%s",str);
    int len=strlen(str);
    int pos=0;
    while(str[pos]!='E') pos++;
    if(str[0]=='-') printf("-");
    int exp=0;
    for(int i=pos+2;i<len;i++){
        exp=exp*10+str[i]-'0';
    }
    if(exp==0){
        for(int i=1;i<pos;i++){
            printf("%c",str[i]);
        }
    }
    if(str[pos+1]=='-'){
        printf("0.");
        for(int t=0;t<exp-1;t++) printf("0");
        for(int j=1;j<pos;j++){
            if(str[j]=='.') continue;
            printf("%c",str[j]);
        }
    }
    else{
        for(int i=1;i<pos;i++){
            if(str[i]=='.') continue;
            printf("%c",str[i]);
            if(i==exp+2&&(pos-3)!=exp){
                printf(".");
            }
        }
        for(int k=0;k<exp-(pos-3);k++) printf("0");
    } 
    return 0;
}

A1100

#include<cstdio>
#include<iostream>
#include<map>
#include<string>
using namespace std;
string s1[13] = { "tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
string s2[13] = { "tret","tam", "hel", "maa", "huh", "tou", "kes","hei", "elo", "syy", "lok", "mer", "jou" };
map<string, int>strtonum;
int main() {
    int n;
    string str;
    scanf("%d%*c", &n);
    while (n--) {
        getline(cin, str);
        if (str[0] >= '0' && str[0] <= '9') {
            int number = stoi(str);
            if (number < 13) cout << s1[number]<<endl;
            else {
                int unit = number % 13;
                number /= 13;
                int tens = number % 13;
                if (unit == 0) cout << s2[tens] << endl;
                else cout << s2[tens] << " " << s1[unit] << endl;
            }   
        }
        else {
            for (int i = 0; i < 13; i++) {
                strtonum[s1[i]] = i;
            }
            for (int i = 1; i < 13;i++ ) {
                strtonum[s2[i]] = 13 * i;
            }
            for (int i = 1; i < 13; i++) {
                for (int j = 0; j < 13; j++) {
                    strtonum[s2[i] +" "+s1[j]] = i * 13 + j;
                }
            }
            cout << strtonum[str] << endl;
        }
    }
    return 0;
}

以上是关于PAT甲级题的主要内容,如果未能解决你的问题,请参考以下文章

PAT甲级--The Largest Generation

PAT甲级题

PAT甲级1067

PAT甲级1085

PAT甲级1031

PAT甲级1010