当前位置:网站首页>题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
2022-07-06 04:10:00 【潘道熹】
文章目录
单词覆盖还原
题目描述
一个长度为 l ( 3 ≤ l ≤ 255 ) l(3\le l\le255) l(3≤l≤255) 的字符串中被反复贴有 boy
和 girl
两单词,后贴上的可能覆盖已贴上的单词(没有被覆盖的用句点表示),最终每个单词至少有一个字符没有被覆盖。问贴有几个 boy 几个 girl?
输入格式
一行被被反复贴有boy和girl两单词的字符串。
输出格式
两行,两个整数。第一行为boy的个数,第二行为girl的个数。
样例 #1
样例输入 #1
......boyogirlyy......girl.......
样例输出 #1
4
2
题解
// Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
// 计数
int boy=0,girl=0;
string a;
cin>>a;
int len=a.size();
for(int i=0;i<len-2;i++){
boy+=(a[i]=='b'||a[i+1]=='o'||a[i+2]=='y'?1:0);
if(i<len-3) girl+=(a[i]=='g'||a[i+1]=='i'||a[i+2]=='r'||a[i+3]=='l'?1:0);
}
cout<<boy<<endl<<girl;
return 0;
}
最长连号
题目描述
输入长度为 n n n 的一个正整数序列,要求输出序列中最长连号的长度。
连号指在序列中,从小到大的连续自然数。
输入格式
第一行,一个整数 n n n。
第二行, n n n 个整数 a i a_i ai,之间用空格隔开。
输出格式
一个数,最长连号的个数。
样例 #1
样例输入 #1
10
1 5 6 2 3 4 5 6 8 9
样例输出 #1
5
提示
数据规模与约定
对于 100 % 100\% 100% 的数据,保证 1 ≤ n ≤ 1 0 4 1 \leq n \leq 10^4 1≤n≤104, 1 ≤ a i ≤ 1 0 9 1 \leq a_i \leq 10^9 1≤ai≤109。
题解
// Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
int n,a,b=1,c=0,d;
cin>>n>>a;
for(int i=1;i<n;i++){
cin>>d;
if(a<d&&d-a==1) b++;
else b=1; // 一个数也是连号
if(b>c) c=b;
a=d;
}
cout<<c;
return 0;
}
小玉买文具
题目描述
班主任给小玉一个任务,到文具店里买尽量多的签字笔。已知一只签字笔的价格是 1 1 1 元 9 9 9 角,而班主任给小玉的钱是 a a a 元 b b b 角,小玉想知道,她最多能买多少只签字笔呢。
输入格式
输入只有一行两个整数,分别表示 a a a 和 b b b。
输出格式
输出一行一个整数,表示小玉最多能买多少只签字笔。
样例 #1
样例输入 #1
10 3
样例输出 #1
5
提示
数据规模与约定
对于全部的测试点,保证 0 ≤ a ≤ 1 0 4 0 \leq a \leq 10^4 0≤a≤104, 0 ≤ b ≤ 9 0 \leq b \leq 9 0≤b≤9。
题解
没什么说的,相对来说挺简单的。
// Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<(10*a+b)/19;
return 0;
}
小玉家的电费
题目描述
夏天到了,各家各户的用电量都增加了许多,相应的电费也交的更多了。小玉家今天收到了一份电费通知单。小玉看到上面写:据闽价电[2006]27号规定,月用电量在150千瓦时及以下部分按每千瓦时0.4463元执行,月用电量在151~400千瓦时的部分按每千瓦时0.4663元执行,月用电量在401千瓦时及以上部分按每千瓦时0.5663元执行;小玉想自己验证一下,电费通知单上应交电费的数目到底是否正确呢。请编写一个程序,已知用电总计,根据电价规定,计算出应交的电费应该是多少。
输入格式
输入一个整数,表示用电总计(单位以千瓦时计),不超过10000。
输出格式
输出一个数,保留到小数点后1位(单位以元计,保留到小数点后1位)。
样例 #1
样例输入 #1
267
样例输出 #1
121.5
题解
分段计费,写好if
就可以了。
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double s;
int n;
cin>>n;
if(n>400) s=150*0.4463+250*0.4663+(n-400)*0.5663;
else if(n>150) s=150*0.4463+(n-150)*0.4663;
else s=n*0.4463;
cout<<fixed<<setprecision(1)<<s;
return 0;
}
边栏推荐
- 记一次excel XXE漏洞
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- Interface idempotency
- Script lifecycle
- Python book learning notes - Chapter 09 section 01 create and use classes
- ESP32_ FreeRTOS_ Arduino_ 1_ Create task
- After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
- 80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
- 2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
猜你喜欢
After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
登录mysql输入密码时报错,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
Execution order of scripts bound to game objects
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
DM8 archive log file manual switching
Proof of Stirling formula
随机推荐
Use js to complete an LRU cache
Stable Huawei micro certification, stable Huawei cloud database service practice
51nod 1130 n factorial length V2 (Stirling approximation)
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
Basic use of MySQL (it is recommended to read and recite the content)
After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
MySQL master-slave replication
Ipv4中的A 、B、C类网络及子网掩码
Oracle ORA error message
mysql关于自增长增长问题
KS003基于JSP和Servlet实现的商城系统
Class A, B, C networks and subnet masks in IPv4
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
Hashcode and equals
Unity中几个重要类
Ks008 SSM based press release system
Determine which week of the month the day is