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 分)(简单,找最大相同后缀)的更多相关文章

  1. PAT甲级——1077.Kuchiguse(20分)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  2. PAT Advanced 1077 Kuchiguse (20 分)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  3. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  4. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

  5. 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)

    题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...

  6. PAT甲级——1035 Password (20分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  7. PAT 甲级 1077 Kuchiguse

    https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...

  8. PAT甲级——1061 Dating (20分)

    Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkg ...

  9. 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 ...

随机推荐

  1. AXURE RP EXTENSION For Chrome----解决办法

    出现这个问题是因为chrome://extensions/中没有安装扩展程序 解决办法: 步骤一:情景再现,打开某个html会出现如下页面,不停地提示你安装插件 步骤二:如果点击安装扩展程序,能够成功 ...

  2. ArcGIS操作技巧——怎样把地图放到PPT中,并且进行编辑?

    需求:把arcgis配好的矢量地图插入到ppt中,并且要求可以在PPT中进行修改和重新着色.编辑. 效果:如下图所示: 操作过程: 方法一: 在最上面工具栏找到edit——>copy map t ...

  3. 对字符串'//*[@]/div/p/a[1]/c[2]/a[3]/b'从右向左依次删除指定字符串

    import re s='//*[@]' a=s+'/div/p/a[1]/c[2]/a[3]/b' c=[1,2] b=a.split(s) #切割 c=b[1].split('/') #切割 d= ...

  4. C++中的常量指针和指针常量

    1.概述: const Type * pointer;常量指针(const在*之前,与类型的位置无要求),所指向的地址上的数据是常量,而指向的地址可以变化. Type * const pointer: ...

  5. LeetCode 931. Minimum Falling Path Sum

    原题链接在这里:https://leetcode.com/problems/minimum-falling-path-sum/ 题目: Given a square array of integers ...

  6. WinDbg常用命令系列---日志操作相关命令log*

    .logopen (Open Log File) .logopen命令将事件和命令的副本从调试器命令窗口发送到新的日志文件. .logopen [Options] [FileName] .logope ...

  7. Js 在页面中输入消息的几种方式

    一.方式 alert(“”); confirm(“”) ; prompt(“”);         接收用户信息 console.log(“”);      在网页控制台中输出消息 document. ...

  8. 28-ESP8266 SDK开发基础入门篇--编写wifi模块TCP 客户端程序(官方API版,非RTOS版)

    https://www.cnblogs.com/yangfengwu/p/11432795.html 注:这节实现的功能是WIFI模块作为TCP 客户端,连接咱的TCP服务器,然后实现透传 本来想着做 ...

  9. 原生 ajax 请求

    ajax 即 Asynchronous Javascript And XML,AJAX 不是一门的新的语言,而是对现有持术的综合利用.本质是在 HTTP 协议的基础上以异步的方式与服务器进行通信. 异 ...

  10. 农场派对(party)(信息学奥赛一本通 1497)

    [题目描述] N(1≤N≤1000)头牛要去参加一场在编号为 x(1≤x≤N) 的牛的农场举行的派对.有 M(1≤M≤100000) 条有向道路,每条路长 Ti(1≤Ti≤100):每头牛都必须参加完 ...