PTA团体程序设计天梯赛-练习集61-65题

L1-061 新胖子公式

根据钱江晚报官方微博的报导,最新的肥胖计算方法为:体重(kg) / 身高(m) 的平方。如果超过 25,你就是胖子。于是本题就请你编写程序自动判断一个人到底算不算胖子。

输入格式:

输入在一行中给出两个正数,依次为一个人的体重(以 kg 为单位)和身高(以 m 为单位),其间以空格分隔。其中体重不超过 1000 kg,身高不超过 3.0 m。

输出格式:

首先输出将该人的体重和身高代入肥胖公式的计算结果,保留小数点后 1 位。如果这个数值大于 25,就在第二行输出 PANG,否则输出 Hai Xing

输入样例 1:

100.1 1.74

输出样例 1:

33.1
PANG

输入样例 2:

65 1.70

输出样例 2:

22.5
Hai Xing
#include<cmath>
#include<iostream>

using namespace std;
//一个公式即可,注意数据类型
int main()
{
	float kg,hight;
	scanf("%f %f",&kg,&hight);
	float goal;
    goal=kg/(hight*hight);
	printf("%.1f\n",goal);
	if(goal>25)cout<<"PANG";
	else cout<<"Hai Xing";
	return 0;
}

L1-062 幸运彩票 

彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的彩票是不是幸运的。

输入格式:

输入在第一行中给出一个正整数 N(≤ 100)。随后 N 行,每行给出一张彩票的 6 位数字。

输出格式:

对每张彩票,如果它是幸运的,就在一行中输出 You are lucky!;否则输出 Wish you good luck.

输入样例:

2
233008
123456

输出样例:

You are lucky!
Wish you good luck.
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
//,sum1,sum2,
//数字求和的话,直接/10,%10,就可以提取每个数字了
int main()
{
	int n;
	cin>>n;
	while(n--){
		int m;//输入数字
		cin>>m;
		int sum1=0,sum2=0;
		for(int i=1;i<=3;i++){//计算后三位的求和
			sum1+=m%10;
			m/=10;
		}
		for(int i=1;i<=3;i++){//计算前三位的求和
			sum2+=m%10;
			m/=10;
		}
		if(sum1==sum2)cout<<"You are lucky!"<<endl;
		else cout<<"Wish you good luck."<<endl;
	}
	
	
	return 0;
}

 L1-063 吃鱼还是吃肉

国家给出了 8 岁男宝宝的标准身高为 130 厘米、标准体重为 27 公斤;8 岁女宝宝的标准身高为 129 厘米、标准体重为 25 公斤。

现在你要根据小宝宝的身高体重,给出补充营养的建议。

输入格式:

输入在第一行给出一个不超过 10 的正整数 N,随后 N 行,每行给出一位宝宝的身体数据:

性别 身高 体重

其中性别是 1 表示男生,0 表示女生。身高体重都是不超过 200 的正整数。

输出格式:

对于每一位宝宝,在一行中给出你的建议:

  • 如果太矮了,输出:duo chi yu!(多吃鱼);
  • 如果太瘦了,输出:duo chi rou!(多吃肉);
  • 如果正标准,输出:wan mei!(完美);
  • 如果太高了,输出:ni li hai!(你厉害);
  • 如果太胖了,输出:shao chi rou!(少吃肉)。

先评价身高,再评价体重。两句话之间要有 1 个空格。

输入样例:

4
0 130 23
1 129 27
1 130 30
0 128 27

输出样例:

ni li hai! duo chi rou!
duo chi yu! wan mei!
wan mei! shao chi rou!
duo chi yu! shao chi rou!
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
//一点点比较即可
int main()
{
	int n;
	cin>>n;
	while(n--){
		int sex,hight,kg;//输入性别。身高,体重
		cin>>sex>>hight>>kg;
		//两种情况男生和女生
		if(sex==1){
			//先分析身高
			if(hight>130)cout<<"ni li hai! ";
			else if(hight==130)cout<<"wan mei! ";
			else cout<<"duo chi yu! ";
			//再分析体重
			if(kg==27)cout<<"wan mei!"<<endl;
			else if(kg<27)cout<<"duo chi rou!"<<endl;
			else cout<<"shao chi rou!"<<endl;
		}
		if(sex==0){
			//先分析身高
			if(hight>129)cout<<"ni li hai! ";
			else if(hight==129)cout<<"wan mei! ";
			else cout<<"duo chi yu! ";
			//再分析体重
			if(kg==25)cout<<"wan mei!"<<endl;
			else if(kg<25)cout<<"duo chi rou!"<<endl;
			else cout<<"shao chi rou!"<<endl;
		}
	}
	
	return 0;
}



 L1-064 估值一亿的AI核心代码【这一题花了我几个小时,还是有点错误,就搜个答案先给你们吧】【不喜喜】

