1077. Kuchiguse (20)

时间限制
100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
HOU, Qiming

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的更多相关文章

  1. PAT1077. Kuchiguse (20)

    #include <iostream> #include <vector> #include <sstream> using namespace std; int ...

  2. 1077. Kuchiguse (20)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  3. PAT 1077 Kuchiguse

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  4. A1077. Kuchiguse

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  5. PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】

    1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

  6. 1077 Kuchiguse (20 分)

    1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

  7. 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise

    题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...

  8. PAT 甲级 1077 Kuchiguse

    https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...

  9. PAT 1077 Kuchiguse [一般]

    1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

随机推荐

  1. libevent之event

    就如libevent官网上所写的“libevent - an event notification library”,libevent就是一个基于事件通知机制的库,可以看出event是整个库的核心.e ...

  2. Leetcode_75_Sort Colors

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43302343 Given an array with n  ...

  3. Android平台根目录文件

    > 系统分区 # adb shell # mount rootfs / rootfs ro 0 0 tmpfs /dev tmpfs rw,mode=755 0 0 devpts /dev/pt ...

  4. 客户端状态的存储空间——Session

    http协议在设计之初被设计成无状态特性,客户端的每次请求在服务端看来都是独立且无任何相关性,同一个客户端第一次请求不会与第二次请求有任何关联,即使相隔时间很短.无状态的特性让请求变得很快速且服务器也 ...

  5. android查看源码的时候看不了

    原因:未关联android中jar包源码 解决方案:导入sdk---->>resource---->>api 这样就可以在代码中查看源码了.

  6. ITU-T Technical Paper: QoS 的参数(非常的全,共计88个)

    本文翻译自ITU-T的Technical Paper:<How to increase QoS/QoE of IP-based platform(s) to regionally agreed ...

  7. Android开源经典项目

    目前包括: Android开源项目第一篇--个性化控件(View)篇   包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView. ...

  8. Paxos 算法

    1 概述 Paxos算法是莱斯利·兰伯特(Leslie Lamport,就是 LaTeX 中的"La",此人现在在微软研究院)于1990年提出的一种基于消息传递的一致性算法.[1] ...

  9. LeetCode - 二叉树的最大深度

    自己解法,欢迎拍砖 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例:给定二叉树 [3,9,20,null,nu ...

  10. PyCharm导入pymysql包运行报错问题解决:No module named 'PyMySQL'

    import pymysql # 导入包 # 报错问题显示: ImportError: No module named 'PyMySQL' 出现该问题提示:找不到该包名. 解决办法如下: ①先下载Py ...