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 <algorithm>
#include <stack>
using namespace std; int main()
{
int T,min=;
cin>>T;
string s[T];
getline(cin,s[]);
stack<char> sta;
for(int i=;i<T;i++){
getline(cin,s[i]);
reverse(s[i].begin(),s[i].end());
if(min>s[i].length()) min=s[i].length();
}
bool isSame;
for(int i=;i<min;i++){
isSame=true;
for(int j=;j<T;j++){
if(s[j][i]!=s[][i]) isSame=false;
}
if(isSame) sta.push(s[][i]);
else break;
/**不相同直接break掉,这边是一个失误点
失误案例 abddnai
aaaanai*/
}
if(sta.empty()) cout<<"nai";
while(!sta.empty()){
cout<<sta.top();
sta.pop();
}
system("pause");
return ;
}

PAT Advanced 1077 Kuchiguse (20 分)的更多相关文章

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

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

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

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

  3. 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)

    题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...

  4. PAT Advanced 1035 Password (20 分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  5. PAT Advanced 1008 Elevator (20 分)

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...

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

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

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

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

  8. pat 1035 Password(20 分)

    1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...

  9. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

随机推荐

  1. 解析JSON有俩种方式:JSONObject和GSON

    JSONObject: //JSONObject解析JSON文件 private void parseJSONWithJSONObject(String json_data) { try { JSON ...

  2. 通过构造器配置Bean

    public class Role { private Log id; private String roleName; private String note; public Role(String ...

  3. C语言第四次实验报告

    第四次实验报告 一·实验项目名称: 多球反弹 二·实验项目功能描述: (1)实现多个小球 (2)实现多个小球碰壁会反弹 (3)实现小球之间碰撞反弹 三· 项目模块结构介绍 #define High 4 ...

  4. 使用mybatis-generator-core-1.3.2.jar根据数据库表自动生成实体

    1 导入mybatis-generator-core-1.3.2.jar 2配置mbg.xml <?xml version="1.0" encoding="UTF- ...

  5. windows的 附件到底是什么东东?

    附件, 包括其父目录"所有程序" -> "开始菜单", 其实都是一个目录而已!! 要对"开始菜单"下的所有内容进行 自定义 : 添加删 ...

  6. The file is inaccessible to Server.

    ArcGIS Unable to Start serviceserver安装后,启动服务失败,报错信息如下:Unable to Start service. Error (Server object  ...

  7. 解决hibernate 序列化死循环的问题

    用ie8时,请求json,eclipse直接死机!!!! 调试时,可以用chrome,看到无限循环的报错...类似 {"empty":true,"total": ...

  8. 第三方app抽奖发送微信红包实现

    1.控制器方法: private string SendRedPackge(string OpenId, int Amount, string LuckyCode) { Models.PayWeiXi ...

  9. 如何在linux上部署vue项目

    安装nginx的前奏 安装依赖 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 创建一个文件夹 cd /usr/ ...

  10. SpringCloud:(一)服务注册与发现

    最近跟着方志明老师学习SpringCloud,博客地址如下: https://blog.csdn.net/forezp/article/details/81040925 自己也跟着撸了一遍,纸上得来终 ...