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. DRF 外键字段深度查询优化、ListSerializer辅助完成群改

    目录 一.Response封装 二.外键字段深度查询 1.序列化配置exclude.depth 2.模型层函数.插拔式字段查询 三.listserializer辅助类 一.Response封装 用de ...

  2. 2021-2-27:Linux 下如何优化 Java MMAP 写入

    主要是调整 pdflush 相关参数. 在linux操作系统中,写操作是异步的,即写操作返回的时候数据并没有真正写到磁盘上,而是先写到了系统cache里,随后由pdflush内核线程将系统中的脏页写到 ...

  3. Docker SDK for Python

    一.概述 Docker引擎API的Python库.它允许您执行docker命令所做的任何操作,但可以在Python应用程序中运行容器.管理容器.管理群集等. 官方文档: https://docker- ...

  4. InnoDB存储引擎——页和记录(行)

    一.InnoDB页 InnoDB是一个将表中的数据存储到磁盘上的存储引擎,所以即使关机后重启我们的数据还是存在的.而真正处理数据的过程是发生在内存中的,所以需要把磁盘中的数据加载到内存中,如果是处理写 ...

  5. DCL之单例模式

    所谓的DCL 就是 Double Check Lock,即双重锁定检查,在了解DCL在单例模式中如何应用之前,我们先了解一下单例模式.单例模式通常分为"饿汉"和"懒汉&q ...

  6. 【转】理解Serverless

    理解Serverless No silver bullet. - The Mythical Man-Month 许多年前,我们开发的软件还是C/S(客户端/服务器)和MVC(模型-试图-控制器)的形式 ...

  7. 653. 两数之和 IV - 输入 BST + HashSet

    653. 两数之和 IV - 输入 BST 题目描述 题解分析 最简单的方法就是遍历整棵树,找出所有可能的组合,判断是否存在和为 kk 的一对节点.现在在此基础上做一些改进. 如果存在两个元素之和为 ...

  8. 2.2 Python3基础-基本数据类型

    >>返回主目录 源代码 # 基本数据类型 # Number类型:如何查看变量的数据类型? name = 'Portos' print(type(name)) # 结果:str print( ...

  9. MySQL日志收集之Filebeat和Logstsh的一键安装配置(ELK架构)

    关于ELK是什么.做什么用,我们不在此讨论.本文重点在如何实现快速方便地安装logstash和filebeat组件,特别是在近千台DB Server的环境下(为了安全保守,公司DB Server 目前 ...

  10. 漏洞复现-CVE-2017-4971-Spring Web Flow 远程代码执行

            0x00 实验环境 攻击机:Win 10 靶机也可作为攻击机:Ubuntu18 (docker搭建的vulhub靶场)(兼顾反弹shell的攻击机) 0x01 影响版本 Spring ...