2019年天梯赛全国总决赛题集

本文提供了2019年天梯赛全国总决赛的部分题目简介,包括L1-1到L2-4四个难度级别的题目。L1-2需要注意末尾连续6的情况,L1-3和L1-7分别涉及find函数和决策选择,L2-3和L2-4则需要深入理解DFS和栈的运用。
摘要由CSDN通过智能技术生成

题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/type/7

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

在这里插入图片描述

#include <iostream>
using namespace std;

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

L1-2 6翻了 (15分)

在这里插入图片描述

需要额外考虑连续的6在末尾的情况

#include <iostream>
#include <string>
using namespace std;

int main(void)
{
   
	string s;
	int cnt = 0;
	getline(cin, s);
	for (int i = 0; i < s.size(); i++){
   
		if (s[i] == '6')
			cnt++;
		if (s[i] != '6' || i == s.size() - 1){
   //如果当前不是6或者是最后一个字符 
			if (cnt <= 3){
   
				for (int j = 0; j < cnt; j++)
					cout << "6";
			}
			else if (cnt > 3 && cnt <= 9)
				cout << "9";
			else if (cnt > 9)
				cout << "27";
			cnt = 0;
			if (i != s.size() - 1)//当前不是最后一个字符 
				cout << s[i];
			else if (i == s.size() - 1 && s[i] != '6')//当前是最后一个字符并且不是6 
				cout << s[i];
		}
	}
	cout << endl;
	return 0;
}

L1-3 敲笨钟 (20分)

在这里插入图片描述

灵活使用find函数

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(void)
{
   
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值