PTA天梯赛L1 071-080题目解析

目录

1.L1-071 前世档案

2.L1-072 刮刮彩票

3.L1-073 人与神

4.L1-074 两小时学完C语言

5.L1-075 强迫症

6.L1-076 降价提醒机器人

7.L1-077 大笨钟的心情

8.L1-078 吉老师的回归

9.L1-079 天梯赛的善良

10.L1-080 乘法口诀数列


1.L1-071 前世档案

解析:

观察规律,如果从1开始,如果向右是否,则结果翻倍,否则变为翻倍-1

#include<iostream>using namespace std;int n,len;string s;
signed main() {cin>>len>>n;for(int i=0;i<n;i++) {cin>>s;int indexs = 1;for(int i=0;i<s.size();i++) indexs = indexs*2- (s[i] == 'y' ? 1:0);cout<<indexs<<endl;}	return 0;
} 

2.L1-072 刮刮彩票

#include<iostream>
#include<vector>
#include<map>using namespace std;const int N = 5;
int arr[N][N];
int x,y;  // 选择刮开的位置  或者是 0所在的位置 
int line_index;  // 最后输入的线编号
int sum; // 选择的线的总和 
int sum_num[] = {0,0,0,0,0,0,0,0,0,0};
map<int,int> my_map;
int check_num(int *a) {for(int i=1;i<=9;i++) {if (!a[i]) return i;} 
}void init_map() {my_map.insert({6,10000});my_map.insert({7,36});my_map.insert({8,720});my_map.insert({9,360});my_map.insert({10,80});my_map.insert({11,252});my_map.insert({12,108});my_map.insert({13,72});my_map.insert({14,54});my_map.insert({15,180});my_map.insert({16,72});my_map.insert({17,180});my_map.insert({18,119});my_map.insert({19,36});my_map.insert({20,306});my_map.insert({21,1080});my_map.insert({22,144});my_map.insert({23,1800});my_map.insert({24,3600});
}
signed main() {init_map();for(int i=1;i<=3;i++) {for(int j=1;j<=3;j++) {cin>>arr[i][j];if(arr[i][j] == 0) {x = i;y=j;} sum_num[arr[i][j]] ++;}}int available_num = check_num(sum_num);arr[x][y] = available_num; // 补全缺失数字for(int i=0;i<3;i++) {cin>>x>>y;cout<<arr[x][y]<<endl;;} cin>>line_index;if (1<=line_index && line_index<=3) for (int i=1;i<=3;i++) sum+=arr[line_index][i]; else if (4<=line_index && line_index<=6) for (int i=1;i<=3;i++) sum+=arr[i][line_index-3]; else {if (line_index == 7) {sum += arr[1][1];sum += arr[2][2];sum += arr[3][3];} else if (line_index == 8) {sum += arr[3][1];sum += arr[2][2];sum += arr[1][3];}}cout<<my_map[sum]<<endl;return 0;
} 

3.L1-073 人与神

#include<iostream>
#include<vector>
#include<map>using namespace std;signed main() {cout<<"To iterate is human, to recurse divine."; return 0;
} 

4.L1-074 两小时学完C语言

#include<iostream>
#include<vector>
#include<map>using namespace std;int n,k,m;signed main() {cin>>n>>k>>m;cout<<n-k*m;return 0;
} 

5.L1-075 强迫症

#include<iostream>
#include<vector>
#include<map>
#include<iomanip>using namespace std;int n,year,mouth;signed main() {cin>>n;year = n/100;mouth = n%100;if (year < 100) year = (year < 22 ?2000 :1900) +year;cout<<year<<"-"<<setw(2)<<setfill('0')<<mouth<<endl; return 0;
} 

6.L1-076 降价提醒机器人

