077 Kuchiguse
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
题意:
找出最长公共后缀。
思路:
模拟。
Code:
#include <bits/stdc++.h> using namespace std; int main() {
int n;
cin >> n;
getchar();
string last, cur, temp;
for (int i = 0; i < n; ++i) {
if (i == 0)
getline(cin, last);
else {
temp = "";
getline(cin, cur);
int len1 = cur.length() - 1;
int len2 = last.length() - 1;
while (len1 >= 0 && len2 >= 0) {
if (cur[len1--] == last[len2]) {
temp = last[len2--] + temp;
} else
break;
}
last = temp;
}
}
if (last.length() == 0)
cout << "nai" << endl;
else {
for (int i = 0; i < temp.length(); ++i) cout << temp[i];
cout << endl;
}
return 0;
}
077 Kuchiguse的更多相关文章
- 1077. Kuchiguse (20)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT1077: Kuchiguse
1077. Kuchiguse (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming The Japan ...
- PAT 1077 Kuchiguse
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- A1077. Kuchiguse
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- 1077 Kuchiguse (20 分)
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
https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...
- PAT 1077 Kuchiguse [一般]
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
随机推荐
- ServiceMesh
传统微服务架构 在微服务模式下,企业内部服务少则几个到几十个,多则上百个,每个服务一般都以集群方式部署,这时自然产生两个问题: 一.服务发现:服务的消费方(Consumer)如何发现服务的提供方(Pr ...
- 后端程序员之路 10、gbdt(Gradient Boosting Decision Tree)
1.GbdtModelGNode,含fea_idx.val.left.right.missing(指向left或right之一,本身不分配空间)load,从model文件加载模型,xgboost输出的 ...
- 少走弯路之marshalsec的编译(RMI必备工具)
0x00 实验环境 实验机:Ubuntu18(公网Linux系统) 0x01 安装包 私聊我博客将会第一时间提供安装包环境: 0x02 避坑指南 由上篇文章:https://www.cnblo ...
- 白嫖微软Azure12个月服务器
前言 Azure是微软提供的一个云服务平台.是全球除了AWS外最大的云服务提供商.Azure是微软除了windows之外另外一个王牌,微软错过了移动端,还好抓住了云服务.这里的Azure是Azure国 ...
- Shell:如何写一个多选菜单的脚本
Blog:博客园 个人 翻译自How to Create a Multiple Choice Menu in Bash Scripts 目录 多选菜单脚本介绍 配置输入提示 创建预定选项列表 创建预选 ...
- gulp打包详解
gulp的作用 删除文件中冗余的内容,压缩文件,减小文件体积 实际项目中运行的都是压缩完成以后的文件 减小加载响应时间 gulp打包压缩对象 html,css,js,sass,webserver 音频 ...
- 1x1卷据层的作用
1. 尽管1x1的卷据不会捕捉空间特征(spatial features/patterns,直观点说就是2D平面图的纹理特征),但是他们能很好基于通道(channel-wise/along the d ...
- C# 8.0 宝藏好物 Async streams
之前写<.NET gRPC 核心功能初体验>,利用gRPC双向流做了一个打乒乓的Demo,存储消息的对象是IAsyncEnumerable<T>,这个异步可枚举泛型接口支撑了g ...
- Hadoop学习笔记—HDFS
目录 搭建安装 三个核心组件 安装 配置环境变量 配置各上述三组件守护进程的相关属性 启停 监控和性能 Hadoop Rack Awareness yarn的NodeManagers监控 命令 hdf ...
- [Fundamental of Power Electronics]-PART I-6.变换器电路-0 序
6 变换器电路 我们已经分析了包括buck,boost,buck-boost以及cuk电路,电压源逆变器等一系列电路的工作原理.利用这些变换器,可以执行许多不同的功能:降压,升压,极性反转以及直流交流 ...