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 ...
随机推荐
- [Jobdu] 题目1545:奇怪的连通图
题目描述: 已知一个无向带权图,求最小整数k.使仅使用权值小于等于k的边,节点1可以与节点n连通. 输入: 输入包含多组测试用例,每组测试用例的开头为一个整数n(1 <= n <= 100 ...
- Regression Analysis Using Excel
Regression Analysis Using Excel Setup By default, data analysis add-in is not enabled. Follow the st ...
- 【Android】19.0 第19章 前面章节的代码优化及本章示例主界面
分类:C#.Android.VS2015: 创建日期:2016-03-05 一.简介 这一章我们介绍"共享存储和内容提供程序"的基本用法. 二.先优化一下前面章节例子的代码 在前面 ...
- MySQL数据库如何去掉数据库中重复记录
对于常规的MySQL数据表中可能存在重复的数据,有些情况是允许重复数据的存在,有些情况是不允许的,这个时候我们就需要查找并删除这些重复数据,以下是具体的处理方法! 方法一:防止表中出现重复数据 当表中 ...
- Cortex-A
本文整理了arm cortexA 系列的CPU的相关信息,以便在芯片选型时提供帮助. Cortex-A发布时间 Cortex-A 支持的位数及架构 Cortex-A 系列的芯片 ARMv7-A内核的比 ...
- C++11 long long使用及输出
相比于C++98标准,C++11整型的最大改变就是多了 long long.分为两种:long long 和unsigned long long.在C++11中,标准要求long long 整型可以在 ...
- IDEA开发工具常用快捷键总结
Ctrl+Alt+V 快速补全变量名 Alt+Enter 自动修复 psvm 生成main方法 Ctrl+X 删除一行 Ctrl+D 复制一行 Ctrl+N 查找类 Ctrl+P 显示方法参数 Ctr ...
- 有趣的switch应用(填入种类,显示响应的价格)
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 如何保证RabbitMQ的消息不丢失及其背后的原理
一.消息为什么丢失 RabbitMQ默认情况下的交换机和队列以及消息是非持久化的,也就是说在服务器重启或者宕机恢复后,之前创建的交换机和队列都将不复存在,之前未消费的消息也就消失不见了.原因在于每个队 ...
- FreeRTOS 低功耗之停机模式
以下转载自安富莱电子: http://forum.armfly.com/forum.php STM32F103 如何进入停机模式在 FreeRTOS 系统中,让 STM32 进入停机模式比较容易,调用 ...