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≤N≤100). 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
分析: 求字符串的公共后缀。思路是先逆置字符串,然后从第一个开始比较。
/**
* Copyright(c)
* All rights reserved.
* Author : Mered1th
* Date : 2019-02-24-21.51.09
* Description : A1077
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
;
string a[maxn];
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
;
cin>>n;
getchar();
;i<n;i++){
getline(cin,a[i]);
int len=a[i].size();
if(minlen>len) minlen=len;
reverse(a[i].begin(),a[i].end());
}
string ans="";
;i<minlen;i++){
][i];
bool same=true;
;j<n;j++){
if(c!=a[j][i]){
same=false;
break;
}
}
if(same) ans+=c;
else break;
}
if(ans.size()){
reverse(ans.begin(),ans.end());
cout<<ans;
}
else{
cout<<"nai";
}
;
}
1077 Kuchiguse (20 分)的更多相关文章
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT Advanced 1077 Kuchiguse (20 分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT甲级——1077.Kuchiguse(20分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)
题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...
- 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise
题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...
- 1077. Kuchiguse (20)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT (Advanced Level) 1077. Kuchiguse (20)
最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...
- PAT甲题题解-1077. Kuchiguse (20)-找相同后缀
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- PAT 1077 Kuchiguse
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
随机推荐
- 20165210 Java第八周学习总结
20165210 Java第八周学习总结 教材内容学习 - 第十二章学习总结 进程与线程 操作系统与进程 Java中的线程 Java的多线程机制 主线程 线程的状态与生命周期 1. 新建 2. 运行 ...
- Tesseract-OCR 训练教程(二) 合并新的训练文件
在原有训练数据的基础上,如果有新的字符训练信息需要加入,所有数据重新校准一遍就累死人了.... 经研究找到实用合并方法(红色部分为示例,实际应为你自己生成的文件名): 在新的训练数据生成.box 和. ...
- springboot date接收参数
使用springboot框架对日期类型进行操作,遇到无法保持的情况,一开始报400的错误(解决方法),解决之后日期类型无法保存到数据库,为了解决这个问题,设置了个全局date转换器. 配置方法 1.新 ...
- Python GIL 系列之再谈Python的GIL
1. 之前写过一篇<通过实例认识Python的GIL>的文章,感觉有些意犹未尽 2. 这次对例子作了些扩展,进一步的分析GIL对Python程序的影响 2.1 先来看例子: [python ...
- string用scanf读入(节省时间)
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...
- TimeSpan格式化字符串格式(摘)
一直在用DateTime, 却不常用TimeSpan , 今天突然用到了, 发现不知道咋做格式化...百度一下,找到了答案, 在这记录一下, 免得以后找花费时间 以下内容摘抄自 Microsoft D ...
- rest_cherrypy
一.简介 A REST API FOR SALT 二.安装,配置 yum -y install salt-api rest_cherrypy: port: # disable_ssl: True ss ...
- How to return NULL string
Q: std::string get_file_contents(const char *filename) { std::ifstream in(filename, std::ios::in | s ...
- Linux基础和网络管理上机试题 - imsoft.cnblogs
一.(使用at命令实现任务的的自动化,要求用一条条的指令完成) 找出系统中任何以txt为后缀名的文档,并且进行打印.打印结束后给用户foxy发出邮件通知取件.指定时间为十二月二十五日凌晨两点 ...
- 20155328 2016-2017-2 《Java程序设计》第5周学习总结
教材学习内容总结 程序设计本身的错误,建议使用Exception或其子类实例来表现. Java中所有错误都会被打包成对象. 如果父类异常对象在子类异常对象前被捕捉,则catch子类异常对象的区块将永远 ...