A1077. Kuchiguse
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的更多相关文章
- PAT甲级——A1077 Kuchiguse
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT A1077 Kuchiguse (20)
晴神书中AC代码 #include <cstdio> #include <cstring> #include <iostream> using namespace ...
- PAT_A1077#Kuchiguse
Source: PAT A1077 Kuchiguse (20 分) Description: The Japanese language is notorious for its sentence ...
- PAT/字符串处理习题集(二)
B1024. 科学计数法 (20) Description: 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+ ...
- PAT题目AC汇总(待补全)
题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
- 1077 Kuchiguse (20 分)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- 1077. Kuchiguse (20)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT1077: Kuchiguse
1077. Kuchiguse (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming The Japan ...
随机推荐
- WordPress更新时提示无法连接到FTP服务器的解决方案
这几天在搭建主站的时候,更新wordpress时无法连接到FTP原因服务器 解决方法如下: 在WordPress目录下找到wp-config.php文件并编辑,在最后一行加上: define('FS_ ...
- inode 软/硬链接
一.inode是什么? 理解inode,要从文件储存说起. 文件储存在硬盘上,硬盘的最小存储单位叫做"扇区"(Sector).每个扇区储存512字节(相当于0.5KB). 操作系统 ...
- linux下expect环境安装以及简单脚本测试
expect是交互性很强的脚本语言,可以帮助运维人员实现批量管理成千上百台服务器操作,是一款很实用的批量部署工具!expect依赖于tcl,而linux系统里一般不自带安装tcl,所以需要手动安装 下 ...
- 牛客第二场-J-farm-二维树状数组
二维树状数组真的还挺神奇的,更新也很神奇,比如我要更新一个区域内的和,我们的更新操作是这样的 add(x1,y1,z); add(x2+1,y2+1,z); add(x1,y2+1,-z); add( ...
- Linux大棚命令记录
查看系统支持的shell: cat /etc/shells 查看当前系统用的shell: echo $SHELL 从bash切换到zsh: 先yum安装,然后 chsh -s /bin/zsh ,退 ...
- 【BUAA软件工程】第一次阅读作业
BUAA软件工程 第一次阅读作业 项目 内容 这个作业属于哪个课程? 北航软工 这个作业的要求在哪里? 第一次个人作业 我在这个课程的目标是? 学习高效严谨的软件工程开发过程,建立团队意识 这个作业在 ...
- 《Linux内核分析》期终总结&《Linux及安全》期中总结
<Linux内核分析>期终总结&<Linux及安全>期中总结 [李行之 原创作品 转载请注明出处 <Linux内核分析>MOOC课程http://mooc. ...
- UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现(转)
UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现 类与类图 1) 类(Class)封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性.操作.关系的对象集合的总称. 2) 在系统 ...
- wordpress升级出错
服务器是腾讯云 搜索到的解决方案有几个,试了好几个,不知道哪个是根本原因,反正都操作了. 设置wordpress文件夹和子文件夹的权限 编辑wp-config.php,在文末添加如下: define( ...
- yii框架通过IP地址来使用gii
这里使用的YII框架的版本是2.0.13 详情请参考官方文档:用Gii生成代码 使用gii的主要步骤 1.生成模型(Model Generator) 2.生成CRUD代码 注意点 1.在生成CURD代 ...