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. firebug中的console常用的方法

    firebug中的console常用的方法 1.console.log("Hello!"); --------------------显示基本信息 2.console.info(& ...

  2. HighCharts之2D饼图

    HighCharts之2D饼图 1. HighCharts之2D饼图源码 <!DOCTYPE html> <html> <head> <meta charse ...

  3. freemarker中的split字符串分割

    freemarker中的split字符串分割 1.简易说明 split分割:用来根据另外一个字符串的出现将原字符串分割成字符串序列 2.举例说明 <#--freemarker中的split字符串 ...

  4. 从1.5K到18K,一个程序员的5年成长之路

    原文地址:点击打开链接 168楼朋友批评的很有道理, 虚心接受. 我自己是开始学的时候已经错过了基础课的学习, 现在也是深受其苦的, 面临技术上的瓶颈, 需要花更多的时间补充这些知识. 希望看到此文的 ...

  5. RHEL64 缺少ISO 9660图像 安装程序试图挂载映像#1,在硬盘上无法找到该映像

    用光盘安装Linux,很容易,按照提示一步一步就好.如果没有光驱,只好想办法用硬盘或者U盘安装了. 首先说说怎样用U盘启动Linux的安装程序:1.将ISO镜像文件拷贝到U盘中,并解压到U盘根目录.将 ...

  6. freemarker基本数据类型(十一)

    freemarker基本数据类型 1.基本数据类型 (1)字符串 (2)数字 (3)布尔值 (4)日期 2.展示示例 <html> <head> <meta http-e ...

  7. cookie的初步认识

    一.会话的概念 会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. 有状态会话:一个同学来过教室,下次再来教室,我们会知道这个同学曾 ...

  8. 解决无法同步 OneNote 的问题

    在本地创建的笔记本,无法共享到云端,显示无法连接onedrive. 关闭改笔记本,重新连接共享. 参考: https://support.office.com/zh-cn/article/%E8%A7 ...

  9. 学IT应该看些书?

    第一阶段:<数据结构><数据库><算法><信息系统管理><互联网>第二阶段:<莫生气><佛经><老子>& ...

  10. Codeforces Round #467 (div.2)

    Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...