PAT 1077 Kuchiguse [一般]
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:
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
题目大意:给出m个句子,判断所有句子的最长后缀。
//有空格怎么办?那就不是一个character了。。。
#include <iostream>
#include <algorithm>
#include<cstdio>
#include <vector>
#include<cstring>
#include<string.h>
#include<string>
using namespace std; int main()
{
int n;
cin>>n;
string pe="",now;//那就以第一个作为标准,剩下的去和它作比较。
int j=,k=,mins=j;
for(int i=;i<n;i++){//如何读取一行,真的是不会。。。。
getline(cin,now);
if(pe==""){
pe=now;continue;
}
for(j=pe.size()-,k=now.size()-;k>=,j>=;j--,k--){
if(pe[j]!=now[k]){
break;
}
}
if(j<mins){
mins=j;
}
}
if(mins==){
cout<<"nai";
}else{
for(int i=mins;i<pe.size();i++){
cout<<pe[i];
}
} return ;
}
//本来是写成这个样子,根本就不行啊,不过整行读取字符串的函数写的是对的。
根据柳神的修改了之后的,可以AC了
#include <iostream>
#include <algorithm>
#include<cstdio>
#include <vector> using namespace std; int main()
{
int n;
cin>>n;
string pe="",now,ans;//那就以第一个作为标准,剩下的去和它作比较。
getline(cin,now);
for(int i=;i<n;i++){//如何读取一行,真的是不会。。。。
getline(cin,now);
reverse(now.begin(),now.end());
if(i==){
ans=now;
}else{
int j=;
for(j=;j<ans.size()&&j<now.size();j++){
if(ans[j]!=now[j])break;
}
ans=ans.substr(,j);
}
}
reverse(ans.begin(),ans.end());
if(ans=="")
cout<<"nai";
else
cout<<ans;
return ;
}
1.使用reverse进行倒转,因为是比较后缀,不太好比较,最后的答案需要再翻转过来。
2.关于这个getline(cin,now)读取一行的问题,在输入了n之后,其实就有一个\n被getline给读取进来了,所以这样就浪费了一个,需要单独加一个getline来消灭\n才对!
3.使用substr进行截取答案。
PAT 1077 Kuchiguse [一般]的更多相关文章
- PAT 1077 Kuchiguse
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- pat 1077 Kuchiguse(20 分) (字典树)
1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise
题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- 1077 Kuchiguse (20 分)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- PAT 1077. 互评成绩计算
PAT 1077. 互评成绩计算 在浙大的计算机专业课中,经常有互评分组报告这个环节.一个组上台介绍自己的工作,其他组在台下为其表现评分.最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个 ...
- PAT 甲级 1077 Kuchiguse
https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...
- PAT Advanced 1077 Kuchiguse (20 分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
随机推荐
- Java,Mysql-根据一个给定经纬度的点,进行附近500米地点查询–合理利用算法
Java,Mysql-根据一个给定经纬度的点,进行附近500米地点查询–合理利用算法 LBS 球面距离公式 http://wiki.myoa.info/zh-blog:20 Java,Mysql- ...
- 关于Spring MVC Controller 层的单元测试
关于Spring MVC Controller 层的单元测试 测试准备工作: 1.搭建测试Web环境 2.注入Controller 类 3.编写测试数据 测试数据的文件名一定要与测试类的文件名相同,比 ...
- ES插件elasticsearch-mapper-attachments 2.3.4及各个版本正确下载地址
ES版本更新那么快,文档链接你也倒是跟上啊, 插件zip包下载,都是error link...难不成是我网络原因? 下载zip页面报错信息: This XML file does not appear ...
- 【python】matplotlib中文乱码问题
http://www.pythoner.com/200.html 改matplotlibrc文件进入Python安装目录下的Lib\site-packages\matplotlib\mpl-data目 ...
- MP 及OMP算法解析
转载自http://blog.csdn.net/pi9nc/article/details/18655239 1,MP算法[盗用2] MP算法是一种贪心算法(greedy),每次迭代选取与当前样本残差 ...
- AWS系列-S3实现文件服务页面展示
最近由于业务需求,对于备份的数据存放到S3上面,并需要页面展示.而且还能下载. 把这个桶里面的对象,都在某个静态页面展示.并且 我可以把这个对象下载下来. 首页内容就是 桶里面的对象. 并且可以随时查 ...
- 1455: 罗马游戏[左偏树or可并堆]
1455: 罗马游戏 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1861 Solved: 798[Submit][Status][Discuss] ...
- windows安装oracle11g第二部
Oracle 11g数据库安装及配置 安装Oracle数据库: 1)压缩包解压,双击运行win64_11gR2_database\database\setup.exe 2)输入电子邮件,点击“下一步” ...
- iOS UILable 高度自适
#import "ViewController.h" #define FontSize 20 @interface ViewController () @end @implemen ...
- 160425、linux安装SVN服务器
1:查看linux是否已经安装svn服务 [root@nb ~]# rpm -qa subversion subversion-1.6.11-15.el6_7.x86_64 2:安装svn #yum ...