1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise
题目信息
1077. Kuchiguse (20)
时间限制100 ms
内存限制65536 kB
代码长度限制16000 B
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
解题思路
反转字符串后逐个字符比較
AC代码
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int n;
vector<string> v;
string s, rs;
cin >> n;
getline(cin, s);// 去掉回车
while (n--){
getline(cin, s);
reverse(s.begin(), s.end());
v.push_back(s);
}
int loc = -1;
bool flag = true;
while (flag && ++loc < v[0].size()){
for (int i = 0; i < v.size(); ++i){
if (v[i][loc] != v[0][loc]){
flag = false;
break;
}
}
if (flag){
rs += v[0][loc];
}
}
if (rs.empty()){
cout <<"nai" <<endl;
}else{
reverse(rs.begin(), rs.end());
cout <<rs <<endl;
}
return 0;
}
1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise的更多相关文章
- 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise
题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...
- PAT (Advanced Level) Practise - 1092. To Buy or Not to Buy (20)
http://www.patest.cn/contests/pat-a-practise/1092 Eva would like to make a string of beads with her ...
- 1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise
题目信息 1069. The Black Hole of Numbers (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B For any 4-digit inte ...
- PAT (Advanced Level) Practise - 1096. Consecutive Factors (20)
http://www.patest.cn/contests/pat-a-practise/1096 Among all the factors of a positive integer N, the ...
- PAT (Advanced Level) Practise - 1094. The Largest Generation (25)
http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...
- PAT (Advanced Level) Practise - 1095. Cars on Campus (30)
http://www.patest.cn/contests/pat-a-practise/1095 Zhejiang University has 6 campuses and a lot of ga ...
- PAT (Advanced Level) Practise 1001 解题报告
GiHub markdown PDF 问题描述 解题思路 代码 提交记录 问题描述 A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判 ...
- PAT (Advanced Level) Practise 1004 解题报告
GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...
- PAT (Advanced Level) Practise - 1093. Count PAT's (25)
http://www.patest.cn/contests/pat-a-practise/1093 The string APPAPT contains two PAT's as substrings ...
随机推荐
- Spring aop与AspectJ的区别?
根据我看spring官方文档的理解(不出意外是最正确的答案): ①选择spring的AOP还是AspectJ? spring确实有自己的AOP.功能已经基本够用了,除非你的要在接口上动态代理或者方法拦 ...
- 莫名其妙的js脚本文件引用不到
今天遇到一个很奇怪的问题,在页面中引用的脚本文件,引用路径没有问题,而且在很多浏览器中都测试没有问题,包括Win8 Modren UI下的IE11也同样没有问题,唯独Win8桌面版的IE11无法引用. ...
- 在vps上安装中文环境
现在vps默认都是安装的英文环境,其实变成中文环境也很简单.我记录以下在ubuntu下如何改变为中文环境. 1.安装中文环境包. sudo apt install language-pack-zh-h ...
- jquery定时器的简单代码
当收到消息的时候能够及时的刷新,显示收到消息的条数,下面与大分享下使用简单的代码实现jquery定时器 简单的代码实现jquery定时器. 今天,项目遇到一个消息的模块,在导航条最上面.想实现,当收到 ...
- 【Android】12.5 利用Intent读取和更新通讯录
分类:C#.Android.VS2015: 创建日期:2016-02-23 修改日期:2016-03-08更正了未关闭cursor的bug. 一.简介 本节演示如何在安卓系统中通过用户配置文件(us ...
- C语言可变参数宏及‘##’在可变参数中的作用
测试代码及解释: #include <stdio.h> #define PRINT(x) printf x #define SECONDPRINT(fmt,arg...) printf(f ...
- Oracle PLSQL Demo - 06.LOOP循环,以IF判断退出[IF in LOOP]
declare v_sal ; begin loop v_sal :; dbms_output.put_line(v_sal); then exit; end if; end loop; end;
- PairRDD中算子combineByKey图解
1.combineByKey combine 为结合意思. 作用: 将RDD[(K,V)] => RDD[(K,C)] 表示V的类型可以转成C两者可以不同类型. def combineBy ...
- 回调形成树形结构tree
//Tree.vue <template> <li> <span @click="toggle"> <i v-if="isFol ...
- Dubbo阅读笔记——高级功能
事件处理线程说明 如果事件处理的逻辑能迅速完成,并且不会发起新的IO请求,比如只是在内存中记个标识,则直接在IO线程上处理更快,因为减少了线程池调度. 但如果事件处理逻辑较慢,或者需要发起新的IO请求 ...