团体程序设计天梯赛L1

时间:2024-03-27 14:24:40

L1-057 PTA使我精神焕发 (5 分)

2019团体程序设计天梯赛L1

以上是湖北经济学院同学的大作。本题就请你用汉语拼音输出这句话。

输入格式:
本题没有输入。
输出格式:
在一行中按照样例输出,以惊叹号结尾。

输入样例:

输出样例:

PTA shi3 wo3 jing1 shen2 huan4 fa1 !
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
using namespace std;



int main()
{
	cout << "PTA shi3 wo3 jing1 shen2 huan4 fa1 !" << endl;


	system("pause");
	return 0;
}

L1-058 6翻了 (15 分)

2019团体程序设计天梯赛L1

“666”是一种网络用语,大概是表示某人很厉害、我们很佩服的意思。最近又衍生出另一个数字“9”,意思是“6翻了”,实在太厉害的意思。如果你以为这就是厉害的最高境界,那就错啦 —— 目前的最高境界是数字“27”,因为这是 3 个 “9”!
本题就请你编写程序,将那些过时的、只会用一连串“6666……6”表达仰慕的句子,翻译成最新的高级表达。

输入格式:
输入在一行中给出一句话,即一个非空字符串,由不超过 1000 个英文字母、数字和空格组成,以回车结束。
输出格式:
从左到右扫描输入的句子:如果句子中有超过 3 个连续的 6,则将这串连续的 6 替换成 9;但如果有超过 9 个连续的6,则将这串连续的 6 替换成 27。其他内容不受影响,原样输出。

输入样例:

it is so 666 really 6666 what else can I say 6666666666 

输出样例:

it is so 666 really 9 what else can I say 27
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
using namespace std;



int main()
{
	string str;
	getline(cin, str);//pta不能用gets
	int i;
	for (i = 0; i < str.length(); i++)
	{
		int n = 0;//记录6的个数
		for (int j = i; str[j] == '6'; j++)//当不是6时结束记录
		{
			n++;
		}
		if (n > 9)//先排除9个以上的,这样3个以上不需要考虑是否大于9
		{
			cout << "27";
			i = i + n;//不再输出6
			i--;//抵消for里面的i--
			continue;
		}
		if (n > 3)
		{
			cout << "9";
			i = i + n;
			i--;
			continue;
		}
		cout << str[i];//正常输出
	}


	system("pause");
	return 0;
}

L1-059 敲笨钟 (20 分)

微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。为了增加敲钟的趣味性,还会糟改几句古诗词。其糟改的方法为:去网上搜寻压“ong”韵的古诗词,把句尾的三个字换成“敲笨钟”。例如唐代诗人李贺有名句曰:“寻章摘句老雕虫,晓月当帘挂玉弓”,其中“虫”(chong)和“弓”(gong)都压了“ong”韵。于是这句诗就被糟改为“寻章摘句老雕虫,晓月当帘敲笨钟”。
现在给你一大堆古诗词句,要求你写个程序自动将压“ong”韵的句子糟改成“敲笨钟”。

输入格式:
输入首先在第一行给出一个不超过 20 的正整数 N。随后 N 行,每行用汉语拼音给出一句古诗词,分上下两半句,用逗号 ,分隔,句号 . 结尾。相邻两字的拼音之间用一个空格分隔。题目保证每个字的拼音不超过 6 个字符,每行字符的总长度不超过100,并且下半句诗至少有 3 个字。
输出格式:
对每一行诗句,判断其是否压“ong”韵。即上下两句末尾的字都是“ong”结尾。如果是压此韵的,就按题面方法糟改之后输出,输出格式同输入;否则输出 Skipped,即跳过此句。

输入样例:

5
xun zhang zhai ju lao diao chong, xiao yue dang lian gua yu gong.
tian sheng wo cai bi you yong, qian jin san jin huan fu lai. 
xue zhui rou zhi leng wei rong, an xiao chen jing shu wei long. 
zuo ye xing chen zuo ye feng, hua lou xi pan gui tang dong. 
ren xian gui hua luo, ye jing chun shan kong.

