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. CodeChef Little Elephant and Balance

    Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that L ...

  2. K The Right-angled Triangles

    链接:https://ac.nowcoder.com/acm/contest/338/K来源:牛客网 题目描述 Consider the right-angled triangles with sid ...

  3. 图标,空格,大小尖括号,段落,换行,标题,div白板,span白板

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. NGUI技能CD效果制作(sprite的type:filled)

    一,我们先添加一个sprite,改名为skill.给当前skill添加图片,然后再sprite下添加一个sprite和一个label,结果如下 二现在我们来设置skill下的sprite,给他设置一个 ...

  5. android&iOS设计分辨率

    --- iPhone --- iPhone SE 1136 * 640 2.0875 iPhone 6 1334 * 750 1.778666666666667 iPhone X 2436 * 112 ...

  6. 微信小程序(17)-- RSA加密 解密 加签 验签

    RSA加密 解密 加签 验签 /** * 注:区分RSA私钥的类型,有pkcs1和pkcs8.pkcs8格式的私钥主要用于Java中 pkcs1格式: -----BEGIN RSA PRIVATE K ...

  7. Kotlin学习笔记(9)- 数据类

    系列文章全部为本人的学习笔记,若有任何不妥之处,随时欢迎拍砖指正.如果你觉得我的文章对你有用,欢迎关注我,我们一起学习进步! Kotlin学习笔记(1)- 环境配置 Kotlin学习笔记(2)- 空安 ...

  8. 运行rabbitmq

    docker run -d -p 5672:5672 -p 15672:15672 --name myrabbitmq c4663bdca2cd

  9. Ubuntu分区小知识与分区方案

    Most PC operating systems still work with an ancient disk partition scheme that historically makes d ...

  10. Linux任务计划at

    Linux任务计划at 一Linux任务计划介绍 Linux任务计划.周期性任务执行at:未来的某时间点执行一次任务batch:系统自行选择空闲时间去执行此处指定的任务cron:周期性运行某任务 二a ...