PAT1077: Kuchiguse
1077. Kuchiguse (20)
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 思路 求输入的几个字符串的最长公共后缀。
用一个cmstr暂时记录最长公共后缀,然后对于每一个输入的新字符串循环比较更新就行。 代码
#include<iostream>
using namespace std;
int main()
{
int N;
cin >> N;
string cmstr;
getchar();
for(int i = 0; i < N; i++)
{
string s;
getline(cin,s);
const int len = s.size();
for(int j = 0; j < len/2; j++)
{
swap(s[j],s[len - j - 1]);
}
if(i == 0)
{
cmstr = s;
continue;
}
else
{
int minlen = len > cmstr.size()?cmstr.size():len;
for(int v = 0; v < minlen; v++)
{
if(cmstr[v] != s[v])
{
cmstr = cmstr.substr(0,v);
break;
}
}
} }
if(cmstr.size() == 0)
cout << "nai" <<endl;
else
{
for(int i = cmstr.size() - 1;i >= 0;i--)
{
cout << cmstr[i];
}
}
}
PAT1077: Kuchiguse的更多相关文章
- PAT1077. Kuchiguse (20)
#include <iostream> #include <vector> #include <sstream> using namespace std; int ...
- 1077. Kuchiguse (20)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- 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 ...
随机推荐
- RHEL6下获取安装包(RPM)而不安装的方法
RHEL6下获取安装包(RPM)而不安装的方法 有时候我们只能在某个机器上网获得RPM安装包,如何将RPM包在不能上网的内网机器安装,就需要能将安装包下载到本地而不安装,然后再把这些包复制到内网机器, ...
- android Google推荐的容器SparseArrayCompat简介
android Google推荐的容器SparseArrayCompat简介 private static SparseArrayCompat<BaseFragment> mCaches ...
- VC工程的.gitignore模板
VC工程的.gitignore模板 文件内容如下: #====================================== # .gitignore # # 2015-01-09 create ...
- 【线性代数】标准正交矩阵与Gram-Schmidt正交化
1.标准正交矩阵 假设矩阵Q有列向量q1,q2,...,qn表示,且其列向量满足下式: 则 若Q为方阵,由上面的式子则有 我们举例说明上述概念: 2.标准正交矩阵的好处 上面我们介绍了标准正交 ...
- LeetCode之“动态规划”:Distinct Subsequences
题目链接 题目要求: Given a string S and a string T, count the number of distinct subsequences of T in S. A s ...
- android SurfaceView绘制实现原理解析
在Android系统中,有一种特殊的视图,称为SurfaceView,它拥有独立的绘图表面,即它不与其宿主窗口共享同一个绘图表面.由于拥有独立的绘图表面,因此SurfaceView的UI就可以在一个独 ...
- OpenCV图片矩阵操作相关,对png图片操作(多通道)
文献链接: http://www.cnblogs.com/tornadomeet/archive/2012/12/26/2834336.html 下面这个高手,写了个小程序我还没有调试,回头 调试看看 ...
- ZooKeeper 会话超时
1.会话概述 在ZooKeeper中,客户端和服务端建立连接后,会话随之建立,生成一个全局唯一的会话ID(Session ID).服务器和客户端之间维持的是一个长连接,在SESSION_TIMEOUT ...
- java--交通灯管理系统
转载请申明出处:http://blog.csdn.net/xmxkf/article/details/9944947 .交通灯管理系统的业务和需求分析 交通灯管理系统的项目需求: 模拟实现十字路口的交 ...
- linux下32位汇编调用规则
传递给系统调用的参数必须安装参数顺序一次放到寄存器中,当系统调用完成后,返回值放在eax中: 当系统调用参数<=5个时: eax中存放系统调用的功能号,传递给系统调用的参数顺序依次放到寄存器:e ...