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:

  1. 3
  2. Itai nyan~
  3. Ninjin wa iyadanyan~
  4. uhhh nyan~
 

Sample Output 1:

  1. nyan~
 

Sample Input 2:

  1. 3
  2. Itai!
  3. Ninjinnwaiyada T_T
  4. T_T
 

Sample Output 2:

  1. nai

题意:

  找出最长公共后缀。

思路:

  模拟。

Code:

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int n;
  7. cin >> n;
  8. getchar();
  9. string last, cur, temp;
  10. for (int i = 0; i < n; ++i) {
  11. if (i == 0)
  12. getline(cin, last);
  13. else {
  14. temp = "";
  15. getline(cin, cur);
  16. int len1 = cur.length() - 1;
  17. int len2 = last.length() - 1;
  18. while (len1 >= 0 && len2 >= 0) {
  19. if (cur[len1--] == last[len2]) {
  20. temp = last[len2--] + temp;
  21. } else
  22. break;
  23. }
  24. last = temp;
  25. }
  26. }
  27. if (last.length() == 0)
  28. cout << "nai" << endl;
  29. else {
  30. for (int i = 0; i < temp.length(); ++i) cout << temp[i];
  31. cout << endl;
  32. }
  33. return 0;
  34. }

077 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. jquery动态赋值id与动态取id方法

    $("#" + packageNameId + "").text(packageName); $("#" + packageNumId + ...

  2. 无需编程,通过配置零代码生成CRUD RESTful API

    Hello,crudapi!(你好,增删改查接口!) 本文通过学生对象为例,无需编程,通过配置实现CRUD RESTful API. 概要 CRUD简介 crud是指在做计算处理时的增加(Create ...

  3. C++ 中的虚函数表及虚函数执行原理

    为了实现虚函数,C++ 使用了虚函数表来达到延迟绑定的目的.虚函数表在动态/延迟绑定行为中用于查询调用的函数. 尽管要描述清楚虚函数表的机制会多费点口舌,但其实其本身还是比较简单的. 首先,每个包含虚 ...

  4. 2020年12月-第02阶段-前端基础-CSS初识

    CSS层叠样式表 理解 css的目的作用 css的三种引入方式 1.HTML的局限性 说起HTML,这其实是个非常单纯的家伙, 他只关注内容的语义, 比如`<h1>`表明这是一个大标题,用 ...

  5. 用vue.js实现的期货,股票的实时K线

    用vue.js实现的期货,股票的实时k线 项目地址:https://github.com/zhengquantao/vue-Kline vue-kline 效果图 Build Setup 本项目基于V ...

  6. python3中post和get请求处理

    post 请求处理 def url(): url = "www.xxx.com.cn" data = { "csrfmiddlewaretoken":" ...

  7. 漫漫Java路1—基础知识—初涉java

    前言 主学信息安全,在编程的路上还是一个孩子,还在一步一步探索,有些东西可能是站在自己的位置思考的,很可能会出现一些啼笑皆非的错误,如果有误,还希望各位斧正. Java安装 jdk的安装 甲骨文官网选 ...

  8. 测试工程师Docker基础

    一.docker概述 1.docker为什么会出现 本质:所有技术的出现都是因为出现了一些问题,我们需要去解决,才去研究和学习: 问题: ​ 开发环境.测试环境.仿真环境.正式环境等诸多环境都需要进行 ...

  9. 内置了一个缓冲区(数组)缓冲流BufferInputStream为何要配合字节数组的使用?

    内置了一个缓冲区(数组)缓冲流BufferInputStream为何要配合字节数组的使用? 只为效率而积累[积少成多送一趟比送多趟快] 举例子:超市买30个鸡蛋回家煮 (1)读一个送一个(效率太低啦) ...

  10. Git Fetch failed解决办法

    Git 下拉过程中,电脑死机了,重启后出现问题 找到的解决办法 https://blog.csdn.net/qq_33330887/article/details/80242206