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. ES排序值相同顺序随机的问题

    ES排序值相同顺序随机的问题 code[class*="language-"] { padding: .1em; border-radius: .3em; white-space: ...

  2. C# Socket-TCP异步编程原理详解附源码

    目录 目录异步原理主要方法源码Server源码:Client源码实验效果(广播为例)参考博客 TOC 异步原理 套接字编程原理:延续文件作用思想,打开-读写-关闭的模式. C/S编程模式如下: Ø 服 ...

  3. @清晰掉 Sizeof与字符串

    Sizeof与字符串 1.以字符串形式出现的,编译器都会为该字符串自动添加一个0作为结束符 如在代码中写  "abc",那么编译器帮你存储的是"abc/0" 2 ...

  4. 复选框checked 选中后不显示打钩

    复选框checked 选中后不显示打钩 checkbox属性checked="checked"已有,但复选框却不显示打钩的原因   复选框绑定了click事件,点一次选中,再点击取 ...

  5. 使用resultMap定义查询结果集,实现关联查询

    接下来介绍resultMap定义查询结果集,实现关联查询 1 首先在接口中定义操作的方法 public interface EmployeeMapperPlus { public Employee g ...

  6. 64位ubuntu下安装ia32-libs

    echo "deb http://archive.ubuntu.com/ubuntu/ raring main restricted universe multiverse" &g ...

  7. Microsoft:Team Foundation Server 20XX Release Notes

    ylbtech-Microsoft:Team Foundation Server 2017 Release Notes 1.返回顶部 1. https://docs.microsoft.com/en- ...

  8. seleniumIDE回放找不到页面元素

    seleniumIDE回放找不到页面元素 如下所示,自动回放就报错,手动执行就不报错.

  9. WPF DevExpress Chart控件 需要引用的类库

    DevExpress.Charts.v16.1.Core.dll DevExpress.Data.v16.1.dll DevExpress.Mvvm.v16.1.dll DevExpress.Xpf. ...

  10. wpf slider刻度

    TickFrequency:刻度之间的间隔   IsSnapToTickEnabled:是否对齐到刻度   TickPlacement:刻度位置