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 [一般]的更多相关文章

  1. PAT 1077 Kuchiguse

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

  2. pat 1077 Kuchiguse(20 分) (字典树)

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

  3. PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】

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

  4. 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise

    题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...

  5. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

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

  6. 1077 Kuchiguse (20 分)

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

  7. PAT 1077. 互评成绩计算

    PAT 1077. 互评成绩计算 在浙大的计算机专业课中,经常有互评分组报告这个环节.一个组上台介绍自己的工作,其他组在台下为其表现评分.最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个 ...

  8. PAT 甲级 1077 Kuchiguse

    https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...

  9. PAT Advanced 1077 Kuchiguse (20 分)

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

随机推荐

  1. MapReduce程序的工作过程

    转自:http://www.aboutyun.com/thread-15494-1-2.html 问题导读1.HDFS框架组成是什么?2.HDFS文件的读写过程是什么?3.MapReduce框架组成是 ...

  2. android jni log

    在编写的jni时,经常需要输出打印信息进行调试,而C中printf在jni中没有效果,这时就需要使用NDK提供的函数. 1. jni中包含头文件 #include <android/log.h& ...

  3. 编译内核出现"mkimage" command not found - U-Boot images will not be built

    参考链接: http://spyker729.blogspot.com/2010/07/mkimage-command-not-found-u-boot-images.html 制作uImage的工具 ...

  4. c#后台List转为js对象(在前台操作)

    <!-- 用html标签防止html转义 (html.raw方法转双引号中的双引号时不会转义) --><input id="json" type="hi ...

  5. db2 import和load

    Import和Load 都可以将数据导入到DB2服务器中,但是2者是有很大区别的. Import 其实执行了SQL 的INSERT 操作.和INSERT 操作一样,Import 执行的时候会激活触发器 ...

  6. Python+selenium之简单介绍unittest单元测试框架

    Python+selenium之简单介绍unittest单元测试框架 一.unittest简单介绍 unittest支持测试自动化,共享测试用例中的初始化和关闭退出代码,在unittest中最小单元是 ...

  7. iOS开发之--打印一堆奇怪东西的解决方案

    Xcode8总是打印一堆奇怪的东西.虽然不影响开发,但是看着很不爽.解决的方法就是在Scheme里面添加(name):OS_ACTIVITY_MODE (value):disable 然后再在突出的框 ...

  8. iOS开发之--TableViewCell重用机制避免重复显示问题

    常规配置如下 当超过tableView显示的范围的时候 后面显示的内容将会和前面重复 // 这样配置的话超过页面显示的内容会重复出现 - (UITableViewCell *)tableView:(U ...

  9. Socket通信编程实例(SIB和SS'SOB)

    客户端: package socket; import java.io.BufferedReader; import java.io.IOException; import java.io.Input ...

  10. android高仿微信UI点击头像显示大图片效果, Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果

    http://www.cnblogs.com/Jaylong/archive/2012/09/27/androidUI.html http://blog.csdn.net/xiaanming/arti ...