PAT(乙级)2022年夏季考试

PAT(乙级)2022年夏季考试题解

7-1 又是一道 A+B

15分

原题

在这里插入图片描述

算法标签

模拟 哈希

代码

#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 10005;
int f[N][N];
int a[N], b[N]; 
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>=10) put(x/10);
    putchar(x%10^48);
}
unordered_map<string, int> ump={
    {"1011111", 0}, 
    {"0000011", 1}, 
    {"1110110", 2},
    {"1110011", 3},
    {"0101011", 4},
    {"1111001", 5},
    {"1111101", 6},
    {"1000011", 7},
    {"1111111", 8},
    {"1111011", 9},
};
vector<string> get(string str){
    vector<string> res;
    string word;
    for (auto c: str){
        if (c == ' '){
            res.push_back(word);
            word = "";
        }
        else word += c;
    }
    res.push_back(word);
    return res;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s, s1;
	getline(cin, s);
	getline(cin, s1);
	vector<string> get00=get(s);
	vector<string> get10=get(s1);
	int a=0, b=0;
	rep(i, 0, get00.size()){
	    a=a*10+ump[get00[i]];
	}
	rep(i, 0, get10.size()){
	    b=b*10+ump[get10[i]];
	}
	printf("%lld", (a+b));
	return 0;
}

7-2 健身达人

分数 20

原题

在这里插入图片描述
在这里插入图片描述

算法标签

模拟 STL

代码

#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 10005;
int f[N][N];
int a[N], b[N],c[N],d[N]; 
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>=10) put(x/10);
    putchar(x%10^48);
}
vector<vector<int>> vs;
vector<int> v;
vector<int> v1;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int n=read();
    rep(i, 0, n){
        rep(j, 0, 8){
            f[i][j]=read();
        }
    }
    // i列
    rep(i, 1, 8){
        int max=0;
        rep(j, 0, n){
            if(f[j][i]>max){
                max=f[j][i];
            }
        }
        rep(j, 0, n){
            if(f[j][i]==max&&max){
                v.push_back(f[j][0]);
            }
        }
        vs.push_back(v);
        v.erase(v.begin(), v.end());
    }
    int max1=0, max2=0;
    rep(i, 0, n){
        rep(j, 1, 8){
            if(f[i][j])d[i]++;
            c[i]+=f[i][j];
        }
        if(max1<c[i]&&d[i]>=3){
            max1=c[i];
        }
    }
    rep(i, 0, n){
        if(c[i]==max1&&d[i]>=3){
            v1.push_back(f[i][0]);
        }
    }
    int cnt=0;
    for(auto a:vs){
        printf("Star %lld\n", ++cnt);
        if(a.size())for(auto b:a){
            printf("%06lld\n", b);
        }else{
            printf("NONE\n");
        }
    }
    puts("Star of the week");
    for(auto a:v1){
        printf("%06lld\n", a);
    }
	return 0;
}

7-3 阶乘方程

分数 20

原题

在这里插入图片描述

算法标签

模拟 数学

代码

#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 10005;
int f[N][N];
int a[N], b[N],c[N],d[N]; 
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>=10) put(x/10);
    putchar(x%10^48);
}
int mul(int a,int b){
    int ans=1;
    rep(i, a+1, b+1){
        ans*=i;
        if(ans>0x3f3f3f3f){
            return -1;
        }
    }
    return ans;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n=read();
    while(n--){
        int a=read(), b=read(), c=read(), d=read();
        if(mul(c, d)==mul(a, b)&&mul(a, b)!=-1){
            puts("YES");
        }else{
            puts("NO");
        }
    }
	return 0;
}

7-4 今天是周几

分数 20

原题

在这里插入图片描述

算法标签

模拟 哈希

代码

