PAT 1077. Kuchiguse (20)
来源:互联网 发布:斗鱼鱼丸能用淘宝买 编辑:程序博客网 时间:2024/06/05 10:07
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:
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:3Itai nyan~Ninjin wa iyadanyan~uhhh nyan~Sample Output 1:
nyan~Sample Input 2:
3Itai!Ninjinnwaiyada T_TT_TSample Output 2:
nai
#include <iostream>#include<stdio.h>#include<queue>#include<string.h>#include<string>#include<vector>using namespace std;string sentence[105];int main(){ int n; cin>>n; getchar(); for(int i=0;i<n;i++) getline(cin,sentence[i]); int flag=1; int cnt=1; char path[10000]; int p=0; while(flag) { int l=sentence[n-1].size()-cnt; char now=sentence[n-1][l]; for(int i=n-2;i>=0;i--) { int x=sentence[i].size()-cnt; if(x<0) { flag=0;break; } if(sentence[i][x]!=now) { flag=0; break; } } if(!flag) break; path[p++]=now; cnt++; } //while(path[p-1]==' '&&p>0) p--; 去公共开头的空格 if(p==0) cout<<"nai"; else { p--; for(;p>=0;p--) cout<<path[p]; } return 0;}
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- pat 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- 【PAT】1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT (Advanced) 1077. Kuchiguse (20)
- PAT A 1077. Kuchiguse (20)
- PAT甲级.1077. Kuchiguse (20)
- 1077. Kuchiguse (20) PAT甲级
- PAT-A 1077. Kuchiguse (20)
- PAT-A-1077. Kuchiguse (20)
- 【PAT甲级】1077. Kuchiguse (20)
- PAT 甲级 1077. Kuchiguse (20)
- 从零开发一个完整的Android项目(九)——图片浏览
- 归并排序
- ResourceBundle读取配置文件
- GitChat·架构 | 云架构下的性能分析两实例
- 机器学习实战:KNN算法讲解
- PAT 1077. Kuchiguse (20)
- Centos虚拟机可以ping通外网IP但是无法ping通域名
- java基础学习总结——数组
- 启动MyEclipse10时出现Errors occurred during the build。
- python 读写json文件
- 【bzoj1103】[POI2007]大都市meg DFS序
- underscore用法,完整示例,喜欢就点赞加关注,以后会有更多惊喜
- js中for 和event
- 上传下载(sevlet实现)