Source:

PAT A1077 Kuchiguse (20 分)

Description:

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

Keys:

  • 模拟题

Attention:

  • s.insert(s.begin()+pos, str[i]),s.insert(pos, str)
  • 使用getline(cin,str),注意吃掉上一行的换行符

Code:

 #include<cstdio>
#include<string>
#include<iostream>
using namespace std; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
string s,t;
scanf("%d\n", &n);
getline(cin,s);
for(int i=; i<n; i++)
{
getline(cin,t);
string p;
int ps=s.size()-,pt=t.size()-;
while(ps>= && pt>= && s[ps]==t[pt])
{
p.insert(p.begin(),s[ps]);
ps--;
pt--;
}
s = p;
}
if(s.size())
cout << s;
else
printf("nai"); return ;
}

PAT_A1077#Kuchiguse的更多相关文章

  1. 1077. Kuchiguse (20)

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

  2. PAT1077: Kuchiguse

    1077. Kuchiguse (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming The Japan ...

  3. PAT 1077 Kuchiguse

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

  4. A1077. Kuchiguse

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

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

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

  6. 1077 Kuchiguse (20 分)

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

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

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

  8. PAT 甲级 1077 Kuchiguse

    https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...

  9. PAT 1077 Kuchiguse [一般]

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

随机推荐

  1. LCT题单(自己的做题情况反馈)(转自Flash)

    LCT题单(自己的做题情况反馈)(转自Flash) 随时进Flash Hu的LCT看一发 也可以看一下我自己的风格的板子 开始 维护链信息(LCT上的平衡树操作) [X] 洛谷P3690 [模板]Li ...

  2. mt-picker 样式修改

    // html : <div class="applyInformations" @click="chooseSex"> <p>性别&l ...

  3. C# IEnumerable与IQueryable ,IEnumerable与IList ,LINQ理解Var和IEnumerable

    原文:https://www.cnblogs.com/WinHEC/articles/understanding-var-and-ienumerable-with-linq.html 使用LINQ从数 ...

  4. npm run dev 报错:Error: Cannot find module 'webpack-cli/bin/config-yargs'

    使用 npm run dev 时报错: Error: Cannot find module 'webpack-cli/bin/config-yargs' 原因是找不到webpack-cli这个包,使用 ...

  5. Java疯狂讲义笔记——内部类

    [定义]内部类:定义在其它类内部的类.外部类:包含内部类的类,也称 宿主类.局部内部类:定义在方法里的内部类. [接口内部类]接口中也可以定义内部类,必须为public static修饰(自动添加), ...

  6. linux的iptables设置---防火墙

    1.首先介绍一下指令和相关配置文件 启动指令:service iptables start 重启指令:service iptables restart 关闭指令:service iptables st ...

  7. django项目中账号注册登陆使用JWT的记录

    需求分析 1.  注册用JWT做状态保持    1.1 安装jwt    pip install djangorestframework-jwt        1.2 去settings里面配置jwt ...

  8. java 接口概念及使用

    package java11; /* 在任何版本的java中,接口都能定义抽象方法 格式: public abstrace 返回值类型 方法名称(参数列表): 注意事项: 1.接口当中的抽象方法,修饰 ...

  9. python基础:2.二进制

    1.二进制:计算机存储0,1的一种方式,规则是逢2进1. 一个数字在计算机存储的是一个字节,即8个bit,每个bit要么存储0,要么存储1. 0000 0000 (二进制)表示 0(十进制), 000 ...

  10. oracle多表连接方式Hash Join Nested Loop Join Merge Join

    在查看sql执行计划时,我们会发现表的连接方式有多种,本文对表的连接方式进行介绍以便更好看懂执行计划和理解sql执行原理. 一.连接方式:        嵌套循环(Nested  Loops (NL) ...