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 ...
随机推荐
- OpenGL学习(1)—— 测试OpenGL环境是否搭建成功
一个用来验证OpenGL(glfw + glad)环境是否搭建成功的测试代码 内容为生成一个小窗口 #include <glad/glad.h> #include <GLFW/glf ...
- 数组函数some、every、find、filter、map、forEach有什么区别
- wordpress调用指定post type文章怎么操作
我们有时会用wordpress创建好几种post type文章,比如默认的post文章和product文章,如果我们要在每个页面的底部调用post type类型为post最新文章要如何操作呢?那我们就 ...
- Centos7 虚拟机里查看IP并启动网卡
输入ip查询命名 ip addr 也可以输入 ifconfig(centOs7没有ifconfig命令)查看ip,但此命令会出现3个条目,centos的ip地址是ens33条目中的inet值. 发现 ...
- (3) esp8266 官方库文件,没有求逆函数
下载库文件 #include <MatrixMath.h> #define N (2) mtx_type A[N][N]; mtx_type B[N][N]; mtx_type C[N][ ...
- 手工部署yugabyte的几点说明
ntp 时间同步 ntp 时间同步对于yugabyte 是一个比较重要的服务,需要注意时间的同步 YB-Master 个数的说明 原则 YB-Master 的个数,必须和复制因子的个数一样,同时mas ...
- dbt 0.13.0 新添加特性sources 试用
dbt 0.13 添加了一个新的功能sources 我呢可以用来做以下事情 从基础模型的源表中进行数据选择 测试对于源数据的假设 计算源数据的freshness source 操作 定义source ...
- dinoql 试用
dinoql 前面有过介绍,详细的参考文档即可,这篇主要是简单使用 注意目前dinoql 直接通过node 运行会有window 的问题,有好几种解决方法,后边会说明 环境准备 项目初始化 yarn ...
- 【cf contest 1119 H】Triple
题目 给出 \(n\) 个三元组\(\{ a_i,b_i,c_i \}\)和\(x,y,z\): 将每个三元组扩展成(\(x\)个\(a_i\),\(y\)个\(b_i\),\(z\)个\(c_i\) ...
- GoCN每日新闻(2019-10-03)
GoCN每日新闻(2019-10-03) 国庆专辑:GopherChina祝大家国庆节快乐 GoCN每日新闻(2019-10-03) 1. 垃圾回收器如何监控你的应用程序 https://medium ...