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. 硬盘GPT分区与MBR分区的转换

    如何将gpt分区更改成mbr分区? "因为笔记本电脑硬盘分区表是GPT而导致大家无法安装引导系统.需要转换为MBR分区还能顺利安装." 问题是,分区工具无法转换MBR,这里小编知道 ...

  2. HTML5可以省略结束标记的元素

    HTML5可以省略结束标记的元素 1.dd 2.dt 3.li 4.p 5.optgroup 6.option 7.rt 8.rp 9.thread 10.tfoot 11.tr 12.td 13.t ...

  3. 采用Global.asax的Application_BeginRequest事件过滤敏感字符

    1.特殊字符过滤公共类ProcessRequest.cs using System.Web.UI; using System.Web.UI.WebControls; using System.Web. ...

  4. Tomcat 代码方式启动

    配置好参数,只需在Booter类中调用 EmbbedTomcat.main(args); 就可以启动. maven中也需要配置相应插件. import java.io.File; import org ...

  5. C# 图解教程 第四章 类的基本概念

    类的基本概念 类的概述声明类 类成员字段方法 创建变量和类的实例为数据分配内存实例成员访问修饰符 私有访问和公用访问 从类的内部访问成员从类的外部访问成员综合应用 类的基本概念 类的概述 类是一种活动 ...

  6. Android热修复技术原理详解(最新最全版本)

    本文框架 什么是热修复? 热修复框架分类 技术原理及特点 Tinker框架解析 各框架对比图 总结   通过阅读本文,你会对热修复技术有更深的认知,本文会列出各类框架的优缺点以及技术原理,文章末尾简单 ...

  7. python访问mysql和redis

    1. 修改mysql配置文件 修改bind-address=0.0.0.0(允许通过远程网络连接) 2. 修改redis配置文件 修改bind-address=0.0.0.0(允许通过远程网络连接), ...

  8. JavaScript保留关键字2。

    一些不做解释的关键字是在js中预留的东西. abstract 抽象  . arguments  参数 标识符arguments是指向实参对象的引用,实参对象是一个类数组对象. boolean 布尔值. ...

  9. Angular通过订阅观察者对象实现不同组件中数据的实时传递

    在angular官方定义中,组件直接的数据交换只要在父子直接传递,但是我们在项目中经常需要在各种层级之间传递数据,下面介绍关于订阅可观察对象实现的数据传递. 首先定义一个服务app.sevice.ts ...

  10. 【BZOJ2818】Gcd(莫比乌斯反演)

    [BZOJ2818]Gcd(莫比乌斯反演) 题面 Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的 数对(x,y)有多少对. Input 一个整数N Ou ...