#include<iostream>
#include<vector>
#include<map>
#include<iomanip>using namespace std;int n;
double price,current_price;signed main() {cin>>n>>price;for(int i=0;i<n;i++) {cin>>current_price;if (current_price < price) cout<<"On Sale! "<<fixed<<setprecision(1)<<current_price<<endl;}	return 0;
} 

7.L1-077 大笨钟的心情

#include<iostream>
#include<vector>
#include<map>
#include<iomanip>using namespace std;const int N = 24;
int times;
vector<int> time_mood;
signed main() {for(int i=0;i<N;i++) {cin>>times;time_mood.push_back(times);}while(cin>>times) {if (!(0<=times && times <= 23)) break;if (time_mood[times] > 50) cout<<time_mood[times]<<" Yes";else cout<<time_mood[times]<<" No";cout<<endl;}return 0;
} 

8.L1-078 吉老师的回归

解析:

使用vector记录要做的题目列表,然后输出下标为k时的题目即可

注意如果k刚好是总待做题目,那么应该直接输出AK的文字

#include<iostream>
#include<vector>
#include<map>
#include<iomanip>using namespace std;int n,k;
string topic; 
string target_1 = "qiandao";
string target_2 = "easy";
vector<string> out_str;signed main() {cin>>n>>k;getchar();for(int i=0;i<n;i++) {getline(cin,topic);if(topic.find(target_1) == string::npos && topic.find(target_2) == string::npos )  {out_str.push_back(topic);}}// 注意k和题目数量n一致 if (!out_str.empty() && k < out_str.size()) cout<<out_str[k]<<endl;else cout<<"Wo AK le";return 0;
} 

9.L1-079 天梯赛的善良

#include<iostream>
#include<vector>
#include<map>
#include<iomanip>
#define int long long
using namespace std;map<int,int>  my_map;
int n,score;
signed main() {cin>>n;for(int i=0;i<n;i++) {cin>>score;my_map[score] ++;}
//	for(auto it:my_map) {
//		cout<<it.first<<" "<<it.second<<endl;
//	}if (!my_map.empty()) {auto first_ele = my_map.begin();auto last_ele = my_map.rbegin(); // 反向迭代器,返回低地址元素。 如果使用正向迭代器,则需要last_ele -- cout<<first_ele->first<<" "<<first_ele->second<<endl;cout<<last_ele->first<<" "<<last_ele->second<<endl;}return 0;
} 

10.L1-080 乘法口诀数列

解析:

注意是前方每个数字都要经历相乘得到结果放在结尾,所以使用vector会比较好

另外考虑到0会短路while,所以要对运算结果为0的数进行特判加进去

#include<iostream>
#include<vector>
#include<map>
#include<iomanip>
#define int long long
using namespace std;vector<int> res;
int a_1,a_2,k;vector<int> tmp;
signed main() {cin>>a_1>>a_2>>k;res.push_back(a_1);	res.push_back(a_2);int current_index = 2;while(res.size() < k) {int sum = res[current_index - 1] * res[current_index - 2];if (sum) while(sum) tmp.push_back(sum%10),sum/=10;else tmp.push_back(0);while(!tmp.empty()) {res.push_back(tmp.back());tmp.pop_back();} current_index ++;}for(int i=0;i<k;i++) {if(i) cout<<" ";cout<< res[i];}return 0;
} 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/87337.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/87337.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

git常用操作 --- idea编译器 --- 公司实战版

前言 虽然git的命令方式很灵活,但是还是不够人性化,不够方便。 如果对git操作不熟练特别容易犯迷,可能敲一会命令就不知道当前在干什么了,下一步要干什么。 下面,我将演示在Java开发中使用最常用最经典的idea编译器来进行git操作,非常人性化和方便。 如果没有安装git和初始…

window显示驱动开发—流输出阶段

流输出 (SO) 阶段可以在这些顶点到达光栅器之前将顶点流式传输到内存。 流输出的运行方式类似于管道中的点击。 即使数据继续向下流向光栅器&#xff0c;也可以打开此点击。 通过流输出发送的数据连接到缓冲区。 这些缓冲区可以在后续传递上作为管道输入进行循环。 流输出的一…

