PAT (Advanced level) 1077. Kuchiguse (20) 最长共同后缀
来源:互联网 发布:西部数码域名管理地址 编辑:程序博客网 时间:2024/05/29 09:13
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
从后往前遍历。
/*2015.7.29cyq*/#include <iostream>#include <string>#include <vector>#include <fstream>#include <cstring>using namespace std;//ifstream fin("case1.txt");//#define cin finint main(){int N;cin>>N;string enter;getline(cin,enter);//去掉第一行的回车vector<string> svec(N);vector<int> len(N);for(int i=0;i<N;i++){getline(cin,svec[i]);len[i]=svec[i].size();}int count=0;bool flag;for(int i=1;i<=len[0];i++){flag=true;for(int j=1;j<N;j++){//第二个string及之后的stringif(len[j]<i||svec[j][len[j]-i]!=svec[0][len[0]-i]){flag=false;break;}}if(!flag)break;count++;}if(count==0)cout<<"nai";elsecout<<svec[0].substr(len[0]-count);return 0;}
- PAT (Advanced level) 1077. Kuchiguse (20) 最长共同后缀
- PAT Advanced Level 1077. Kuchiguse (20)
- PAT (Advanced Level) 1077. Kuchiguse (20)
- 【PAT】【Advanced Level】1077. Kuchiguse (20)
- PAT (Advanced Level) Practise 1077Kuchiguse (20)
- PAT (Advanced Level) Practise 1077 Kuchiguse (20)
- PAT (Advanced) 1077. Kuchiguse (20)
- 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise
- Pat(Advanced Level)Practice--1077(Kuchiguse)
- 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)
- 取同色手套的排列组合问题
- hdoj 3277 Marriage Match III 【最大流经典建图】【二分 + 最大流 + 并查集】
- HDOJ 1051 Wooden Sticks(贪心)
- 3Sum
- 给CS专业大学生的推荐书籍
- PAT (Advanced level) 1077. Kuchiguse (20) 最长共同后缀
- 设计模式之设计原则学习
- 执行一个shell脚本而导致虚拟机centos6崩溃,慎重使用root权限
- HDU 5046 Airport
- sort 进行下标排序
- IDEA14.X环境下Java Web项目的创建
- android开发之merge结合include优化布局
- hdu 5323 Solve this interesting problem 【DFS】
- OpenCV - win7+vs2013(2012)+opencv3.0.0 环境配置 (以及配置技巧)