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. 通过SSH服务登陆linux服务器(版本RHEL7)

    通过SSH服务登陆linux服务器(版本RHEL7) SSH服务概述:是一种能够以安全的方式提供远程登陆的协议,也是目前远程管理linux系统的首选方式.在此之前,我们一般使用FTP或者telnet来 ...

  2. 20155232 2016-2017-3 《Java程序设计》第3周学习总结

    20155232 2016-2017-3 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 认识对象 1.对象(Object):存在的具体实体,具有明确的状态和行为. 2.类( ...

  3. SQLite3日期与时间,常见函数

    SQLite3日期与时间,常见函数 import sqlite3 #con = sqlite3.connect('example.db') con = sqlite3.connect(":m ...

  4. Apache入门篇(四)之LAMP架构部署

    一.LAMP解析 a: apachem: mariadb, mysqlp: php, perl, python 静态资源:静态内容:客户端从服务器获得的资源的表现形式与原文件相同:动态资源:通常是程序 ...

  5. RegExp,实现匹配合法邮箱(英文邮箱)的正则表达式

    邮箱列表:@qq.com.@vip.qq.com.@foxmail.com,数字邮箱暂时不考虑 以下邮箱列表用于测试: lihaha@qq.com lihaha@vip.qq.com lihaha@f ...

  6. 一个经典的PHP加密解密算法authcode

    项目中有时我们需要使用PHP将特定的信息进行加密,也就是通过加密算法生成一个加密字符串,这个加密后的字符串可以通过解密算法进行解密,便于程序对解密后的信息进行处理.最常见的应用在用户登录以及一些API ...

  7. 验证码示例代码演示——以php为例

    运行 · 修改index.php(图片验证码的生成示例) [html] view plain copy initNECaptcha({ captchaId: 'YOUR_CAPTCHA_ID', // ...

  8. PL/SQL编辑数据"这些查询结果不可更新,请包括ROWID或使用SELECT...FOR UPDATE获得可更新结果"处理

    只要有人用了: select t.* from 表名  t where 字段=xxx  for update 而不是: select t.rowid,t.* from 表名  t where 字段=x ...

  9. 【转】在Android Studio中下载Android SDK的两种方式(Android Studio3.0、windows)

    在Android Studio中下载Android SDK的两种方式(Android Studio3.0.windows) 方式一.设置HTTP Proxy1. 打开Settings2. 点击HTTP ...

  10. Ubuntu常用shell命令

    目录 ls cd mkdir mv cp scp rm df du chmod chown chgrp head tail screen apt-get Ubuntu常用shell命令 Ubuntu作 ...