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
英文地址,請注明出處:http://en.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…