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 ...
随机推荐
- ruby 记一次查看方法定义位置
今天在回头看JSON类的时候,发现有一个语法特别诡异 JSON(str),一开始以为是一种类的特殊语法,结果问了群里大神才知道,就是定义了一个JSON(str)方法,但是我没有找到定义该方法的地方,问 ...
- PTA(BasicLevel)-1007素数对猜想
一 问题描述-素数对 让我们定义素数差dn为:dn=pn+1−pn,其中pi是第i个素数.显然有d1=1,且对于n>1有dn是偶数.“素数对猜想”认为“ ...
- C# typeof() 和 GetType()区是什么
1.typeof(x)中的x,必须是具体的类名.类型名称等,不可以是变量名称. 2.GetType()方法继承自Object,所以C#中任何对象都具有GetType()方法,它的作用和typeof() ...
- Linux入门第五天——shell脚本入门(中)基础语法之判断与条件
一.判断式 利用 test 命令进行执行结果的判断(例如判断是否存在该文件):关于test test:test 示例:结合回传值 $? 进行判断:关于$?:$? [root@localhost tm ...
- 第三次随笔——虚拟机及Linux入门
虚拟机及Linux入门 虚拟机的安装 对于虚拟机的概念我早有接触,但是从来没有真正的实践过,借这次作业机会我终于实践了虚拟机的安装,安装的过程较为顺利,但还是出现了以下问题: 无法选择64位的系统 解 ...
- 课上实践练习——MyOd
编写MyOD.java 用java MyOD XXX实现Linux下od -tx -tc XXX的功能 Linux下od -tx -tc XXX的功能 1.功能 od命令用于将指定文件内容以八进制.十 ...
- 【SHOI2008】堵塞的交通
题面 题解 这里提供几种不用脑子的算法(当然是离线的): $\text{LCT}$ 记下每条边的删除时间,用$\text{LCT}$维护最大生成树,每次加进一条边时,跟原来那条链上的做比较,删除那条删 ...
- 在sql server 中查找一定时间段内访问数据库情况
total_worker_time AS [总消耗CPU 时间(ms)], execution_count [运行次数], qs.total_worker_time AS [平均消耗CPU 时间(ms ...
- mysql 创建外键时发生错误的原因和解决方法
可以去网上查看错误号,就能知道到底哪里出错了 https://zhidao.baidu.com/question/359868536.html 这里1452对应的错误是因为建立外键的表中还有数据,所以 ...
- java模拟http请求
java模拟http发送请求,第一种是HttpURLConnection发送post请求,第二种是使用httpclient模拟post请求, 方法一: package main.utils; impo ...