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\n");
        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\n", 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\n", 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\n", time, money / 100.0);
            on=off+1;
        }
        printf("Total amount:$%.2f\n", 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\n");
        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\n");
        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\n",total);
    for(int i=0;i<total;i++){
        printf("%s %d %d %d\n",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\n", 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("\n");
    }
    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\n");
    if (female.score > -1) printf("%s %s\n", female.name, female.id);
    if (male.score == 101) printf("Absent\n");
    if (male.score <101) printf("%s %s\n", 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("\n");
    }
    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\n", 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\n", i, course[i].size());
        sort(course[i].begin(), course[i].end(), cmp);
        for (int j = 0; j < course[i].size(); j++) {
            printf("%s\n", 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\n");
        else printf("NO\n");
    }
    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:\n",i+1);
        int needprintf=0;
        for(int k=0;k<query&&k<t.size();k++){
            needprintf++;
            printf("%s %d %d\n",t[k].name,t[k].age,t[k].money);
        }
        if(needprintf==0) printf("None\n");
    }
    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\n", pass);
    for (int i = 0; i < pass; i++) {
        printf("%s %d %d\n", 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%%\n", (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\n", 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;
}

原文地址:https://www.cnblogs.com/liuxbo/p/12401973.html

时间: 2024-07-30 21:01:59

PAT甲级题的相关文章

PAT甲级题分类汇编——线性

线性类,指线性时间复杂度可以完成的题.在1051到1100中,有7道: 题号 标题 分数 大意 时间 1054 The Dominant Color 20 寻找出现最多的数 200ms 1061 Dating 20 寻找字符串中相同字符 200ms 1071 Speech Patterns 25 寻找出现最多的单词 300ms 1077 Kuchiguse 20 字符串共同后缀 150ms 1082 Read Number in Chinese 25 中文读数 400ms 1084 Broken

PAT甲级题分类汇编——理论

理论这一类,是让我觉得特别尴尬的题,纯粹是为了考数据结构而考数据结构.看那Author一栏清一色的某老师,就知道教数据结构的老师的思路就是和别人不一样. 题号 标题 分数 大意 Author 1051 Pop Sequence 25 判断一个序列是否是pop序列 CHEN, Yue 1052 Linked List Sorting 25 链表排序 CHEN, Yue 1057 Stack 30 一个有中位数功能的stack CHEN, Yue 1074 Reversing Linked List

PAT甲级题分类汇编——杂项

集合.散列.数学.算法,这几类的题目都比较少,放到一起讲. 题号 标题 分数 大意 类型 1063 Set Similarity 25 集合相似度 集合 1067 Sort with Swap(0, i) 25 通过与0号元素交换来排序 数学 1068 Find More Coins 30 子集和问题 算法 1070 Mooncake 25 背包问题 算法 1078 Hashing 25 散列 散列 1085 Perfect Sequence 25 符合约束的最大数列长度 集合 1092 To

PAT甲级题分类汇编——计算

计算类,指以数学运算为主或为背景的题. 题号 标题 分数 大意 1058 A+B in Hogwarts 20 特殊进制加法 1059 Prime Factors 25 分解素因数 1060 Are They Equal 25 一定精度下两数是否相等 1065 A+B and C (64bit) 20 大数加法与比较 1069 The Black Hole of Numbers 20 黑洞数 1073 Scientific Notation 20 科学计数法还原 1081 Rational Su

PAT甲级题分类汇编——树

AVL树好难!(其实还好啦~) 我本来想着今天应该做不完树了,没想到电脑里有一份讲义,PPT和源代码都有,就一遍复习一遍抄码了一遍,更没想到的是编译一遍通过,再没想到的是运行也正常,最没想到的是一遍AC. 其实很多题都有数,std::set 之类用的是红黑树,据说很复杂,比AVL树还要复杂的那种.但是,用到这些设施的题,都不在这一分类下,这一分类下的题,因为题目要求自己建树,也就不用标准库设施了. 大多数题中,树在内存中都是连续存放的.不是像完全二叉树那样的连续,是物理上连续而逻辑上用数组下表代

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

PAT甲级考前整理

终于在考前,刷完PAT甲级130道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种境界.PAT甲级题目总的说卡题目的比较多,卡测试点的比较少,有些题目还会有题意混淆,这点就不吐槽了吧.静下心来耍这130道题,其实磨练的是一种态度与手感,养成的是一种习惯.热爱AC没有错!! 130道题目主要的考点: 1.排序:快速排序,直接插入排序,希尔排序,分治排序,堆排序. 2.图论:拓扑排序.最短路径.深度搜索.广度搜索. 3.树:树的遍历.完全二叉树.AVL. 4.其他:并查集,模拟,哈希.背包.

PAT甲级考试题库1001 A+B Format 代码实现及相关知识学习

准备参加九年九月份的PAT甲级证书考试,对网站上的题目进行总结分析: 1001题 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). 计算a+b的值并以一定格式输出其和sum(数字需要

【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全部出手的利润.输出最大利润. trick: 测试点2可能包含M不为整数的数据.(尽管题面说明M是正整数,可是根据从前PAT甲级题目的经验,有可能不是整数.....) 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using names