本题要求你实现一个稍微更值钱一点的 AI 英文问答程序,规则是:

  • 无论用户说什么,首先把对方说的话在一行中原样打印出来;
  • 消除原文中多余空格:把相邻单词间的多个空格换成 1 个空格,把行首尾的空格全部删掉,把标点符号前面的空格删掉;
  • 把原文中所有大写英文字母变成小写,除了 I
  • 把原文中所有独立的 can youcould you 对应地换成 I canI could—— 这里“独立”是指被空格或标点符号分隔开的单词;
  • 把原文中所有独立的 I 和 me 换成 you
  • 把原文中所有的问号 ? 换成惊叹号 !
  • 在一行中输出替换后的句子作为 AI 的回答。

输入格式:

输入首先在第一行给出不超过 10 的正整数 N,随后 N 行,每行给出一句不超过 1000 个字符的、以回车结尾的用户的对话,对话为非空字符串,仅包括字母、数字、空格、可见的半角标点符号。

输出格式:

按题面要求输出,每个 AI 的回答前要加上 AI: 和一个空格。

输入样例:

6
Hello ?
 Good to chat   with you
can   you speak Chinese?
Really?
Could you show me 5
What Is this prime? I,don 't know

输出样例:

Hello ?
AI: hello!
 Good to chat   with you
AI: good to chat with you
can   you speak Chinese?
AI: I can speak chinese!
Really?
AI: really!
Could you show me 5
AI: I could show you 5
What Is this prime? I,don 't know
AI: what Is this prime! you,don't know
#include<bits/stdc++.h>
using namespace std;
	string str; 
string s1="can you",s11="I can";
string s2="could you",s22="I could";
string s31="I",s32="me",s33="yoU";
 
//isletter函数用来判断当前字符是否为字母,1代表为字母 
int isletter(char ch){
	if(ch>='A'&&ch<='Z'||ch>='a'&&ch<='z') return 1;
	return 0;
}
int main(){ 
	int N;cin>>N;getchar();
	for(int i=0;i<N;++i){
		getline(cin,str); 
		cout<<str<<endl;
		str=" "+str;
		//大写转小写 并格式化语句 
		for(int i=0;i<str.length();++i){
			if(str[i]==' '&&!isletter(str[i+1])&&!isdigit(str[i+1])){
				 str.erase(i,1);
				 i--;
			}
			if(str[i]>='A'&&str[i]<='Z'&&str[i]!='I') str[i]+=32;
			if(str[i]=='?'){
				 str[i]='!';
			}
		}
		//独立的 I 换成 you 	string s31="I",s32="me",s33="you";
		for(int i=0;i<str.length();++i){
			i=str.find(s31,i);
			if(i==-1) break;
			if(!(isletter(str[i-1])||isletter(str[i+s31.length()]))){
				str.replace(i,s31.length(),s33);
			}
		}
	//	cout<<"str换前:"+str<<"---------"<<endl; 
		//独立的 me 换成 you 	string s31="I",s32="me",s33="you";
		for(int i=0;i<str.length();++i){
			i=str.find(s32,i);
			if(i==-1) break;
			if(!(isletter(str[i-1])||isletter(str[i+s32.length()]))){
				str.replace(i,s32.length(),s33);
			}
		}
	//	cout<<"str换后:"+str<<"---------"<<endl; 
		// can you 换成 I can  		string s1="can you",s11="I can";
		for(int i=0;i<str.length();++i){
			i=str.find(s1,i);
			if(i==-1) break;
			if(!(isletter(str[i-1])||isletter(str[i+s1.length()]))){
				str.replace(i,s1.length(),s11); 
			}
		}
		// could you 换成 I could  		string s2="could you",s22="I could";
		for(int i=0;i<str.length();++i){
			i=str.find(s2,i);
			if(i==-1) break;
			if(!(isletter(str[i-1])||isletter(str[i+s2.length()]))){
				str.replace(i,s2.length(),s22);
			}
		}
		for(int i=0;i<str.length();++i){
			if(str[i]=='U') str[i]='u';
		}
		if(str[0]!=' ') str=" "+str; 
		cout<<"AI:"+str+"\n";
	}
}

 L1-065 嫑废话上代码

Linux 之父 Linus Torvalds 的名言是:“Talk is cheap. Show me the code.”(嫑废话,上代码)。本题就请你直接在屏幕上输出这句话。

输入格式:

本题没有输入。

输出格式:

在一行中输出 Talk is cheap. Show me the code.

输入样例:

输出样例:

Talk is cheap. Show me the code.
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	
	
	printf("Talk is cheap. Show me the code.");
	return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值