A-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:
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

#include <string>
#include <iostream>
using namespace std;int main(){int n,i,j,x;cin >> n;getchar();//吸收回车int w[n]={};string str[n]={};string camp;for(i=0;i<n;i++){getline(cin,str[i]);w[i]=str[i].size();//存储每个字符串的长度}camp=str[0];//camp为比较字段x=w[0];for(i=0;i<n;i++){for(j=0;j<w[i];j++){if(camp[camp.size()-j-1]!=str[i][w[i]-j-1])break;//从末尾开始比较,如果遇到不一样的就退出这层循环}if(j<x){//此时的j为相同字段的长度,如果相同字段比原先减小的话,就要删除camp的头x-j个字符camp.erase(camp.begin(),camp.end()-j);x=j;}}if(camp.size()!=0)cout << camp;//如果camp的长度不为零就输出campelse cout << "nai";//否则输出naireturn 0;
}

A-1077 Kuchiguse (20 分)相关推荐

  1. 1077.Kuchiguse(20分)

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

  2. 1077 Kuchiguse (20分)

    并不是很复杂的判断尾部相同公共部分. 注意要保证最长相同子串要小于等于最短字符串长度: 最后一个测试点,也就是测试点4就是这种情况,其中一个字符串刚好等于公共字符串. 附本人AC代码: #includ ...

  3. 1077.Kuchiguse (20)

    1077.Kuchiguse (20) pat-al-1077 2017-01-27 本题无坑 方法:把字符串一个一个读进来,每个都逆序一下,并且在这个过程中记录一下最短的字符串的长度:然后开始对每个 ...

  4. A1077 Kuchiguse (20分)【C语言】

    A1077 Kuchiguse (20分)[C语言] 原题链接 要比较每个字符串的最后几个字母是否相同, 把字符串倒序处理会简单一点,因此先将字符串倒过来,然后以所有字符串中最短的为基准,挨个扫描是否 ...

  5. 【1077】Kuchiguse (20 分)

    #include<iostream> #include<stdio.h> #include<stdlib.h> #include<math.h> #in ...

  6. 1077. Kuchiguse (20)-PAT甲级真题

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

  7. 1077. Kuchiguse (20)

    题目如下: The Japanese language is notorious for its sentence ending particles. Personal preference of s ...

  8. 【PAT甲级】11077 Kuchiguse (20 分) Java

    题目 Java题解(最后一个测试用例没通过) import java.io.BufferedReader; import java.io.IOException; import java.io.Inp ...

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

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

最新文章

  1. pytorch量化感知训练(QAT)示例---ResNet
  2. cdn加速的原理是怎么样的
  3. 怎么把springboot部署到阿里云_听说“一分钟就能部署阿里云ECS集群”?
  4. linux nslookup 解析不到dns_涉及DNS的简单操作,只看这一篇就够了
  5. zynq开发系列3:GPIO连接MIO通过按键控制LED灯亮起
  6. Flink 1.10 Container 环境实战
  7. 如何快速的开发一个完整的iOS直播app
  8. jQuery京东分类导航菜单
  9. 气质由内而外 都市白领3个饮食排毒法则
  10. 任意用户注册任意用户密码修改
  11. (Tiled官方文档翻译)第二节:四种图层的介绍
  12. linux环境nutch的配置,linux下nutch的安装配置
  13. 戴尔服务器EMS01安装系统,PowerEdge 2950 (DC Power Supply) - EMS01
  14. GPS模块(GPS-NEO-6M)
  15. 千寻位置 开发demo_打开摄像头,2D插画实时变动画,中国程序媛出品,Demo在线可玩...
  16. GPS定位及获取卫星参数实例整理
  17. MathType到期后的解决方法
  18. .NET Framework 源码
  19. AXI4_full协议详解
  20. Wine完全使用完全指南(从初级到高级)

热门文章

  1. 5,1长假学几句英语
  2. 哈希表实现通讯录的设计与实现
  3. 【EHub_tx1_tx2_E100】Ubuntu18.04 + ROS_ Melodic + Velodyne VLP-16雷达 测试使用
  4. 蓝牙kc认证音频+数据模块推荐
  5. 蓝牙手环企业标准备案办理说明
  6. PIC芯片调试记录:配置字对程序调试和烧录后是否工作的影响,及部分应用总结
  7. DDOS攻击防护DNS篇
  8. How to Get WiFi From a Mile Away
  9. google play store的app数据分析
  10. 修改网站设置里的php版本号,Nginx服务优化(隐藏版本号、修改用户和组、设置链接超时)...