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 ...
随机推荐
- java->php之在线子域名查询-接口光速版
因为不懂java,所以 用php重写了大佬的 在线子域名查询-接口光速版 http://sbd.ximcx.cn/ 这是大佬的 然后 改一下 ,用php 其实就是改了几行代码而已,jquery和aj ...
- 关于LP64,ILP64,LLP64,ILP32,LP32字长(数据)模型
太长不看: 1.32位Windows和类Unix使用ILP32字长模型,64位Windows使用ILP64模型,64位类Unix使用LP64字长模型. 2.根据1,long在32位和64位Window ...
- 20155315 2016-2017-2 《Java程序设计》第二周学习总结
教材学习内容总结 在教材中,有一句话叫做 伪代码是最好的注释. 一开始我不理解什么是伪代码,但在参考了百度和C语言的学习过程后,我发现伪代码的作用就相当于是解决问题前期的流程图设计,伪代码设计好了之后 ...
- 如何指定rman下的备份路径
如果不想使用缺省路径,可以以如下方式来指定: RMAN> configure channel 1 device type disk format '/rman/bak/%F';RMAN> ...
- DataGrid中Combox bingding string
DataGrid列中绑定Combox 正常情况下的Combox绑定回传不会失效:但是在DataGrid中选择Combox属性后不会回传:即调用Set属性 如图中的模板: 显示的方式有三种: 第一种: ...
- JDBC处理大数据
1.处理大文本 package com.demo; import java.io.File; import java.io.FileNotFoundException; import java.io. ...
- Django-建立网页
进入cmd模式做 django-admin startproject helloworld创建一个project,并命名helloworld,新生成的文件结构如下 输入python manage. ...
- Jenkins Git安装设置
Jenkins Git安装设置 在此安装中,必须确保Internet连接可连接其安装 Jenkins 机器.在 Jenkins 仪表盘(主屏幕)的左侧单击 Manage Jenkins 选项.打开网址 ...
- Numpy入门笔记第一天
# 导入包 import numpy as np # 创建一维数组 a = np.arange(5) print "一维numpy数组", a print "数组的类型& ...
- mysql把一字段拆分为多行
sql语句 select a.house_no as '房子',substring_index(substring_index(a.name,',',b.help_topic_id+1),',',-1 ...