PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
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
题意:
题意是寻找一组字符串中最大相同后缀,并输出。如果没有:则输出‘nai’
题解:
简单题,可以reverse反转一下找最大前缀
AC代码:
#include<bits/stdc++.h>
using namespace std;
string a[];
int main(){
int n;
cin>>n;
getchar();
for(int i=;i<=n;i++){
getline(cin,a[i]);
reverse(a[i].begin(),a[i].end());
//cout<<a[i]<<endl;
}
string s="";
int f=;
char c;
for(int i=;i<;i++){
for(int j=;j<=n;j++){
if(i>=a[j].length()){
f=;
break;
}
if(j>=){
if(a[j][i]!=a[][i]){
f=;
break;
}
}else{
c=a[][i];
}
}
if(f==){
s+=c;
}
}
reverse(s.begin(),s.end());
if(s!="") cout<<s;
else cout<<"nai";
return ;
}
PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)的更多相关文章
- PAT甲级——1077.Kuchiguse(20分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT Advanced 1077 Kuchiguse (20 分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)
1061 Dating (20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...
- 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)
题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...
- PAT甲级——1035 Password (20分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- PAT 甲级 1077 Kuchiguse
https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...
- PAT甲级——1061 Dating (20分)
Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkg ...
- PAT甲级——1005.SpellItRight(20分)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...
随机推荐
- PEP 8016-Python之父重回决策层
PEP 8016-Python之父重回决策层 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 去年,技术社区里还发生了一件大事:Linux 之父 Linus Torvalds 宣 ...
- rhce 考试题目总结
rhce 考试题目总结归类 开机需要做的事: 检查系统版本 配置yum源 修改selinux的模式 ping一下server机器 1.分区类题目 1.1 rhcsa 第十五题 添加swap分区 要点: ...
- python开发应用笔记-SciPy扩展库使用
SciPy https://www.scipy.org/ SciPy中的数据结构: 1.ndarray(n维数组) 2.Series(变长字典) 3.DataFrame(数据框) NumPy适合于线性 ...
- BZOJ3028 食物 和 LOJ6261 一个人的高三楼
总结一下广义二项式定理. 食物 明明这次又要出去旅游了,和上次不同的是,他这次要去宇宙探险!我们暂且不讨论他有多么NC,他又幻想了他应该带一些什么东西.理所当然的,你当然要帮他计算携带N件物品的方案数 ...
- Fiddler——手机端无法安装证书
前言 一个APP测试,需要抓包,设置好代理后,访问代理地址,下载证书,下载完成却不能安装. 提示:无法读取该证书文件 手机型号: OPPO A5 步骤 设置->其他设置->设备与隐私-&g ...
- pycharm激活2018(终极解决办法)
1.将“0.0.0.0 account.jetbrains.com”中的内容添加到hosts文件中,hosts路径为:C:\Windows\System32\drivers\etc 2.打开http: ...
- WinDbg的环境变量
有很多的环境变量,主要分为常规环境变量和内核模式环境变量.下面分别列出. 常规环境变量 下表列出了可在用户模式和内核模式调试的环境变量. 变量 含义 _NT_DEBUGGER_EXTENSION_PA ...
- vault 使用 中间ca 进行证书管理
使用vault 进行pki 管理是很方便的,以前测试的都是由根证书进行证书签发,这次使用中间ca 进行签发 所以会有一个证书连 测试使用docker-compose 运行 环境准备 docker-co ...
- 使用terraform v0.12 生成gitlab repo 创建部署tf 文件
以前写过一个使用模版引擎+ rest 接口的模式,生成tf 文件,v0.12 直接提供了方便的json 处理函数 我们可以直接结合http 以及templatefile providers 方便的 ...
- 15-ESP8266 SDK开发基础入门篇--上位机串口控制 Wi-Fi输出PWM的占空比,调节LED亮度,上位机程序编写
https://www.cnblogs.com/yangfengwu/p/11104167.html 先说一下整体思路哈.. 咱滑动的时候 会进入这个,然后咱呢不直接从这个里面写发送 因为这样的话太快 ...