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

概要

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

L1-065 嫑废话上代码 (5分)

#include<bits/stdc++.h>
using namespace std;
int main(){
	cout<<"Talk is cheap. Show me the code.";
	return 0;
}

L1-066 猫是液体 (5分)


#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
	cin>>a>>b>>c;
	cout<<a*b*c;
	return 0;
}

L1-067 洛希极限 (10分)

#include<bits/stdc++.h>
using namespace std;
int main(){
	float a, b, c; int d;
	cin>>a>>d>>b;
	if(d==0){
		c = a*2.455;
	}else{
		c = a*1.26;
	}
	printf("%.2f ",c);
	if(c<b)cout<<"^_^";
	else cout<<"T_T";
	return 0;
}

L1-068 调和平均 (10分)

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;  cin>>n;
	float ans;
	for(int i = 1; i <= n; i++){
		float x;  cin>>x; 
		ans += 1.0/x;
	}
	ans /= n;
	ans = 1.0/ans;
	printf("%.2f",ans);
	return 0;
}


L1-069 胎压监测 (15分)

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[10], bj, yz;
	int mx=-1;
	for(int i=1;i<=4;i++){cin>>a[i];mx=max(mx,a[i]);}
	cin>>bj>>yz;
	
	int ok = 1, lq;
	for(int i = 1; i <= 4; i++){
		if(mx-a[i]>yz || a[i]<bj){
			if(ok==1)ok=0;
			else ok = 2;
			lq = i;
		}
	}
	if(ok==1)cout<<"Normal\n";
	else if(ok==0)cout<<"Warning: please check #"<<lq<<"!\n";
	else cout<<"Warning: please check all the tires!\n";
	
	return 0;
}


L1-070 吃火锅 (15分)

#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int n=0, fs=0, cnt=0;
	while(getline(cin,s)){
		if(s==".")break;
		n++;
		if(s.find("chi1 huo3 guo1")!=string::npos){
			if(cnt==0)fs=n;
			cnt++;
		}
	}
	cout<<n<<"\n";
	if(cnt!=0)cout<<fs<<" "<<cnt<<endl;
	else cout<<"-_-#\n";
	return 0;
}


L1-071 前世档案 (20分)

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, m;  cin>>n>>m;
	for(int i = 1; i <= m; i++){
		string s;  cin>>s;
		int p = 0;
		for(int j = 0; j < s.size(); j++){
			if(s[j]=='y')p = p<<1;
			else p = p<<1|1;
		}
		cout<<p+1<<"\n";
	}
	return 0;
}


L1-072 刮刮彩票 (20分)

#include<bits/stdc++.h>
using namespace std;

int a[10][10], b[10], bx,by,bz;
int num[] = {0,1,2,3,4,5,10000,36,720,360,80,252,108,72,54,180,72,180,119,36,306,1080,144,1800,3600};
int main(){
	for(int i = 1; i <= 3; i++){
		for(int j = 1; j <= 3; j++){
			cin>>a[i][j];
			b[a[i][j]]++;
			if(a[i][j]==0){
				bx = i; by = j;
			}
		}
	}
	for(int i = 1; i <= 9; i++)
		if(b[i]==0)bz=i;
	a[bx][by]=bz;
	for(int i = 1; i <= 3; i++){
		int x, y;  cin>>x>>y;
		cout<<a[x][y]<<"\n";
	}
	int fx;  cin>>fx;
	int ans = 0;
	for(int i = 1; i <= 3; i++){
		if(fx<=3)ans += a[fx][i];
		else if(fx<=6)ans += a[i][fx-3];//WA2
		else if(fx==7)ans += a[i][i];
		else ans += a[i][3-i+1];
		
	}
	cout<<num[ans];
	return 0;
}


已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页