PAT_A1077#Kuchiguse
Source:
Description:
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
Keys:
- 模拟题
Attention:
- s.insert(s.begin()+pos, str[i]),s.insert(pos, str)
- 使用getline(cin,str),注意吃掉上一行的换行符
Code:
#include<cstdio>
#include<string>
#include<iostream>
using namespace std; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
string s,t;
scanf("%d\n", &n);
getline(cin,s);
for(int i=; i<n; i++)
{
getline(cin,t);
string p;
int ps=s.size()-,pt=t.size()-;
while(ps>= && pt>= && s[ps]==t[pt])
{
p.insert(p.begin(),s[ps]);
ps--;
pt--;
}
s = p;
}
if(s.size())
cout << s;
else
printf("nai"); return ;
}
PAT_A1077#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 ...
随机推荐
- 利用Lua实现二叉查找树并进行各种遍历
-- author : coder_zhang-- date : 2014-6-25 root = nil function insert_node(number) if root == nil th ...
- 最小生成树,Prim算法实现
最小生成树 所谓最小生成树,就是一个图的极小连通子图,它包含原图的所有顶点,并且所有边的权值之和尽可能的小. 首先看看第一个例子,有下面这样一个带权图: 它的最小生成树是什么样子呢?下图绿色加粗的边可 ...
- 使用easyui框架 设置时间格式
之前做的一个商城项目,后台系统页面使用Easyui做的,记录一个当时卡住的地方: 首先通过<table>标记创建数据网格(datagrid) <table class="e ...
- vue 页面切换从右侧切入效果
1.将切换的页面用transition包裹 <div class="index-content"> <transition> <router-view ...
- C语言获取当前时间
#include <stdio.h> #include <time.h> void main () { time_t rawtime; struct tm * timeinfo ...
- python常用函数 P
popleft(iterable) 对应pop,左侧弹出,队列适用. 例子: permutations(iterable, int) itertools的permutations方法可以产生集合的所有 ...
- django学习笔记--数据库中的多表操作
1.Django数据库----多表的新增操作 1.一对一模式下新增 创建一个详情对象,把这个对象赋值给创建的新的user对象 author_detail = models.AuthorDetail.o ...
- mysql的锁
前言 mysql锁的概念参考如下连接: 1.http://blog.csdn.net/u013063153/article/details/53432468 2.http://www.yesky.co ...
- 二、Angular项目创建、安装、启动
1.项目创建,进入预先存放项目的路径,命令行执行 ng new ProjectName 创建成功后的项目 2.项目安装,进行项目中执行命令 npm install 3. 项目运行,执行命令 ng s ...
- java泛型通配符详解
前言 泛型带来的好处 泛型中通配符 常用的 T,E,K,V,? ?无界通配符 上界通配符 < ? extends E> 下界通配符 < ? super E> ?和 T 的区别 ...