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 ...
随机推荐
- jquery动态赋值id与动态取id方法
$("#" + packageNameId + "").text(packageName); $("#" + packageNumId + ...
- 无需编程,通过配置零代码生成CRUD RESTful API
Hello,crudapi!(你好,增删改查接口!) 本文通过学生对象为例,无需编程,通过配置实现CRUD RESTful API. 概要 CRUD简介 crud是指在做计算处理时的增加(Create ...
- C++ 中的虚函数表及虚函数执行原理
为了实现虚函数,C++ 使用了虚函数表来达到延迟绑定的目的.虚函数表在动态/延迟绑定行为中用于查询调用的函数. 尽管要描述清楚虚函数表的机制会多费点口舌,但其实其本身还是比较简单的. 首先,每个包含虚 ...
- 2020年12月-第02阶段-前端基础-CSS初识
CSS层叠样式表 理解 css的目的作用 css的三种引入方式 1.HTML的局限性 说起HTML,这其实是个非常单纯的家伙, 他只关注内容的语义, 比如`<h1>`表明这是一个大标题,用 ...
- 用vue.js实现的期货,股票的实时K线
用vue.js实现的期货,股票的实时k线 项目地址:https://github.com/zhengquantao/vue-Kline vue-kline 效果图 Build Setup 本项目基于V ...
- python3中post和get请求处理
post 请求处理 def url(): url = "www.xxx.com.cn" data = { "csrfmiddlewaretoken":" ...
- 漫漫Java路1—基础知识—初涉java
前言 主学信息安全,在编程的路上还是一个孩子,还在一步一步探索,有些东西可能是站在自己的位置思考的,很可能会出现一些啼笑皆非的错误,如果有误,还希望各位斧正. Java安装 jdk的安装 甲骨文官网选 ...
- 测试工程师Docker基础
一.docker概述 1.docker为什么会出现 本质:所有技术的出现都是因为出现了一些问题,我们需要去解决,才去研究和学习: 问题: 开发环境.测试环境.仿真环境.正式环境等诸多环境都需要进行 ...
- 内置了一个缓冲区(数组)缓冲流BufferInputStream为何要配合字节数组的使用?
内置了一个缓冲区(数组)缓冲流BufferInputStream为何要配合字节数组的使用? 只为效率而积累[积少成多送一趟比送多趟快] 举例子:超市买30个鸡蛋回家煮 (1)读一个送一个(效率太低啦) ...
- Git Fetch failed解决办法
Git 下拉过程中,电脑死机了,重启后出现问题 找到的解决办法 https://blog.csdn.net/qq_33330887/article/details/80242206