输出样例:

xun zhang zhai ju lao diao chong, xiao yue dang lian qiao ben zhong. 
Skipped 
xue zhui rou zhi leng wei rong, an xiao chen jing qiao ben zhong. 
Skipped
Skipped
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
using namespace std;



int main()
{
	int n;
	cin >> n;
	getchar();//去除回车
	string str[20];
	int i, j, k;
	int q[20] = { 0 };//用于记录是否押韵
	for (i = 0; i < n; i++)
	{
		getline(cin, str[i]);
		if (str[i].find("ong,") != -1)//判断第一句是否押韵
		{
			q[i]++;//表示押韵句数
		}
		if (str[i].find("ong.") != -1)//判断第二句是否押韵
		{
			q[i]++;//表示押韵句数
		}	
	}


	for (i = 0; i < n; i++)
	{
		if (q[i] != 2)//不是两句都押韵
		{
			cout << "Skipped" << endl;
		}
		else
		{
			int sp = 0;//空格数,代表了单词数
			for (j = str[i].length() - 1; j >= 0; j--)//从后往前查找
			{
				if (str[i][j] == ' ')
				{
					sp++;
				}
				if (sp == 3)//此时j在最后三个字前的空格
				{
					break;
				}
			}
			for (k = 0; k <= j; k++)
			{
				cout << str[i][k];
			}
			cout << "qiao ben zhong." << endl;
		}
	}


	system("pause");
	return 0;
}

L1-060 心理阴影面积 (5 分)

2019团体程序设计天梯赛L1

这是一幅心理阴影面积图。我们都以为自己可以匀速前进(图中蓝色直线),而拖延症晚期的我们往往执行的是最后时刻的疯狂赶工(图中的红色折线)。由红、蓝线围出的面积,就是我们在做作业时的心理阴影面积。

现给出红色拐点的坐标 (x,y),要求你算出这个心理阴影面积。

输入格式:
输入在一行中给出 2 个不超过 100 的正整数 x 和 y,并且保证有x>y。这里假设横、纵坐标的最大值(即截止日和最终完成度)都是 100。

输出格式:
在一行中输出心理阴影面积。
友情提醒:三角形的面积 = 底边长 x 高 / 2;矩形面积 = 底边长 x 高。嫑想得太复杂,这是一道 5 分考减法的题……

输入样例:

90 10 

输出样例:

4000
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
using namespace std;



int main()
{
	int x, y;
	cin >> x >> y;
	int sum = 100 * 50 - (y * 50) - ((100 - x) * 50);
	cout << sum << endl;


	system("pause");
	return 0;
}

L1-061 新胖子公式 (10 分)

