当前位置:网站首页>L1-059 敲笨钟
L1-059 敲笨钟
2022-04-22 00:12:00 【EnochChen_】
一开始我不明白,怎么把一句话分割输入,并且判断
下面是先输入在判断,如果逗号前面时候ong并且.前面也是ong那就是押韵的
并且根据空格判断第几个单词
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
string s;
int main() {
int n;
cin >> n;
getchar();
while (n--) {
getline(cin, s);
int f1 = 0, f2 = 0, num = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == ',')
if (s[i - 3] == 'o' && s[i - 2] == 'n' && s[i - 1] == 'g')
f1 = 1;
if (s[i] == '.')
if (s[i - 3] == 'o' && s[i - 2] == 'n' && s[i - 1] == 'g')
f2 = 1;
if (s[i] == ' ')
num++;
}
if (f1 && f2) {
for (int i = 0; i < s.size(); ++i) {
if (num == 2)
break;
cout << s[i];
if (s[i] == ' ')
num--;
}
cout << "qiao ben zhong.";
} else {
cout << "Skipped";
}
cout << "\n";
}
return 0;
}
下面判断有点不同,他是分成两个输入,把getline玩明白了属于是
然后倒序判断该在哪里输出
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
cin.get(); // 和getchar效果一样
string s1, s2;
getline(cin, s1, ',');
getline(cin, s2, '.');
int l1 = s1.size(), l2 = s2.size();
if (s1[l1 - 1] != 'g' || s1[l1 - 2] != 'n' || s1[l1 - 3] != 'o' || s2[l2 - 1] != 'g' || s2[l2 - 2] != 'n'
|| s2[l2 - 3] != 'o')
puts("Skipped");
else {
cout << s1 << ',';
int i, cnt = 0;
for (i = s2.size(); i >= 0; i--) {
if (s2[i] == ' ')
cnt++;
if (cnt == 3)
break;
}
for (int j = 0; j <= i; j++)
cout << s2[j];
cout << "qiao ben zhong.\n";
}
}
return 0;
}
版权声明
本文为[EnochChen_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/EnochChen_/article/details/124326350
边栏推荐
- LeetCode刷题——字符串
- 09. Raspberry pie ASP Net environment configuration
- 容器云系列之容器技术相关概念介绍
- 笔记本拓展外接显示器时 鼠标移动不到主显示器外的另一块屏上
- Codesys méthode de lecture des fichiers csv (non Excel)
- AI helps to monitor the wearing of labor protection equipment and escort the safe production of enterprises
- 细说MOS管知识-MOS管高端驱动与低端驱动解析和原理及区别
- 2022中国眼博会,北京青少年眼健康产业展会,护眼教育设备展
- What are the characteristics of data visualization software
- FANSEA 4W 单线圈发射无线充5W模块
猜你喜欢

Function of freewheeling diode in switching power supply

架构实战营-模块三-作业

Application layer (I)

Very powerful time and date plug-in --- jedate js

Simple use of OpenSSL

SP4522B 是一款专为2A充电升压集成输出移动电源IC

RT-Thread 应用篇 — 在STM32L051上使用 RT-Thread (一、无线温湿度传感器 之 新建项目)

seo关键词扩展-自动关键词拓展软件免费下载

2022 Beijing Eye Health Exhibition, Beijing glasses exhibition, Beijing myopia correction exhibition, optometry Exhibition

TCP的三次握手详解
随机推荐
Share the 28 we media tools I often use and collect them quickly. If 20000 videos are played, there will be 264 benefits
Function of freewheeling diode in switching power supply
容器雲系列之容器技術相關概念介紹
redis源码之链表(adlist.h和adlist.c)(篇一)
Very powerful time and date plug-in --- jedate js
Detailed explanation of TCP's three handshakes
seo关键词扩展-自动关键词拓展软件免费下载
笔记本拓展外接显示器时 鼠标移动不到主显示器外的另一块屏上
2022 Quality Officer - decoration direction - post skills (Quality Officer) test simulation 100 questions simulation test platform operation
Application layer (I)
DeepTech发布《2022先进计算七大趋势》,破局摩尔桎梏,决胜算力时代
Operation of simulated examination platform of test question bank for electrical installation and maintenance of hoisting machinery in 2022
MES实施过程中为什么会出现需求变更?又该如何解决?
活动预告 | 4月23日,多场OpenMLDB精彩分享来袭,不负周末好时光!
Extreme value theory of R language: visualization of tail index parameter estimation of hill statistics
Applet subcontracting
CocosCreator学习示例合集v3.4.2
分享我常用的28个自媒体工具,赶紧收藏,视频2万播放就有264收益
University four years, self-study programming commonly used 10 learning websites
B. Vlad and Candies