#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 10005;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>=10) put(x/10);
    putchar(x%10^48);
}
int ff(int a,int b, int c, int d, int e, int f, int dd){
    int cnt=0;
    int x, y, z;
    if(dd==0){
        x=a;
        y=(a+1)%7;
        z=(a+2)%7;
    }
    else if(dd==1){
        x=(b-1+7)%7;
        y=b;
        z=(b+1)%7;
    }else if(dd==2){
        y=(c-1+7)%7;
        x=(c-2+7)%7;
        z=c;
    }
    if(d==x){
        cnt+=1;
    }if(e==y){
        cnt+=2;
    }if(f==z){
        cnt+=4;
    }
    return cnt;
}
unordered_map<int,string> ump={
    {0, "Sunday"}, 
    {1, "Monday"}, 
    {2, "Tuesday"},
    {3, "Wednesday"},
    {4, "Thursday"},
    {5, "Friday"},
    {6, "Saturday"},
};
unordered_map<int,string> um={
    {0, "yesterday"}, 
    {1, "today"}, 
    {2, "tomorrow"},
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a=read(),b=read(), c=read();
	int d=read(),e=read(), f=read();
	int t;
	rep(i, 0, 3){
	    int aa=ff(a, b, c, d, e, f, i);
	        if(aa==1){
	            int t=(d+1)%7;
	            cout<<ump[t]<<"\n";
	            cout<<um[i]<<"\n";
	            cout<<"yesterday"<<"\n";
                break;
	        }else if(aa==2){
	            int t=(e)%7;
	            cout<<ump[t]<<"\n";
	            cout<<um[i]<<"\n";
	            cout<<"today"<<"\n";
                break;
	        }else if(aa==4){
	            int t=(f-1+7)%7;
	            cout<<ump[t]<<"\n";
	            cout<<um[i]<<"\n";
	            cout<<"tomorrow"<<"\n";
                break;
	        }
	}
	return 0;
}

7-5 LRU缓存

分数 25

原题

在这里插入图片描述

算法标签

模拟

代码

#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 20005;
int st[N];
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>=10) put(x/10);
    putchar(x%10^48);
}
signed main(){
    int n=read(), m=read();
    vector<int> a(m + 1);
    vector<int> ans;
    rep(i, 1, m+1){
        a[i]=read();
    }
    int cnt = 0;
    for (int i = 1, j = 1; i <= m; ++i){
        if (st[a[i]] == 0)
            cnt += 1;
        st[a[i]] += 1;
        if (cnt > n){
            while (j < i){
                st[a[j]] -= 1;
                if (st[a[j]] == 0){
                    ans.push_back(a[j]);
                    j++;
                    cnt -= 1;
                    break;
                }
                j++;
            }
        }
    }
    rep(i, 0, ans.size()){
        cout << ans[i] << " "[i == ans.size() - 1];
    }
}

战绩

请添加图片描述

原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
在这里插入图片描述

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
PAT乙级1009题是一个关于字符串处理的题目。根据题目要求,我们需要将输入的字符串按照单词的逆序输出。根据提供的引用内容,我们可以看到有三种不同的解法。 引用\[1\]和引用\[2\]是两个相似的解法,使用了字符串处理函数strchr和strrchr来定位空格字符,并将字符串分割成单词。然后通过循环输出单词,最后输出剩余的最后一个单词。 引用\[3\]是另一种解法,使用了二维数组来存储每个单词。通过循环读取输入的字符串,直到遇到换行符为止。然后通过倒序循环输出每个单词。 根据题目要求,你可以选择其中一种解法来完成PAT乙级1009题。 #### 引用[.reference_title] - *1* [PAT考试乙级1009(C语言实现)](https://blog.csdn.net/JeffreyDDD/article/details/78395267)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [PAT乙级1009(C语言实现)](https://blog.csdn.net/weixin_62870950/article/details/124934829)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [PAT乙级测试题1009(C语言实现)](https://blog.csdn.net/weixin_45947840/article/details/105943475)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞滕人生TYF

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值