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 ...
随机推荐
- iOS ipv6 被拒
1.检查你所用到的库,像af 3.0以上什么的(不用改),其他的库自己去搜下是否支持ipv6吧. 2.确保你用的sdk支持ipv6,这个自己去看文档就行. 3.终端 dig +nocmd + nos ...
- L242
They provide a means of keeping track of the thousands of journal papers that are published monthly ...
- 优化cocos2d/x程序的内存使用和程序大小
本站文章均为李华明Himi原创,转载务必在明显处注明:转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/iphone-cocos2d/1043.html ☞ ...
- 安装 Java 6
从服务器下载 Linux 64位 jdk 到本地.下载地址:\\192.167.100.225\share\Tool\JAVA\jdk-6u34-linux-x64.bin 给安装文件添加执行权限 $ ...
- stm32 SPI介绍和配置
SPI是一种高速的,全双工同步的通信总线,在芯片管脚上占用了四根线,节约了芯片的管脚,同时为PCB的布局节省了空间,提供了方便,因此越来越多的芯片集成了这种通信协议,STM32也就有了SPI接口. 有 ...
- python--selenium实用的自动生成测试HTML报告方法--HTMLTestRunner
python--selenium实用的自动生成测试HTML报告方法--HTMLTestRunner 下面给大家介绍下用HTMLTestRunner模块自动生成测试报告的方法. 一.首先我们导入unit ...
- Cannot find config.m4. Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module的 解决方法
cp /php-7.1.22/ext/openssl/config0.m4 /usr/local/php/bin/config.m4
- Linux设备树使用(二)
一.设备树与驱动的匹配1.设备树会被/scripts中的dtc可执行程序编译成二进制.dtb文件,之前设备树中的节点信息会以单链表的形式存储在这个.dtb文件中:驱动与设备树中compatible属性 ...
- Makefile在内核编译中的使用
1.一个配置选项选中多个文件 path:drivers/media/i2c/adv748x adv748x-objs := \ adv748x-afe.o \ adv748x-core.o \ adv ...
- solr学习二(ExtractingRequestHandler)
通过ExtractingRequestHandler,slor能够读取word.pdf等文件,并用于全文搜索.废话少说,进入主题: solr服务端是配出来的: solrconfig.x ...