PAT Advanced 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). 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 <iostream>
#include <algorithm>
#include <stack>
using namespace std; int main()
{
int T,min=;
cin>>T;
string s[T];
getline(cin,s[]);
stack<char> sta;
for(int i=;i<T;i++){
getline(cin,s[i]);
reverse(s[i].begin(),s[i].end());
if(min>s[i].length()) min=s[i].length();
}
bool isSame;
for(int i=;i<min;i++){
isSame=true;
for(int j=;j<T;j++){
if(s[j][i]!=s[][i]) isSame=false;
}
if(isSame) sta.push(s[][i]);
else break;
/**不相同直接break掉,这边是一个失误点
失误案例 abddnai
aaaanai*/
}
if(sta.empty()) cout<<"nai";
while(!sta.empty()){
cout<<sta.top();
sta.pop();
}
system("pause");
return ;
}
PAT Advanced 1077 Kuchiguse (20 分)的更多相关文章
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT甲级——1077.Kuchiguse(20分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)
题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...
- PAT Advanced 1035 Password (20 分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- PAT Advanced 1008 Elevator (20 分)
The highest building in our city has only one elevator. A request list is made up with N positive nu ...
- 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【字符串】【暴力】【Hash】【二分】
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- pat 1035 Password(20 分)
1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
随机推荐
- 大数据笔记(三十)——一篇文章读懂SparkSQL
Spark SQL:类似Hive ======================================================= 一.Spark SQL基础 1.什么是Spark SQ ...
- java分页原理及分类
1.使用List接口最终subList()方法实现分页 2.直接使用数据库SQL语句实现分页 3.使用hibernate等框架实现跨数据库的分页 mybatis是面向SQL的,本质上和第二种分页方式相 ...
- Spring MVC 同一个方法同时返回view或json
https://blog.csdn.net/zzg1229059735/article/details/50854778 @RequestMapping(value = "/htmlorjs ...
- 请简述一下 Ajax 的原理及实现步骤
简述 AJAX:AJAX即“Asynchronous Javascript And XML”(异步 JavaScript 和 XML),是指一种创建交互式网页应用的网页开发技术.通过在后台与服务器进行 ...
- Linux清空文本内容
测试文件:test.txt 第一种: $> test.txt 第二种: $echo "" > test.txt 第三种: $cat /dev/null > tes ...
- 方法一破解:Excel工作表保护密码
在excel2016中实测验证过有效 在Excel中,为了保护自已的工作表不被修改,我们可以添加保护密码. 操作步骤: 1.把Excel文件的扩展名xlsx修改为Rar.瞬间Excel文件变成了压缩包 ...
- cmd 中文显示错误,解决办法
cmd窗口左上角控制按钮(就是图标)上单击-默认-选项-默认编码-936 追问 默认值是936的,但是属性里的当前代码页是437呀,怎么办 囧oz 追答 默认-选项-默认编码-936 不是属性,是 ...
- ES6标准入门 第三章:变量的解构赋值
解构赋值:从数组和对象中提取值,对变量进行赋值. 本质上,这种写法属于“匹配模式”:只要等号两边的模式相同,左边的变量就会被赋予对应的值. 1.数组的结解构赋值 基本用法 let [foo, [[ba ...
- 【HANA系列】SAP HANA STUDIO客户端升级更新
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA STUDIO客 ...
- win10家庭版安装Docker (Docker Toolbox)
开启CPU的虚拟化功能(自行百度)之前安装了VM所以这部跳过.具体查看可以打开任务管理器->性能->cpu 查看是否有 虚拟化:已启用字样 下载Docker Toolbox 下载地址 h ...