https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096

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 <bits/stdc++.h>
using namespace std; char s[111][300], out[1111];
int len[111]; int main() {
int N;
scanf("%d", &N);
getchar();
for(int i = 1; i <= N; i ++) {
cin.getline(s[i], 300);
} int minn = 333;
for(int i = 1; i <= N; i ++) {
len[i] = strlen(s[i]); for(int j = 0; j <= len[i] / 2 - 1; j ++)
swap(s[i][len[i] - j - 1], s[i][j]); if(len[i] < minn) {
minn = len[i];
continue;
}
} int cnt = -1;
for(int j = 0; j < minn; j ++) {
int flag = 1;
for(int i = 1; i <= N; i ++) {
if(s[i][j] != s[1][j]) flag = 0;
}
if(flag == 0) break;
cnt = j;
} if(cnt != -1) {
for(int i = cnt;i >= 0; i --) {
printf("%c", s[1][i]);
}
printf("\n");
}
else
printf("nai\n"); return 0;
}

  

PAT 甲级 1077 Kuchiguse的更多相关文章

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

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

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

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

  3. PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】

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

  4. PAT Advanced 1077 Kuchiguse (20 分)

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

  5. PAT甲级——A1077 Kuchiguse

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

  6. PAT 1077 Kuchiguse

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

  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 [一般]

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

  9. pat 1077 Kuchiguse(20 分) (字典树)

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

随机推荐

  1. STM32 SIM800C SIM868 连接OneNet 以及远程控制流程详解

    Onenet控制继电器教程 本文基于STM32物联网开发版:https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.29e71debNLqzW ...

  2. SQL 去重 显示第一条数据 显示一条数据

    需求描述:根据某一个字段或几个字段去重来显示任一条数据,第一条或最后一条. 数据样式如下图: 尝试解决: --count(*)方法(只把条数为1条的显示出来了,超过1条全部过滤了) select * ...

  3. shiro实战整合

    引入依赖(包括缓存等): <!-- SECURITY begin --> <dependency> <groupId>org.apache.shiro</gr ...

  4. 20155230 2016-2017-2 《Java程序设计》第三周学习总结

    ---恢复内容开始--- 20155230 张瑞琦 2016-2017-2 <Java程序设计>第三周学习总结 教材学习内容总结 1.使用浮点数时用equals()进行比较,否则会出错. ...

  5. 20155331 丹增旦达 2006-2007-2 《Java程序设计》第二周学习总结

    20155331 丹增旦达 2006-2007-2 <Java程序设计>第二周学习总结 教材学习内容总结 一 ,类型.变量与运算符 一.数据类型 1, 分类: 基本数据类型 byte:字节 ...

  6. Ubuntu genymotion

    官网注册帐号 下载genymotion-[VERSION]_[ARCH].bin 进入android studio In Android Studio, go to File > Setting ...

  7. maven 发布springboot项目

    1.把Spring Boot打包成JAR的形式,需要在pom.xml文件对应以下代码 <build> <finalName>ljl</finalName> //打包 ...

  8. pytest使用笔记(一)

    使用环境及预置条件:pycharm+win10+python3.6+pytest 1,创建示范的测试功能脚本,另存为test_sample.py,代码如下: # test_sample.py def ...

  9. 小白初识 - 快速排序(QuickSort)

    我个人觉得快速排序和归并排序有相似之处,都是用到了分治的思想,将大问题拆分成若干个小问题. 不同的地方是归并排序是先把大问题拆分好了之后再排序,而快速排序则是一边拆分,一边排序. 快速排序的原理就是, ...

  10. openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 三

    openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 一 openstack-r版(rocky)搭建基于centos7.4 的openstac ...