The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called "Kuchiguse" and is often exaggerated artistically in Anime and Manga. For example, the artificial sentence ending particle "nyan~" is often used as a stereotype for characters with a cat-like personality:

  • Itai nyan~ (It hurts, nyan~)

  • Ninjin wa iyada nyan~ (I hate carrots, nyan~)

Now given a few lines spoken by the same character, can you find her Kuchiguse?

Input Specification:

Each input file contains one test case. For each case, the first line is an integer N (2). Following are N file lines of 0~256 (inclusive) characters in length, each representing a character's spoken line. The spoken lines are case sensitive.

Output Specification:

For each test case, print in one line the kuchiguse of the character, i.e., the longest common suffix of all N lines. If there is no such suffix, write nai.

Sample Input 1:

3
Itai nyan~
Ninjin wa iyadanyan~
uhhh nyan~
 

Sample Output 1:

nyan~
 

Sample Input 2:

3
Itai!
Ninjinnwaiyada T_T
T_T
 

Sample Output 2:

nai

题意:

  找出最长公共后缀。

思路:

  模拟。

Code:

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
getchar();
string last, cur, temp;
for (int i = 0; i < n; ++i) {
if (i == 0)
getline(cin, last);
else {
temp = "";
getline(cin, cur);
int len1 = cur.length() - 1;
int len2 = last.length() - 1;
while (len1 >= 0 && len2 >= 0) {
if (cur[len1--] == last[len2]) {
temp = last[len2--] + temp;
} else
break;
}
last = temp;
}
}
if (last.length() == 0)
cout << "nai" << endl;
else {
for (int i = 0; i < temp.length(); ++i) cout << temp[i];
cout << endl;
}
return 0;
}

077 Kuchiguse的更多相关文章

  1. 1077. Kuchiguse (20)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  2. PAT1077: Kuchiguse

    1077. Kuchiguse (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming The Japan ...

  3. PAT 1077 Kuchiguse

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  4. A1077. Kuchiguse

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  5. PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】

    1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

  6. 1077 Kuchiguse (20 分)

    1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

  7. 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise

    题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...

  8. PAT 甲级 1077 Kuchiguse

    https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...

  9. PAT 1077 Kuchiguse [一般]

    1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

随机推荐

  1. python类的内部方法

    目录 一.绑定方法与非绑定方法 1.绑定方法 2.非绑定方法 二.property 1.什么是property? 2.为什么要用property? 3.如何使用property? 三.isinstan ...

  2. Django3.0 + nginx + uwsgi 部署

    CentOS7.6 下部署Django3.0应用,使用nginx+uwsgi部署: 1. uwsgi部署 pip install uwsgi 在项目的根目录中,新建文件夹 conf, 然后进入conf ...

  3. vue核心---虚拟dom的实现

    生成dom的过程 由vue模板生成虚拟dom 虚拟dom转换成真实dom渲染到html页面 代码实现 要实现的真实dom <div id="box"> <p cl ...

  4. windows上传ipa文件到苹果开发者中心的教程

    转: windows上传ipa文件到苹果开发者中心的教程 我们在苹果开发者中心上架ios app的时候,需要使用xcode或transporter先上传ipa文件到开发者中心. 但是假如我们只是H5开 ...

  5. MyBatis中的Map

    接口 int addUserMap(Map<String, Object> map); Mapper.xml <!-- Map比较灵活 传递的值为Map的key,可以为任何(野路子, ...

  6. django Form 效验

    Django 登入效验 .py from django import forms from student import models from django.core.exceptions impo ...

  7. 从零学脚手架(二)---初识webpack

    在上一篇中,介绍了 webpack 的 entry . output . plugins 属性. 在这一篇,接着介绍其它配置属性. mode 这个属性在上一篇中使用过一次:设置 webpack 编译模 ...

  8. LNMP配置——Nginx配置 —— 用户认证

    一.配置 再来创建一个新的虚拟主机 #cd /usr/local/nginx/conf/vhost #vi test.com.conf 写入: server { listen 80; server_n ...

  9. 用水浒传来学习OKR

    用水浒传来学习OKR 目录 用水浒传来学习OKR 0x00 摘要 0x01 OKR 1.1 基本概念 1.2 OKR管理的意义 1.3 Objective 1.3.1 什么是好的O 1.3.2 上下级 ...

  10. JAVA视频资料百度网盘分享

    1.javascript视频教程 链接: http://pan.baidu.com/s/1gd57FVH 密码: d9ei 2.JPA视频教程 链接: http://pan.baidu.com/s/1 ...