当前位置:网站首页>题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
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;
}

边栏推荐
- math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
- KS008基于SSM的新闻发布系统
- 查询mysql数据库中各表记录数大小
- Database, relational database and NoSQL non relational database
- After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
- 软考 系统架构设计师 简明教程 | 总目录
- Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
- Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
- Ipv4中的A 、B、C类网络及子网掩码
- 20、 EEPROM memory (AT24C02) (similar to AD)
猜你喜欢

10 exemples les plus courants de gestion du trafic istio, que savez - vous?

记一次excel XXE漏洞

Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage

Redis (replicate dictionary server) cache

Tips for using dm8huge table
![P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]](/img/b1/dbfc42d66548476300501dd839abef.jpg)
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]

Stable Huawei micro certification, stable Huawei cloud database service practice

Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)

【可调延时网络】基于FPGA的可调延时网络系统verilog开发

The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
随机推荐
Prime Protocol宣布在Moonbeam上的跨链互连应用程序
【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
Stable Huawei micro certification, stable Huawei cloud database service practice
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
【leetcode】22. bracket-generating
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
【按键消抖】基于FPGA的按键消抖模块开发
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
Stack and queue
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Mlapi series - 04 - network variables and network serialization [network synchronization]
How to modify field constraints (type, default, null, etc.) in a table
简易博客系统
About some basic DP -- those things about coins (the basic introduction of DP)
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos
MySQL master-slave replication
Cross domain and jsonp details
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了