题解:P14124 [SCCPC 2021] Nihongo wa Muzukashii Desu

news/2025/10/4 12:41:41/文章来源:https://www.cnblogs.com/Linda0417/p/19125490

P14124 题解

题目传送门

题意简化

给你 \(n\) 个字符串,根据字符串的后缀按要求更改字符串。

题目分析

一般的转换规则可以分为 5 种,如下表。

后缀类型 更改后
chimasu tte
rimasu ^
mimasu nde
bimasu ^
nimasu ^
kimasu ite
gimasu ide
shimasu shite

根据题意, ikimasu 需要进行特判,转换为 itte。

根据观察,我们发现题目中给出的字符串都是以 masu 结尾的,所以我们只需要判断 masu 前面的部分便能确定是哪种类型。

我们自然而然想到用遍历来判断,但是每句话前面的东西我们不知道有多长。所以,我们需要倒着遍历。建立一个字符串存储去除 masu 后的后缀,直到和上面的任意一种类型匹配。

由于是倒着遍历的,所以我们的判断条件也要倒过来

int type(string s) {string hz = ""; // 存储后缀for(int i = s.size() - 5; i >= 0; i--) { // 从后往前遍历hz += s[i];if(hz == "ihc" || hz == "ir") return 1;if(hz == "im" || hz == "ib" || hz == "in") return 2;if(hz == "ik") return 3;if(hz == "ig") return 4;if(hz == "ihs") return 5;}
}

确定好类型之后,我们再来确定内容的位置。这里的内容是指去掉后缀的剩余部分。

经过观察,后缀长度有两种,一种是 6 个字符的,一种是 7 个。这里我们用和上面同样的方法判断长度。

