PAT甲级——A1077 Kuchiguse
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). 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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int N;
int main()
{
cin >> N;
string res = "", str;
vector<string>v;
int minL = ;
getchar();
for (int i = ; i < N; ++i)
{
getline(cin, str);
reverse(str.begin(), str.end());
v.push_back(str);
minL = minL < str.length() ? minL : str.length();
}
bool flag = true;
for (int i = ; i < minL && flag; ++i)
{
for (int j = ; j < N && flag; ++j)
{
if (v[][i] != v[j][i])
flag = false;
}
if (flag)
res += v[][i];
}
reverse(res.begin(), res.end());
if (res.length() == )
cout << "nai" << endl;
else
cout << res << endl; return ;
}
PAT甲级——A1077 Kuchiguse的更多相关文章
- PAT 甲级 1077 Kuchiguse
https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...
- 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甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级题分类汇编——线性
本文为PAT甲级分类汇编系列文章. 线性类,指线性时间复杂度可以完成的题.在1051到1100中,有7道: 题号 标题 分数 大意 时间 1054 The Dominant Color 20 寻找出现 ...
- PAT甲级题分类汇编——序言
今天开个坑,分类整理PAT甲级题目(https://pintia.cn/problem-sets/994805342720868352/problems/type/7)中1051~1100部分.语言是 ...
- PAT甲级代码仓库
大道至简,知易行难.希望能够坚持刷题. PAT甲级真题题库,附上我的代码. Label Title Score Code Level 1001 A+B Format 20 1001 * 1002 A+ ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
- PAT甲级1131. Subway Map
PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...
随机推荐
- Codeforces 479【D】div3
题目链接:http://codeforces.com/problemset/problem/977/D 题意:给你一个数字序列,定了一个游戏规则.你可以对当前数字进行两个操作 1./ 3 如果这个数 ...
- Word 多级节标题设置和图表章节号自动生成
写文章的时候,正文.图表.节标题,通过“样式”可以进行统一设置,这里我记录了几点小技巧: 1.多级标题如何设置 假设我要设置三级标题,下面以图的形式记录方式: 设置完之后,应用即可. 章节设定之后,可 ...
- more指令和less指令使用的区别
more和less都是可以一页一页的翻动 more翻页的时候,显示有百分比在最下一行 less没有 more可以用来查询 空白键 (space):代表向下翻一页:Enter :代表向下翻『一行』:/字 ...
- Vue.js小游戏:测试CF打狙速度
此项目只测试反应速度,即手点击鼠标的反应速度 html代码 <div id="top">请等待图片变颜色,颜色便的那一刻即可点击测手速</div> < ...
- nginx 知识
nginx如何实现高并发? 启动nginx服务器后,输入 ps -ef |grep nginx,会发现nginx有一个master进程 和若干个worker进程, 这些worker进程是平等的,都是被 ...
- The linux command 之引用
[me@linuxbox ~]$ echo this is a test this is a test shell 会对echo进行单词分割(word splitting)去除多余的空白. [me@l ...
- Yii2 在php 7.2环境下运行,提示 Cannot use ‘Object’ as class name
出错原因是: Object是php7.2中的保留类名,不可以使用Object作为类的名称. The object name was previously soft-reserved in PHP 7. ...
- Mobox企业网盘回收站文件清空与恢复的管控
1. Mobox系统提供了 个人网盘的回收站 2. Mobox系统提供了 针对公司及部门文档柜的回收站 Mobox系统对个人网盘的回收站可以做这样的限制 1) 可以通过安装程序 ,不出现 回收站 2 ...
- load data local infile
发财 基本语法:load data [low_priority] [local] infile '文件名称' [replace替换策略 | ignore忽略策略]into table 表名称[fiel ...
- IDEA快捷键(收集自网络后整理)
快捷键 说明 CTRL+B 快速打开光标处的类或方法 CTRL+C 拷贝 CTRL+D 复制当前行到下一行 CTRL+E 最近打开的文件 CTRL+F 当前文件查找特定内容 CTRL+G 定位行 CT ...