备份docker desktop中的opengauss数据库

文章目录 备份docker desktop中的opengauss数据库一、前提条件二、备份步骤三、注意事项四、自动化备份&#xff08;可选&#xff09;五、验证备份 备份docker desktop中的opengauss数据库 ​ 以下是在 Docker Desktop 中备份 OpenGauss 数据库&#xff08;以你的环境为例&…

实时中值滤波 + 低通滤波 示例程序(STM32环境)

一、功能概述 本示例实现两个滤波器&#xff1a; 中值滤波器&#xff08;Median Filter&#xff09;&#xff1a;对短期异常值&#xff08;如尖峰噪声&#xff09;有良好的抑制能力&#xff1b;低通滤波器&#xff08;Low-Pass Filter&#xff09;&#xff1a;对数据进行平滑…

AtCoder Beginner Contest 409 题解

本文为AtCoder Beginner Contest 409 的详细题解 目录 题目A: 题目大意: 解题思路: 代码(C): 题目B: 题目大意: 解题思路: 代码(C): 题目C: 题目大意: 解题思路: 代码(C): 题目D: 题目大意: 解题思路: 代码(C): 题目E: 题目大意: 解题思路: 代码(C): 题目A…

Spring @Environment 典型用法

简单说&#xff1a;Spring 里没有直接叫 Environment 的注解&#xff0c;更准确说常用的是 Autowired 注入 Environment 对象&#xff0c;或者结合 Value 配合 Environment 读取配置 。 支持从以下来源读取&#xff1a; 1、application.properties / .yaml 2、JVM 参数&#xf…

【集合与结构体】5.2(课本题)总结代码

ds老师产物&#xff0c;纯为期末复习&#xff0c;自用。 题目1 编写程序&#xff0c;将一个整型变量右移 4 位&#xff0c;并以二进制数形式输出该整数在移位前和移位后的数值。 //观察系统填补空缺的数位情况 代码解答 #include <iostream>//编写程序&#xff0c;将一个…

16.max/min最大最小值函数

1.基本使用 max/min函数返回满足where条件的一列的最大/最小值。 select max(column_name)|min(column_name) from table_namewhere where_definition 示例&#xff1a; ①求班级总分的最高分 #求班级总分的最高分 SELECT MAX(math_scorechinese_scoreenglish_score)AS 总分…

需要做一款小程序,用来发券,后端如何进行设计能够保证足够安全?

温馨提示&#xff1a;本文由ai生成&#xff0c;请辨别阅读&#xff0c;本文仅提供一种思考的方式和设计思路 设计一个安全的后端系统&#xff0c;用于发放优惠券的小程序&#xff0c;需要考虑多个安全层面&#xff0c;包括身份验证、数据安全、API 安全、以及防止常见攻击&…

ACM设计平台-核心模块解析-赵家康

负责模块解析-赵家康 一、Login.vue 功能逻辑、数据绑定、表单验证、与后端交互 Vue 登录页面的代码设计 代码功能概览 代码实现了一个典型的登录页功能&#xff0c;核心包括&#xff1a; 表单输入&#xff08;学号、用户名、密码、验证码&#xff09; 验证码生成与校验 勾…

在 VMware (WM) 虚拟机上安装的 Ubuntu 22.04 分配了 20GB 磁盘,但仅使用 10GB 就显示 “空间已满“

可能原因及解决方案 虚拟机磁盘未实际扩容&#xff08;仅调整了虚拟大小&#xff09; 现象&#xff1a;在 VMware 里调整了磁盘大小&#xff08;如 20GB → 50GB&#xff09;&#xff0c;但 Ubuntu 内部仍只识别 10GB。 原因&#xff1a;VMware 调整的是虚拟磁盘上限&#xf…

