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<=N<=100). 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 main()
{
int n,num;
cin>>n;
cin.get();
vector<string> vi;
string s;
string a="";
num=n;
while(num--)
{
getline(cin,s);
vi.push_back(s);
}
for(int i=vi[0].size()-1,j=vi[1].size()-1;i>=0&&j>=0;i--,j--)//因为初始,最小也有2
{
if(vi[0][i]!=vi[1][j])//如果末尾2个不相等
{
break;
}
else
{
a+=vi[0][i];
}
}//这样就得到了末尾最长的可能性的语气词
reverse(a.begin(),a.end());//这里要注意得到的字符串是倒叙的,需要用到algorithm里面的反转字符串的函数
if(n==2&&a.size()==0)
{
cout<<"nai"<<endl;
return 0;
}
if(n==2&&a.size()>0)
{
cout<<a<<endl;
return 0;
}
//接下去就是大于2的情况了,全在a上面做文章
string cun=a;
for(int t=2;t<vi.size();t++)//剩下那么多的string,进行比较
{
a="";
for(int i=cun.size()-1,j=vi[t].size()-1;i>=0&&j>=0;i--,j--)//这里出错了,调试的发现问题,在于第二个判断条件,应该是都成立的情况下
{
if(cun[i]!=vi[t][j])
{
break;
}
else
{
a+=cun[i];
}
}
reverse(a.begin(),a.end());
cun=a;
}//最后得到的cun,就是最后要的语气词

if(cun.size()==0)
{
cout<<"nai"<<endl;
return 0;
}
else
{
cout<<cun<<endl;
}

return 0;
}

转眼之间,我转行已经7个月了,自学了4个月,试用了3个月,总算顺利的转正成功了。算是正式迈向了程序员的道路上。如果恰好你也是转行看到我这段话,我希望你不要担心,低下头往前走,就行了。心里的焦虑,不安,都会随着时间,流去。努力下,时间会给你想要的答案。

转行而已,不简单,也不难。因为是在国企,下班有足够的学习时间,这段时间刷完了pat,再去刷TCP/IP,数据结构和算法。再补一补C++的模板类范例编程之类的吧。感觉工作中,这种用的都不是太多。

1077. Kuchiguse (20)的更多相关文章

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

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

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

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

  3. PAT Advanced 1077 Kuchiguse (20 分)

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

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

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

  5. PAT (Advanced Level) 1077. Kuchiguse (20)

    最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...

  6. PAT甲题题解-1077. Kuchiguse (20)-找相同后缀

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

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

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

  8. PAT 1077 Kuchiguse

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

  9. 1077 Kuchiguse (20 分)

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

随机推荐

  1. R语言︱排序问题

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 数据排序 1.sort(),rank(),or ...

  2. INS-20802

    1.错误描述 2.错误原因 安装的是64位数据库,由于在设置数据库配置密码时用的是数字开头,取消时出现这个错误 3.解决办法 重新安装Oracle

  3. MFC中CFileDialog用法

    用CFileDialog选择了一个文件后,使用FILE::fopen打开文件错误,使用 的是相对地址,和王工调试了半天,怎么跟踪也没发现错误,原来如此......... CFileDialog文件选择 ...

  4. org.hibernate.MappingException:Unknown entity:java.util.ArrayList

    1.错误描述 [CQ] ERROR [http-apr-8888-exec-3] com.opensymphony.xwork2.util.logging.commons.CommonsLogger. ...

  5. Array.from()

    es6 Array.from() 方法将两类对象转为真正的数组 用法:用于将两类对象转为真正的数组:类似数组的对象和可遍历(iterable)的对象(包含ES6新增的数据结构Set和Map); 说明: ...

  6. Error Correct System CodeForces - 527B

    Ford Prefect got a job as a web developer for a small company that makes towels. His current work ta ...

  7. 异常-----springmvc + ajaxfileupload解决ajax不能异步上传图片的问题。java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.

    说明这个问题产生的原因主要是form表单上传图片的时候必须是Content-Type:"multipart/form-data,这种格式的,但是ajax在页面不刷新的情况下去加载的时候只会把 ...

  8. 【原】如何获取Java动态生成类?

    写作目的:Java大部分框架,如Spring,Hibernate等都会利用动态代理在程序运行的时候生成新的类, 有的时候为了学习,或者深入了解动态代理,想查看动态生成类的源代码究竟长怎么个样子, 通过 ...

  9. 【BZOJ4010】【HNOI2015】菜肴制作(拓扑排序)

    [BZOJ4010][HNOI2015]菜肴制作(拓扑排序) 题面 Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为 ...

  10. 【洛谷T7153】(考试) 中位数

    题目描述 给定 n 个数 a1, a2, ..., an,求这 n 个数两两的差值(共 n(n−1) 2 个)的中位数. 输入格式: 第一行一个正整数 n,表示数的个数. 接下来一行 n 个正整数,分 ...