根据钱江晚报官方微博的报导,最新的肥胖计算方法为:体重(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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
using namespace std;



int main()
{
	double x, y;
	cin >> x >> y;
	double sum = x / (y*y);
	printf("%0.1lf\n", sum);//控制小数
	if (sum > 25)
	{
		cout << "PANG" << endl;
	}
	else
	{
		cout << "Hai Xing" << endl;
	}


	system("pause");
	return 0;
}

L1-062 幸运** (15 分)

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

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

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

输入样例:

2 
233008
123456 

输出样例:

You are lucky! 
Wish you good luck.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
using namespace std;



int main()
{
	int n;
	cin >> n;
	getchar();//去除空格
	string str;
	bool a[100];//记录是否幸运
	int i;
	for (i = 0; i < n; i++)
	{
		getline(cin, str);
		if (str[0] + str[1] + str[2] == str[3] + str[4] + str[5])
		{
			a[i] = true;
		}
		else
		{
			a[i] = false;
		}
	}
	for (i = 0; i < n; i++)
	{
		if (a[i] == true)
		{
			cout << "You are lucky!" << endl;
		}
		else
		{
			cout << "Wish you good luck." << endl;
		}
	}


	system("pause");
	return 0;
}

L1-063 吃鱼还是吃肉 (10 分)

2019团体程序设计天梯赛L12019团体程序设计天梯赛L1

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

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

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

性别 身高 体重

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

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

  • 如果太矮了,输出:duo chi yu!(多吃鱼);
  • 如果太瘦了,输出:duo chi rou!(多吃肉);
  • 如果正标准,输出:wanmei!(完美);
  • 如果太高了,输出: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!
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
using namespace std;

struct baby
{
	string h;//记录身高的状态
	string w;//记录体重的状态
};

int main()
{
	int sex;//记录性别
	int high;//身高
	int wight;//体重

	baby bb[10];

	int n;
	cin >> n;
	int i;
	for (i = 0; i < n; i++)
	{
		cin >> sex >> high >> wight;
		if (sex == 1)//男
		{
			if (high>130)
			{
				bb[i].h = "ni li hai!";
			}
			else if (high == 130)
			{
				bb[i].h = "wan mei!";
			}
			else
			{
				bb[i].h = "duo chi yu!";
			}

			if (wight>27)
			{
				bb[i].w = "shao chi rou!";
			}
			else if (wight == 27)
			{
				bb[i].w = "wan mei!";
			}
			else
			{
				bb[i].w = "duo chi rou!";
			}
		}
		else
		{
			if (high>129)
			{
				bb[i].h = "ni li hai!";
			}
			else if (high == 129)
			{
				bb[i].h = "wan mei!";
			}
			else
			{
				bb[i].h = "duo chi yu!";
			}

			if (wight>25)
			{
				bb[i].w = "shao chi rou!";
			}
			else if (wight == 25)
			{
				bb[i].w = "wan mei!";
			}
			else
			{
				bb[i].w = "duo chi rou!";
			}
		}
	}

	for (i = 0; i < n; i++)
	{
		cout << bb[i].h << " " << bb[i].w << endl;//记得加空格
	}


	system("pause");
	return 0;
}

L1-064 估值一亿的AI核心代码 (20 分)

2019团体程序设计天梯赛L1

以上图片来自新浪微博。

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

  • 无论用户说什么,首先把对方说的话在一行中原样打印出来;
  • 消除原文中多余空格:把相邻单词间的多个空格换成 1个空格,把行首尾的空格全部删掉,把标点符号前面的空格删掉;
  • 把原文中所有大写英文字母变成小写,除了 I
  • 把原文中所有独立的 can youcould you 对应地换成 I canI could—— 这里“独立”是指被空格或标点符号分隔开的单词;
  • 把原文中所有独立的 Ime 换成 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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
using namespace std;



int main()
{
	int n;
	cin >> n;
	getchar();
	int i, j, k;
	string str[10];
	string ai = "";//保存ai的输出
	for (i = 0; i < n; i++)
	{
		getline(cin, str[i]);
	}
	for (i = 0; i < n; i++)
	{
		cout << str[i] << endl;
		cout << "AI: ";
		for (j = 0; j < str[i].length(); j++)
		{
			if ((str[i][j] >= 'A'&&str[i][j] <= 'Z') && str[i][j] != 'I')//把大写变成小写,I不变
			{
				str[i][j] += 32;
			}
			if (str[i][j] == '?')//把?变成!
			{
				str[i][j] = '!';
			}
		}
		for (j = 0; j < str[i].length(); j++)
		{
			k = j;
			if (str[i][k] == ' ')//为空格代表一个单词输入结束
			{
				for (; str[i][k] == ' ' && k < str[i].length(); k++);//检测下一个非空格字符位置
				if (k != str[i].length())
				{
					if ((str[i][k] >= 'a' && str[i][k] <= 'z') || (str[i][k] >= '0' && str[i][k] <= '9') || str[i][k] == 'I')//如果不是表点符号,在前面补上空格
					{
						ai += ' ';
					}
				}
			}
			if (k != str[i].length())//正常输入
			ai += str[i][k];
			j = k;
		}
		if (ai[0] == ' ')//去除开头的空格
		{
			ai.erase(0, 1);
		}
		int pos;//储存查找的值
		for (pos = ai.find("I"); pos != -1; pos = ai.find("I", pos + strlen("I")))//寻找要找的字符的位置,处理后下一次从该字符后开始,当不存在时(-1)结束
		{
			if (pos - 1 >= 0)//判断该字符前方是否为标点或空格
			if ((ai[pos - 1] >= 'a'&&ai[pos - 1] <= 'z') || (ai[pos - 1] >= '0'&&ai[pos - 1] <= '9') || ai[pos - 1] == 'I')
			{
				continue;
			}//判断该字符后方是否为标点或空格
			if ((ai[pos + strlen("I")] >= 'a'&&ai[pos + strlen("I")] <= 'z') || (ai[pos + strlen("I")] >= '0'&&ai[pos + strlen("I")] <= '9') || ai[pos + strlen("I")] == 'I')
			{
				continue;
			}
			ai.replace(pos, strlen("I"), "***");//为了防止二次处理,用***标记
		}


		for (pos = ai.find("me"); pos != -1; pos = ai.find("me", pos + strlen("me")))
		{
			if (pos - 1 >= 0)
			if ((ai[pos - 1] >= 'a'&&ai[pos - 1] <= 'z') || (ai[pos - 1] >= '0'&&ai[pos - 1] <= '9') || ai[pos - 1] == 'I')
			{
				continue;
			}
			if ((ai[pos + strlen("me")] >= 'a'&&ai[pos + strlen("me")] <= 'z') || (ai[pos + strlen("me")] >= '0'&&ai[pos + strlen("me")] <= '9') || ai[pos + strlen("me")] == 'I')
			{
				continue;
			}
			ai.replace(pos, strlen("me"), "***");
		}


		for (pos = ai.find("can you"); pos != -1; pos = ai.find("can you", pos + strlen("can you")))
		{
			if (pos - 1 >= 0)
			if ((ai[pos - 1] >= 'a'&&ai[pos - 1] <= 'z') || (ai[pos - 1] >= '0'&&ai[pos - 1] <= '9') || ai[pos - 1] == 'I')
			{
				continue;
			}
			if ((ai[pos + strlen("can you")] >= 'a'&&ai[pos + strlen("can you")] <= 'z') || (ai[pos + strlen("can you")] >= '0'&&ai[pos + strlen("can you")] <= '9') || ai[pos + strlen("can you")] == 'I')
			{
				continue;
			}
			ai.replace(pos, strlen("can you"), "I can");
		}


		for (pos = ai.find("could you"); pos != -1; pos = ai.find("could you", pos + strlen("could you")))
		{
			if (pos - 1 >= 0)
			if ((ai[pos - 1] >= 'a'&&ai[pos - 1] <= 'z') || (ai[pos - 1] >= '0'&&ai[pos - 1] <= '9') || ai[pos - 1] == 'I')
			{
				continue;
			}
			if ((ai[pos + strlen("could you")] >= 'a'&&ai[pos + strlen("could you")] <= 'z') || (ai[pos + strlen("could you")] >= '0'&&ai[pos + strlen("could you")] <= '9') || ai[pos + strlen("could you")] == 'I')
			{
				continue;
			}
			ai.replace(pos, strlen("could you"), "I could");
		}

		for (pos = ai.find("***"); pos != -1; pos = ai.find("***", pos + strlen("***")))//为了防止二次处理,处理***
		{
			if (pos - 1 >= 0)
			if ((ai[pos - 1] >= 'a'&&ai[pos - 1] <= 'z') || (ai[pos - 1] >= '0'&&ai[pos - 1] <= '9') || ai[pos - 1] == 'I')
			{
				continue;
			}
			if ((ai[pos + strlen("***")] >= 'a'&&ai[pos + strlen("***")] <= 'z') || (ai[pos + strlen("***")] >= '0'&&ai[pos + strlen("***")] <= '9') || ai[pos + strlen("***")] == 'I')
			{
				continue;
			}
			ai.replace(pos, strlen("***"), "you");
		}
		cout << ai << endl;
		ai = "";//重置ai的值
	}


	system("pause");
	return 0;
}

来源:https://pintia.cn/