初学STM32全功能按键非阻塞式实现和强化

其实笔者以前学51的时候按键功能就包含非阻塞式的&#xff0c;而且还包括矩阵按键的非组塞式按键实现。开关的长短键功能笔者在之前的51博文中笔者自己尝试写过&#xff0c;功能是有了但写的其实很混乱&#xff0c;几乎没有移植的价值。这次江科大刚好出了新的教程&#xff0c;…

【网络原理】网络原理简单认识 —— 内含网络通信基础、五元组、网络协议(OSI 七层协议、TCP/IP 五层(或四层)协议)、封装和分用

目录 1. 网络互连 1.1 局域网LAN 1.2 广域网WAN 2 网络通信基础 2.1 IP地址 2.2 端口号 2.3 网络协议 3. 五元组 4. 协议分层 4.1 OSI 七层网络模型 4.2 TCP/IP 五层&#xff08;或四层&#xff09;网络模型 4.3 网络设备所在分层(经典笔试题) 5. 网络数据传输的基…

嵌入式之硬件学习(三)通信方式、串口通信

目录 一、通信种类 1、并行通信 2、串行通信 3、单工模式(Simplex Communication) 4、半双工通信(Half-Duplex Communication) 5、全双工通信(Full-Duplex Communication) 6、串行的异步通信与同步通信 &#xff08;1&#xff09;异步通信 &#xff08;2&#xff09;同…

【微信小程序】3、SpringBoot整合WxJava发送订阅消息

1、创建消息模板 在公共模板库里面选择符合自己业务场景的消息模板&#xff0c;例如&#xff1a; 每个消息模板最多选择5项&#xff0c;可根据自己业务需求自行选择&#xff0c;顺序也可以自己决定。提交后&#xff0c;我们就得到了属于自己的消息模板ID 2、文档阅读 官方文…

Flask 快速精通:从入门到实战的轻量级 Web 框架指南

Flask 作为 Python 生态中最受欢迎的轻量级 Web 框架&#xff0c;以其简洁灵活的设计理念赢得了开发者的青睐。本文将系统梳理 Flask 的核心概念与实战技巧&#xff0c;帮助你快速掌握这一强大框架。 一、Flask 框架概述 1.1 轻量级框架的核心特性 Flask 诞生于 2010 年&…

Python爬取豆瓣短评并生成词云分析

一、项目概述 本项目的目标是爬取豆瓣上某部电影的短评数据&#xff0c;并生成词云进行情感分析。我们将使用Python编程语言&#xff0c;借助爬虫技术获取数据&#xff0c;并利用自然语言处理和数据可视化工具进行分析。具体步骤包括&#xff1a; 爬取豆瓣短评数据。数据清洗…

Controller Area Network (CAN) 通信机制简介

目录 1. CAN 概述 2. 物理结构与传输机制 3. 消息格式与仲裁机制 4. 错误检测与总线状态 5. 工业用 CAN 接口 6. 本讲总结 1. CAN 概述 CAN&#xff08;Controller Area Network&#xff09;是由德国博世&#xff08;Bosch&#xff09;公司于 1983 年提出的串行通信协议…

我有一个想法

我有一个想法 我想为家乡做点事情&#xff0c;但是又不知道从哪里开始。 也许为家乡的教育做点事情是比较靠谱的。 于是&#xff0c;我就想到了&#xff0c;是不是可以在高中学校&#xff0c;设立一个“鸿鹄”奖学金&#xff1f; 这个奖学金怎么使用呢&#xff1f; 在每年9月份…

【Pandas】pandas DataFrame stack

Pandas2.2 DataFrame Reshaping sorting transposing 方法描述DataFrame.droplevel(level[, axis])用于**从 DataFrame 的索引&#xff08;行或列&#xff09;中删除指定层级&#xff08;level&#xff09;**的方法DataFrame.pivot(*, columns[, index, values])用于重塑 Dat…