当前位置:网站首页>Pat (Grade B) 2022 summer exam
Pat (Grade B) 2022 summer exam
2022-07-06 06:12:00 【T_ Y_ F666】
PAT( Class B )2022 Summer examination questions in
7-1 It's another A+B
15 branch
The original title is
Algorithm tags
simulation Hash
Code
#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 Fitness gurus
fraction 20
The original title is
Algorithm tags
simulation STL
Code
#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 Column
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 Factorial equation
fraction 20
The original title is
Algorithm tags
simulation mathematics
Code
#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 What day of the week is today
fraction 20
The original title is
Algorithm tags
simulation Hash
Code
#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 cache
fraction 25
The original title is
Algorithm tags
simulation
Code
#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];
}
}
record
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support
边栏推荐
- 【C语言】qsort函数
- 曼哈顿距离与曼哈顿矩形-打印回字型矩阵
- nodejs实现微博第三方登录
- Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028
- SQLMAP使用教程(三)实战技巧二
- [Thesis code] SML part code reading
- [API interface tool] Introduction to postman interface
- Sqlmap tutorial (III) practical skills II
- [postman] test script writing and assertion details
- 如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
猜你喜欢
ContentType的作用
进程和线程的理解
Application du Groupe Li dans gtsam
功能安全之故障(fault),错误(error),失效(failure)
IPv6 comprehensive experiment
LeetCode 729. 我的日程安排表 I
Embedded point test of app
[ram IP] introduction and experiment of ram IP core
【Postman】Collections配置运行过程
Buuctf-[[gwctf 2019] I have a database (xiaoyute detailed explanation)
随机推荐
数字三角形模型 AcWing 1015. 摘花生
HCIA review
【Postman】Collections-运行配置之导入数据文件
LeetCode 739. 每日温度
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[postman] collections - run the imported data file of the configuration
selenium源码通读·9 |DesiredCapabilities类分析
Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
[paper reading] nflowjs: synthetic negative data intensive anomaly detection based on robust learning
异常检测方法总结
Bit operation rules
Manhattan distance sum - print diamond
假设检验学习笔记
[wechat applet] build a development tool environment
[ram IP] introduction and experiment of ram IP core
P问题、NP问题、NPC问题、NP-hard问题详解
How to use the container reflection method encapsulated by thinkphp5.1 in business code
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
(中)苹果有开源,但又怎样呢?