int type2(string s) {string hz = "";for(int i = s.size() - 5; i >= 0; i--) {hz += s[i];if(hz == "im" || hz == "ib" || hz == "in" || hz == "ir" || hz == "ik" || hz == "ig") return 1; // 六个字符if(hz == "ihc" || hz == "ihs") return 2; // 七个字符}
}
int len(string s) { // 内容位置if(type2(s) == 2) return s.size() - 7;return s.size() - 6;
}

接下来是替换部分。这部分就很简单了,直接根据上面返回的数值进行拼接就行。为了方便,这里开了一个数组存储更改后的后缀。

string change[] = {"", "tte", "nde", "ite", "ide", "shite"};
// 省略其他部分
ans = str.substr(0, len(str)) + change[type(str)]; // substr(0, n)返回的是字符串下标从 0 开始往后 n 位的字串

下面给出完整代码。

代码

#include<iostream>
#include<string>
using namespace std;
int t;
string str, ans;
string change[] = {"", "tte", "nde", "ite", "ide", "shite"};
int type(string s) {string hz = "";for(int i = s.size() - 5; i >= 0; i--) {hz += s[i];if(hz == "ihc" || hz == "ir") return 1;if(hz == "im" || hz == "ib" || hz == "in") return 2;if(hz == "ik") return 3;if(hz == "ig") return 4;if(hz == "ihs") return 5;}
}
int type2(string s) {string hz = "";for(int i = s.size() - 5; i >= 0; i--) {hz += s[i];if(hz == "im" || hz == "ib" || hz == "in" || hz == "ir" || hz == "ik" || hz == "ig") return 1;if(hz == "ihc" || hz == "ihs") return 2;}
}
int len(string s) {if(type2(s) == 2) return s.size() - 7;return s.size() - 6;
}
int main() {cin >> t ;while(t--) {cin >> str ;if(str == "ikimasu") cout << "itte" << endl;else {ans = str.substr(0, len(str)) + change[type(str)];cout << ans << endl;}}return 0;
}

谢谢观看!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/927138.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网站上传在空间哪里女孩子奖励自己的资料

&#x1f40c;博主主页&#xff1a;&#x1f40c;​倔强的大蜗牛&#x1f40c;​ &#x1f4da;专栏分类&#xff1a;C❤️感谢大家点赞&#x1f44d;收藏⭐评论✍️ 目录 一、Static成员 1、概念 2、特性 二、友元 1、友元函数 2、友元类 一、Static成员 1、概念 声…

怎么查看网站是用什么编程语言开发的gta5买房网站建设中

央视网(www.cctv.com)视频下载往往是花屏的&#xff0c;如何处理呢&#xff1f; 如果您是IT技术开发者&#xff0c;那么您可以通过下面步骤自己实现。 用chrome浏览器&#xff0c;F2打开开发者工具&#xff0c;找到当前页面的network 然后找一个接口&#xff1a;https://vdn.a…

上位机知识篇---服务器脚本一直运行方法 - 详解

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

个人网站域名取名chenqinghua wordpress

题目描述: 小红拿到了一个数组&#xff0c;初始数组为空&#xff0c;她希望你实现以下两种操作&#xff1a; 1. 输入x,y&#xff0c;将x插入在元素y的右边。保证此时数组中没有元素等于x&#xff0c;且数组中存在一个y。特殊的&#xff0c;如果将x插入在数组的最左边&#xff0…

python+vue在线视频课程学习系统设计(源码+文档+调试+基础修改+答疑) - 详解

python+vue在线视频课程学习系统设计(源码+文档+调试+基础修改+答疑) - 详解pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-fa…

DeepSeek V3.1-Terminus、阿里 Qwen3-Max、ChatGPT Pulse 同周登场!| AI Weekly 9.22-9.28 - 实践

DeepSeek V3.1-Terminus、阿里 Qwen3-Max、ChatGPT Pulse 同周登场!| AI Weekly 9.22-9.28 - 实践pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block …

wejianzhan是什么网站企业解决方案参考网站

背景&#xff1a;写的算法合并到项目组代码&#xff0c;编译发现一些以前没积累过的错误&#xff0c;这里记录下&#xff0c;也供大家参考。 一、问题1 // 每个类都有单独的.h .cpp class A; class B : public A {// ... }; class C : public A {// ... };若在B.h中引用了一个…

网站建设修饰商品wordpress批量导入页面

文章目录 &#x1f34b;引言&#x1f34b;队列的定义&#x1f34b;队列的实现&#x1f34b;队列的应用&#x1f34b;练习题&#x1f34b;结语 &#x1f34b;引言 队列&#xff08;Queue&#xff09;是计算机科学中一种重要的数据结构&#xff0c;它常用于各种应用程序中&#x…

公司做了网站怎么做推广本地做织梦网站

原文来自http://note.youdao.com/share/web/file.html?id236896997b6ffbaa8e0d92eacd13abbf&typenote 我怕链接会失效&#xff0c;故转载此篇文章。通过这篇文章&#xff0c;我对之前疑惑的地方有了直观的理解&#xff0c;很多地方并没有自己动手实践&#xff0c;所以这篇…

【做题记录】CF2600左右有趣的思维题1

A. Latin Square 考虑维护三元组 \((i,j,a_{i,j})\)。例如:R 操作就是变成了 \((i,j+1,a_{i,j})\);I 操作就是变成了 \((i,a_{i,j},j)\)。时间复杂度 \(O(m+n^2)\)。Code #include<bits/stdc++.h> #define ll …

pdf翻译

pdf翻译 https://github.com/Byaidu/PDFMathTranslate?tab=readme-ov-file

OpenEuler 25.03 installed UKUI but cant run msedge and chrome

[root@OpenEulerWD Desktop]# pwd /root/Desktop[root@OpenEulerWD Desktop]# cat google-chrome.desktop microsoft-edge.desktop | grep stable Exec=/usr/bin/google-chrome-stable %U Exec=/usr/bin/google-chrom…

网站为什么被百度k了关于wordpress更新时无法创建目录

Spring Boot 注解 PostConstruct 介绍 文章目录 Spring Boot 注解 PostConstruct 介绍一、基本介绍二、PostConstruct 的执行时机Spring Bean 的生命周期PostConstruct 的确切执行时机执行顺序示例重要注意事项 三、使用场景及代码示例1. 初始化资源&#xff1a;比如打开数据库…

实用指南:iPhone美区账号登录指南:轻松下载ChatGPT应用

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

德国诺莫斯手表网站电子商务网站建设与管理习题答案

http://www.imooc.com/article/285246?block_idtuijian_wz 最近在设计一款进销存系统的时候&#xff0c;遇到一个分类的设计问题&#xff0c;就是如何将分类设计成数据库里的表&#xff0c;怎么样设计才比较灵活&#xff1f; 举个例子&#xff0c;一级分类&#xff1a;生鲜类&…

推广方案怎么写模板网站内容seo

汇川Easy系列以太网通讯中(MODBUSTCP,plc做主站),终于可以不用使用指令就可以完成了,全程通过简单的配置就可通讯。本文将通过EASY系列PLC与调试助手之间完成此操作。具体演示如下; 关于主站和从站的介绍 A/请求:即主动方 向被动方发送的一个要求的信息。 B/主站:发…

网络调整config.xml的android.mk解析

网络调整config.xml的android.mk解析pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monac…

【Android】RuntimeShader 应用

1 简介 ​ RuntimeShader 是 Android 13(T)中新增的特性,用于逐像素渲染界面,它使用 AGSL(Android Graphics Shading Language)编写着色器代码,底层基于 Skia 图形渲染引擎。官方介绍详见 → RuntimeShader。…