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 ...
随机推荐
- 力扣896. 单调数列-C语言实现-简单题
题目 传送门 文本 如果数组是单调递增或单调递减的,那么它是单调的. 如果对于所有 i <= j,A[i] <= A[j],那么数组 A 是单调递增的. 如果对于所有 i <= j, ...
- javascript中的模块系统
目录 简介 CommonJS和Nodejs AMD异步模块加载 CMD ES modules和现代浏览器 在HTML中使用module和要注意的问题 简介 在很久以前,js只是简单的作为浏览器的交互操 ...
- 看完我的笔记不懂也会懂----less
目录 Less学习 语法篇 注释 变量 映射(Maps) @规则嵌套和冒泡 less中的嵌套规则 less中的混合 less的运算 extend延伸/继承 less忽略编译(转义) 导入(Import ...
- 防数据泄露_MySQL库和数据安全
目录 攻击场景 外部入侵 内部盗取 防御体系建设 参考 在企业安全建设中有一个方向是防数据泄露,其中一块工作就是保障数据库安全,毕竟这里是数据的源头.当然数据库也分不同的种类,不同类型的数据库的防护手 ...
- 200-Java语言基础-Java编程入门-005 | Java方法定义及使用
一.方法概述和格式说明 为什么要用方法: 提高代码的复用性 什么是方法: 完成特定功能的代码块 方法的格式: 修饰符 返回值类型 方法名(参数类型 参数名1,参数类型 参数名2...) { 方 ...
- Kettle连接数据库失败
Kettle是使用Java开发,开源的一款ETL工具,这里记录一下关于Kettle有关于数据库连接的问题 1.mysql版本需要注意区分,在mysql8.0的文档中官方已经给出,使用caching_s ...
- Apache配置 8.配置防盗链
(1)介绍 防盗链,通俗讲,就是不让别人盗用你网站上的资源.这个资源,通常指的是图片.视频.歌曲.文档等. (2)配置 配置防盗链先编辑主机配置文件: #vim /usr/local/apache2. ...
- github个人主页 阿里云域名的绑定
域名解析 我在阿里云上买了一个新域名:gaolu.name,我已经在GitHub Pages上建立了自己的博客:http://gaolu1215.github.io.现在我希望将gaolu.name映 ...
- go语言实现数组去重
import ( "fmt" ) func main() { a := []int{2, 1, 2, 5, 6, 3, 4, 5, 2, 3, 9} z := Rm_duplica ...
- Visual Studio添加引用的方式