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

举报
小哈里 发表于 2022/05/11 00:53:39 2022/05/11
【摘要】 概要 L1一共8题,5分,10分,15分,20分各两题。 5分题一般会输入输出就行,10分题就是一个循环或者选择结构 15分题有简单的模拟和查找,20分题是稍微繁琐的简单模拟这样。 L1-0...

概要

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

文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。

原文链接:gwj1314.blog.csdn.net/article/details/116176691

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。