1077 Kuchiguse (20 分)

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:

  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
  2.  
  3. 分析: 求字符串的公共后缀。思路是先逆置字符串,然后从第一个开始比较。
  1. /**
  2. * Copyright(c)
  3. * All rights reserved.
  4. * Author : Mered1th
  5. * Date : 2019-02-24-21.51.09
  6. * Description : A1077
  7. */
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<iostream>
  11. #include<cmath>
  12. #include<algorithm>
  13. #include<string>
  14. #include<unordered_set>
  15. #include<map>
  16. #include<vector>
  17. #include<set>
  18. using namespace std;
  19. ;
  20. string a[maxn];
  21. int main(){
  22. #ifdef ONLINE_JUDGE
  23. #else
  24. freopen("1.txt", "r", stdin);
  25. #endif
  26. ;
  27. cin>>n;
  28. getchar();
  29. ;i<n;i++){
  30. getline(cin,a[i]);
  31. int len=a[i].size();
  32. if(minlen>len) minlen=len;
  33. reverse(a[i].begin(),a[i].end());
  34. }
  35. string ans="";
  36. ;i<minlen;i++){
  37. ][i];
  38. bool same=true;
  39. ;j<n;j++){
  40. if(c!=a[j][i]){
  41. same=false;
  42. break;
  43. }
  44. }
  45. if(same) ans+=c;
  46. else break;
  47. }
  48. if(ans.size()){
  49. reverse(ans.begin(),ans.end());
  50. cout<<ans;
  51. }
  52. else{
  53. cout<<"nai";
  54. }
  55. ;
  56. }

1077 Kuchiguse (20 分)的更多相关文章

  1. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

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

  2. PAT Advanced 1077 Kuchiguse (20 分)

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

  3. PAT甲级——1077.Kuchiguse(20分)

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

  4. 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)

    题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...

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

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

  6. 1077. Kuchiguse (20)

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

  7. PAT (Advanced Level) 1077. Kuchiguse (20)

    最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...

  8. PAT甲题题解-1077. Kuchiguse (20)-找相同后缀

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  9. PAT 1077 Kuchiguse

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

随机推荐

  1. iOS ipv6 被拒

    1.检查你所用到的库,像af 3.0以上什么的(不用改),其他的库自己去搜下是否支持ipv6吧. 2.确保你用的sdk支持ipv6,这个自己去看文档就行. 3.终端  dig +nocmd + nos ...

  2. L242

    They provide a means of keeping track of the thousands of journal papers that are published monthly ...

  3. 优化cocos2d/x程序的内存使用和程序大小

    本站文章均为李华明Himi原创,转载务必在明显处注明:转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/iphone-cocos2d/1043.html ☞ ...

  4. 安装 Java 6

    从服务器下载 Linux 64位 jdk 到本地.下载地址:\\192.167.100.225\share\Tool\JAVA\jdk-6u34-linux-x64.bin 给安装文件添加执行权限 $ ...

  5. stm32 SPI介绍和配置

    SPI是一种高速的,全双工同步的通信总线,在芯片管脚上占用了四根线,节约了芯片的管脚,同时为PCB的布局节省了空间,提供了方便,因此越来越多的芯片集成了这种通信协议,STM32也就有了SPI接口. 有 ...

  6. python--selenium实用的自动生成测试HTML报告方法--HTMLTestRunner

    python--selenium实用的自动生成测试HTML报告方法--HTMLTestRunner 下面给大家介绍下用HTMLTestRunner模块自动生成测试报告的方法. 一.首先我们导入unit ...

  7. Cannot find config.m4. Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module的 解决方法

    cp /php-7.1.22/ext/openssl/config0.m4 /usr/local/php/bin/config.m4

  8. Linux设备树使用(二)

    一.设备树与驱动的匹配1.设备树会被/scripts中的dtc可执行程序编译成二进制.dtb文件,之前设备树中的节点信息会以单链表的形式存储在这个.dtb文件中:驱动与设备树中compatible属性 ...

  9. Makefile在内核编译中的使用

    1.一个配置选项选中多个文件 path:drivers/media/i2c/adv748x adv748x-objs := \ adv748x-afe.o \ adv748x-core.o \ adv ...

  10. solr学习二(ExtractingRequestHandler)

    通过ExtractingRequestHandler,slor能够读取word.pdf等文件,并用于全文搜索.废话少说,进入主题:     solr服务端是配出来的:     solrconfig.x ...