跳到正文

题解

题解:P14124

qeueu约 4 分钟
原文
文章信息与版本

文章信息

发布
2025年10月3日
收录
2026年6月18日
更新
2026年11月13日
篇幅
约 4 分钟
获赞
5
题目
P14124

版本

  1. v1当前

蒟蒻来水一发题解。

题意简述

有 TT 组数据,你需要修改其中的单词后缀后输出。

原后缀新后缀
chimasutte
rimasu
mimasunde
bimasu
nimasu
kimasuite
gimasuide
shimasushite

特例:对于单词 ikimasu,输出 itte即可。

思路分析

本题考察字符串。

为了偷懒,作者使用了 C++ 20 的 ends_with 功能。其格式如下(s 为字符串名,abc 为 s 的后缀):

C++
if(s.ends_with("abc"))
{//do something
}

于是不难写出代码。

参考代码

C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int a=0;a<t;a++)
    {
        string s;
        cin>>s;
        int i=s.size();
        if(s.ends_with("chimasu"))
        {
            for(int j=0;j<i-7;j++)
            {
                cout<<s[j];
            }
            cout<<"tte";
        }
        if(s.ends_with("rimasu"))
        {
            for(int j=0;j<i-6;j++)
            {
                cout<<s[j];
            }
            cout<<"tte";
        }
        if(s.ends_with("mimasu")||s.ends_with("bimasu")||s.ends_with("nimasu"))
        {
            for(int j=0;j<i-6;j++)
            {
                cout<<s[j];
            }
            cout<<"nde";
        }
        if(s=="ikimasu")//特判
        {
            for(int j=0;j<i-7;j++)
            {
                cout<<s[j];
            }
            cout<<"itte";
        }
        if(s.ends_with("kimasu")&&s!="ikimasu")//注意!不要忘记后半段,不然会输出 2 个后缀
        {
            for(int j=0;j<i-6;j++)
            {
                cout<<s[j];
            }
            cout<<"ite";
        }
        if(s.ends_with("gimasu"))
        {
            for(int j=0;j<i-6;j++)
            {
                cout<<s[j];
            }
            cout<<"ide";
        }
        if(s.ends_with("shimasu"))
        {
            for(int j=0;j<i-7;j++)
            {
                cout<<s[j];
            }
            cout<<"shite";
        }
        cout<<(a!=t?"\n":"");
    }
    return 0;
}

AC 记录

这真的是 ICPC 的题目吗(逃

原文
存档评论2 条抓取于