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

 #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int N;
int main()
{
cin >> N;
string res = "", str;
vector<string>v;
int minL = ;
getchar();
for (int i = ; i < N; ++i)
{
getline(cin, str);
reverse(str.begin(), str.end());
v.push_back(str);
minL = minL < str.length() ? minL : str.length();
}
bool flag = true;
for (int i = ; i < minL && flag; ++i)
{
for (int j = ; j < N && flag; ++j)
{
if (v[][i] != v[j][i])
flag = false;
}
if (flag)
res += v[][i];
}
reverse(res.begin(), res.end());
if (res.length() == )
cout << "nai" << endl;
else
cout << res << endl; return ;
}

PAT甲级——A1077 Kuchiguse的更多相关文章

  1. PAT 甲级 1077 Kuchiguse

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

  2. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

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

  3. PAT甲级——1077.Kuchiguse(20分)

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

  4. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  5. PAT甲级题分类汇编——线性

    本文为PAT甲级分类汇编系列文章. 线性类,指线性时间复杂度可以完成的题.在1051到1100中,有7道: 题号 标题 分数 大意 时间 1054 The Dominant Color 20 寻找出现 ...

  6. PAT甲级题分类汇编——序言

    今天开个坑,分类整理PAT甲级题目(https://pintia.cn/problem-sets/994805342720868352/problems/type/7)中1051~1100部分.语言是 ...

  7. PAT甲级代码仓库

    大道至简,知易行难.希望能够坚持刷题. PAT甲级真题题库,附上我的代码. Label Title Score Code Level 1001 A+B Format 20 1001 * 1002 A+ ...

  8. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  9. PAT甲级1131. Subway Map

    PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...

随机推荐

  1. HTTP请求默认值

    填写后,后面的请求如果对应的未填写,默认使用该参数

  2. Spark应用程序

  3. nginx 知识

    nginx如何实现高并发? 启动nginx服务器后,输入 ps -ef |grep nginx,会发现nginx有一个master进程 和若干个worker进程, 这些worker进程是平等的,都是被 ...

  4. python库之mlxtend

    一.安装 conda install mlxtend --channel conda-forge 具体请看参考文献一 二.入门例子 请看参考文献2上github的举例 参考文献 http://rasb ...

  5. yii2使用vendor文件夹下的的css文件

    yii2 使用 vendor 下在css样式, 可以新建一个Asset,定义 public $sourcePath="@vendor/..",如:public $sourcePat ...

  6. Arthas 3.1.2 版本发布 | 增加 logger/heapdump/vmoption 命令

    最近偶尔有用户反馈某些 HTTP 接口出现超时问题,而 web 服务端的 Trace 监控没有出现 http 返回值为 503 等异常情况.出现这种情况一般是web容器出现问题,客户端连 Arthas ...

  7. Ros node启动与关闭

    1. ros运行单位: Ros程序运行的单位是ros node. 2. ros 节点的启动: (1)初始化ros节点:通过调用ros::init()接口实现:可以通过参数指定默认节点名字,之所以是默认 ...

  8. (转)java源程序加密解决方案(基于Classloader解密)

    转:http://cjnetwork.iteye.com/blog/851544 源程序加密解决方案 1. 概述: Java源程序的加密,有如下两种: 1使用混淆器对源码进行混淆,降低反编译工具的作用 ...

  9. 什么是存根类 Stub

    转:http://www.cnblogs.com/cy163/archive/2009/08/04/1539077.html 存根类是一个类,它实现了一个接口,但是实现后的每个方法都是空的.      ...

  10. manacher/马拉车常用用法一览

    因为manacher算法把原来的字符串扩大了两倍,因此在应用时许多二级结论都非常不直观,现场推出来很麻烦,因此笔者在此做个简单整理,如果发现有错误或者有常用的我没有涉及到的,恳请在下方评论区指出,我会 ...