PAT 甲级 1077 Kuchiguse
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的更多相关文章
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT甲级——1077.Kuchiguse(20分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- PAT Advanced 1077 Kuchiguse (20 分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT甲级——A1077 Kuchiguse
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT 1077 Kuchiguse
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise
题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...
- PAT 1077 Kuchiguse [一般]
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- pat 1077 Kuchiguse(20 分) (字典树)
1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
随机推荐
- 用python实现购物车功能
"""功能要求:1.要求用户输入自己拥有的总资产,例如:20002.显示商品列表的序号,商品名称,商品价格,让用户根据序号选择商品,然后加入购物车 例如: 1 电脑 19 ...
- 目标反射回波检测算法及其FPGA实现 之一:算法概述
目标反射回波检测算法及其FPGA实现之一:算法概述 前段时间,接触了一个声呐目标反射回波检测的项目.声呐接收机要实现的核心功能是在含有大量噪声的反射回波中,识别出发射机发出的激励信号的回波.我会分几篇 ...
- 20155211 2016-2017-2《Java程序设计》课程总结
20155211 2016-2017-2<Java程序设计>课程总结 (按顺序)每周作业链接汇总 预备作业1:对师生关系的理解 预备作业2:熟能生巧及学习c语言的心的 预备作业3:关于假期 ...
- 20155317 王新玮 2006-2007-2 《Java程序设计》第4周学习总结
20155317 王新玮 2006-2007-2 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 继承共同行为 多个类中存在相同属性和行为时,将这些内容抽取到单独一个类中,那 ...
- 客户端与服务器端同步Evernote
原文地址:http://www.zhihu.com/question/20238731 Evernote的同步方式是 以本地为基准同步到网络 还是 以网络为基准同步到本地 的? 若客户端从未与服务器端 ...
- 【洛谷P2252】取石子游戏
题面 题解 威佐夫博弈 代码 #include<cstdio> #include<algorithm> #include<cmath> #define RG reg ...
- 创龙6748开发板加载.out出现a data verification error occurred, file load failed
1. 需要提前添加GEL文件 2. 找到GEL文件路径 3. 然后再加载.out文件
- activeX 打包
原文 http://www.docin.com/p-409284488.html CAB打包文档说明 文档目的 本文档的目的在于说明将ocx和dll以及相关的文件打包成一个CAB包,以便在网页下调用o ...
- python基本数据类型2
python_day_4 今日大纲: 1. list(增删改查) 列表可以装大量的数据. 不限制数据类型. 表示方式:[] 方括号中的每一项用逗号隔开 列表和字符串一样.也有索引和切片 常用的功能: ...
- TensorFlow深度学习实战---循环神经网络
循环神经网络(recurrent neural network,RNN)-------------------------重要结构(长短时记忆网络( long short-term memory,LS ...