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
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
void rev(char a[]){
int len = strlen(a);
for(int i = ; i < len / ; i++)
swap(a[i],a[len - - i]);
}
int main(){
int N, minL = , tag = , len = ;
char str[][], sen[];
scanf("%d", &N);
getchar();
for(int i = ; i < N; i++){
gets(str[i]);
rev(str[i]);
if(minL > strlen(str[i]))
minL = strlen(str[i]);
}
for(int i = ; i < minL; i++){
char c = str[][i];
for(int j = ; j < N; j++)
if(str[j][i] != c){
tag = ;
break;
}
if(tag == )
break;
len++;
}
if(len != )
for(int j = len - ; j >= ; j--)
printf("%c", str[][j]);
else
printf("nai");
cin >> N;
return ;
}

总结:

1、本题即求公共后缀,由于每个字符串长度不一,可以在输入字符串后逆序,转换为求公共前缀。

2、关于字符串的处理,本题无法使用scanf的%s读入字符串,因为字符串中存在空格。所以可以用gets(),在遇到回车时结束。但要注意,在scanf读入N后,还存在一个回车键,需要被吸收掉,否则会导致gets()读到一个回车空串。

3、由于PAT不支持gets()读入带空格的一行。以后遇到复杂的字符串题时,使用string而不是char[]。

A1077. Kuchiguse的更多相关文章

  1. PAT甲级——A1077 Kuchiguse

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  2. PAT A1077 Kuchiguse (20)

    晴神书中AC代码 #include <cstdio> #include <cstring> #include <iostream> using namespace ...

  3. PAT_A1077#Kuchiguse

    Source: PAT A1077 Kuchiguse (20 分) Description: The Japanese language is notorious for its sentence ...

  4. PAT/字符串处理习题集(二)

    B1024. 科学计数法 (20) Description: 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+ ...

  5. PAT题目AC汇总(待补全)

    题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...

  6. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  7. 1077 Kuchiguse (20 分)

    1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

  8. 1077. Kuchiguse (20)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  9. PAT1077: Kuchiguse

    1077. Kuchiguse (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming The Japan ...

随机推荐

  1. Python代码转c#部分参考样例

    最近在做一部分Pyhton代码转c#代码的工作,以下案例亲自都测试过,现整理出来希望对有帮助的同学提供参考: Python | C# *:first-child{margin-top:0 !impor ...

  2. CentOS6下OpenLDAP+PhpLdapAdmin基本安装及主从/主主高可用模式部署记录

    下面测试的部署机ip地址为:192.168.10.2051)yum安装OpenLDAP [root@openldap-server ~]# yum install openldap openldap- ...

  3. javaScript常用API合集

    节点 1.1 节点属性 Node.nodeName   //返回节点名称,只读 Node.nodeType   //返回节点类型的常数值,只读 Node.nodeValue  //返回Text或Com ...

  4. 研究C语言的新型编译环境TCC

    C语言综合研究1 搭建一个tcc环境 研究过程: 问题引出:为什么要使用tcc环境,甚至连图形界面都没有,为什么要使用这样的化境? 按照我们学习的本质来讲,可能是为了体验C语言底层的相关特性,但是在研 ...

  5. Beta版测试报告

    Beta版测试报告 测试中发现的Bug: Version 2.0 Bug List 1. 在动态监测界面,若随便点击“开始”.“关闭”.“结束”.红叉,会出现不定式崩溃现象. 2. 处理空数据时可能会 ...

  6. Tomcat & Servlet

    javaWeb javaWeb是指使用java技术实现所有web程序的技术的总称.我们称之为javaWeb. 1.请求和响应(成对出现) 2.Web资源的分类 web资源分为两大类,分别是静态资源和动 ...

  7. PAT 1022 D进制的A+B

    https://pintia.cn/problem-sets/994805260223102976/problems/994805299301433344 输入两个非负10进制整数A和B(<=2 ...

  8. 安装wamp提示You dont't have permission to accesson on this server的解决方案

    展示一下安装好的效果图 首先找到安装目录下的路径[wamp\bin\apache\Apache2.2.21\conf\] § 找到httpd.conf,用记事本打开httpd.conf,然后将 1. ...

  9. shell获取帮助

    一.內建命令与外部命令 1.內建命令 内建命令是 shell 程序的一部分,是一些比较简单的 Linux 系统命令,这些命令是写在bash源码的builtins里面的,由 shell 程序识别并在 s ...

  10. python 授权

    1.“包装”意思是一个已经存在的对象进行包装,不管他是数据类型还是一段代码,可以是对一个已经存在的对象增加新的,删除不要的或者修改其他已经存在的功能 2.包装 包括定义一个类,他的实例拥有标准类型的核 ...