首页 > 学院 > 开发设计 > 正文

PAT A1077. Kuchiguse (20/17)

2019-11-10 22:56:01
字体:
来源:转载
供稿:网友

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:
3Itai nyan~Ninjin wa iyadanyan~uhhh nyan~Sample Output 1:
nyan~Sample Input 2:
3Itai!Ninjinnwaiyada T_TT_TSample Output 2:
nai
#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#define Max 300using namespace std;struct user{	char name[11];	char pas[11];}a[Max],b[Max];char getc(char a[],int m){	return a[strlen(a)-1-m];}int main(){	char la[Max][Max];	int n,k=0,f=1;	scanf("%d",&n);	getchar();	for(int i=0;i<n;i++){				gets(la[i]);	}	while (f==1){	for(int i=0;i<n-1;i++)	{		if(getc(la[i+1],k)!=getc(la[i],k)){			f=0;			break;		}	}	  if(f==1)  k++;	  else break;	}	if(k==0) printf("nai/n");	else {		for(int i=strlen(la[0])-k;i<strlen(la[0]);i++)			printf("%c",la[0][i]);	}	system("pause");	return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表