当前位置:   article > 正文

【2021团体程序设计天梯赛】L1部分(PTA,L1-073到L1-080)题解代码_pta l1-078

pta l1-078
概要

L1一共8题,5分,10分,15分,20分各两题。
5分题一般会输入输出就行,10分题就是一个循环或者选择结构
15分题有简单的模拟和查找,20分题是稍微繁琐的简单模拟这样。

L1-073 人与神 5 104 135 0.77
L1-074 两小时学完C语言 5 95 124 0.77
L1-075 强迫症 10 68 137 0.50
L1-076 降价提醒机器人 10 66 89 0.74
L1-077 大笨钟的心情 15 58 126 0.46
L1-078 吉老师的回归 15 68 190 0.36
L1-079 天梯赛的善良 20 69 188 0.37
L1-080 乘法口诀数列 20 71 165 0.43

L1-073 人与神 (5分)
#include<bits/stdc++.h>
using namespace std;
int main(){
	cout<<"To iterate is human, to recurse divine.\n";
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
L1-074 两小时学完C语言 (5分)
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, k, m;
	cin>>n>>k>>m;
	int x = n-k*m;
	if(x<0)x = 0;
	cout<<x<<"\n";
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
L1-075 强迫症 (10分)
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s.size()==4){
		int x = stoi(s.substr(0,2));
		if(x<22){
			cout<<20<<s.substr(0,2)<<"-"<<s.substr(2,2)<<"\n";
		}else{
			cout<<19<<s.substr(0,2)<<"-"<<s.substr(2,2)<<"\n";
		}
	}else{
		cout<<s.substr(0,4)<<"-"<<s.substr(4,2);
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
L1-076 降价提醒机器人 (10分)
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n; double m;  cin>>n>>m;
	for(int i = 1; i <= n; i++){
		double p;  cin>>p;
		if(p<m)printf("On Sale! %.1lf\n",p);
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
L1-077 大笨钟的心情(15分)
#include<bits/stdc++.h>
using namespace std;
int a[50];
int main(){
	for(int i = 0; i < 24; i++)
		cin>>a[i];
	int x; 
	while(cin>>x&&x>=0&&x<=23){
		if(a[x]>50)cout<<a[x]<<" Yes\n";
		else cout<<a[x]<<" No\n";
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
L1-078 吉老师的回归(15分)
#include<bits/stdc++.h>
using namespace std;
int a[50];
int main(){
	int n, m;
	cin>>n>>m; cin.get();
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		string s;  getline(cin,s);
		if(s.find("easy")==string::npos && s.find("qiandao")==string::npos){
			//cout<<"adsfkragnnlkm";
			cnt++;
			if(cnt==m+1){
				cout<<s<<"\n";
				return 0;
			}
		}
	}
	cout<<"Wo AK le\n";
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
L1-079 天梯赛的善良 (20分)
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e4+10;
int a[maxn];
int main(){
	int n;  cin>>n;
	int mx = -1, mi = 1e9+10;
	for(int i = 1; i <= n; i++){
		cin>>a[i]; 
		mx = max(mx, a[i]);
		mi = min(mi, a[i]);
	}
	int a1 = 0, a2 = 0;
	for(int i = 1; i <= n; i++){
		if(a[i]==mx)a1++;
		if(a[i]==mi)a2++;
	}
	cout<<mi<<" "<<a2<<"\n";
	cout<<mx<<" "<<a1<<"\n";
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
L1-080 乘法口诀数列 (20分)
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e4+10;
int a[maxn];
int main(){
	int n;
	cin>>a[1]>>a[2]>>n;
	int cur = 3;
	for(int i = 3; i <= n; i++){
		int x = a[i-1]*a[i-2];
		string s = to_string(x);
		for(int j = 0; j < s.size(); j++){
			a[cur++] = s[j]-'0';
		}
	}
	for(int i = 1; i <= n; i++){
		if(i!=n)cout<<a[i]<<" ";
		else cout<<a[i];
	}
		
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/232687
推荐阅读
相关标签
  

闽ICP备14008679号