当前位置:网站首页>L1-058 6翻了 (15 分)
L1-058 6翻了 (15 分)
2022-04-21 22:15:00 【WTXYL】

“666”是一种网络用语,大概是表示某人很厉害、我们很佩服的意思。最近又衍生出另一个数字“9”,意思是“6翻了”,实在太厉害的意思。如果你以为这就是厉害的最高境界,那就错啦 —— 目前的最高境界是数字“27”,因为这是 3 个 “9”!
本题就请你编写程序,将那些过时的、只会用一连串“6666……6”表达仰慕的句子,翻译成最新的高级表达。
输入格式:
输入在一行中给出一句话,即一个非空字符串,由不超过 1000 个英文字母、数字和空格组成,以回车结束。
输出格式:
从左到右扫描输入的句子:如果句子中有超过 3 个连续的 6,则将这串连续的 6 替换成 9;但如果有超过 9 个连续的 6,则将这串连续的 6 替换成 27。其他内容不受影响,原样输出。
输入样例:
it is so 666 really 6666 what else can I say 6666666666
输出样例:
it is so 666 really 9 what else can I say 27
代码:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
string s;
getline(cin, s);
int l = -1, r = -1;
for(r = 0; r < s.size(); r ++){
if(s[r] != '6'){
if(l != -1){
if(r - l > 3 && r - l <= 9) cout << 9;
else if(r - l > 9) cout << 27;
else
for(int i = l; i < r; i ++) cout << 6;
l = -1;
}
cout << s[r];
}
else
if(l == -1) l = r;
}
if(l != -1){
if(r - l > 3 && r - l <= 9) cout << 9;
else if(r - l > 9) cout << 27;
else
for(int i = l; i < r; i ++) cout << 6;
}
}
简单的双指针算法 。
版权声明
本文为[WTXYL]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_46891900/article/details/124219784
边栏推荐
猜你喜欢

CPT 102_LEC 11

Echart writes a large screen showing a circular edge gradient histogram

搭建本地Canal中间件进行数据迁移 —— 从缓存击穿得到的启发

字节日常实习(已OC)

Csr8670 SPI mode software burning method

Unity3d import tilt model, etc

Kotlin crawler app, Android development, interview preparation

CC00012.MySQL———————————————
![[vscode] detailed user manual for debugger](/img/b1/ceed28f4366ec2b116f308656c9e7a.png)
[vscode] detailed user manual for debugger

ROS——编译PCL相关程序报错:Could not find a package configuration file provided by “PCL“
随机推荐
[ES6] array expansion
ROS——使用OpenCV实现摄像头的发送和接收
[ES6] deconstruction and assignment of variables
[ES6] string extension
L3-1 那就别担心了 (30 分)——坑点,测试点分析
CC00012.ZABBIX———————————————
【ES6】字符串的扩展
CC00000.ZABBIX———————————————
STM32外设GPIO的配置和应用
[best practice] patrol inspection item: local disk type inspection of cloud server (CVM) instance
专精特新代办机构及专精特新代办政策分析解读,补贴20-100万
排序方式(8种)详解6—快速排序
「运维有小邓」企业如何解决AD域弱密码问题?
Oracle merge data operation (merge)
搭建本地Canal中间件进行数据迁移 —— 从缓存击穿得到的启发
【VSCode】调试器debugger详细使用手册
2022年中级会计职称考试会计实务练习题及答案
外包學生管理系統架構設計文檔
2022年中级会计职称考试经济法练习题及答案
【ES6】对象的扩展