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 ...
随机推荐
- 函数式编程之pipeline——很酷有没有
Pipeline pipeline 管道借鉴于Unix Shell的管道操作——把若干个命令串起来,前面命令的输出成为后面命令的输入,如此完成一个流式计算.(注:管道绝对是一个伟大的发明,他的设哲学就 ...
- ThinkPHP支持的4种路由模式
下面这个说法和示例,比较具有总结性.
- 学习app开发思路
1.首先在学习之前进行一次或者是整体或者是部分的检测,当第一次检测就通过,则可以认为是熟练掌握的东西(可以在后期对其进行验证是否是熟练)2.后面的学习过程,对回答的正确与否以及从第一次开始学习到目前为 ...
- python打造seo必备工具-自动查询排名
因为工作需要,利用业余时间开发的,可以查询百度排名+360排名工具,附上代码. #360搜索排名查询 # -*- coding=utf-8 -*- import requests from lxml ...
- destoon下动态链接301到伪静态(ngnix)
分享一个destoon6.0/7.0下动态链接301到伪静态上面,实现权重提升. if ($request_uri ~* "^/index.php\?itemid=(\d+)&mod ...
- about云Hadoop相关技术总结
让你真正明白spark streaminghttp://www.aboutyun.com/forum.php?mod=viewthread&tid=21141(出处: about云开发)
- mybatis框架-查询用户表中的记录数
之前已经搭建过mybatis框架了,现在我们要用mybatis框架真正的干点事情了. 这是这个简单web项目的整体架构. 我们使用mybatis框架查询用户表中的记录数: 这是用户类: package ...
- 4-html图片与链接
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- AOP_原理
什么是AOPAOP(Aspect-OrientedProgramming,面向方面编程),可以说是OOP(Object-Oriented Programing,面向对象编程)的补充和完善.OOP引入封 ...
- Can't generate API documentation in l5-swagger
Can't generate API documentation in l5-swagger Ask Question Asked 3 months ago Active 1 month ago Vi ...