题目信息

1077. Kuchiguse (20)

时间限制100 ms

内存限制65536 kB

代码长度限制16000 B

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

解题思路

反转字符串后逐个字符比較

AC代码

#include <iostream>
#include <string>
#include <algorithm>
using namespace std; int main()
{
int n;
vector<string> v;
string s, rs;
cin >> n;
getline(cin, s);// 去掉回车
while (n--){
getline(cin, s);
reverse(s.begin(), s.end());
v.push_back(s);
}
int loc = -1;
bool flag = true;
while (flag && ++loc < v[0].size()){
for (int i = 0; i < v.size(); ++i){
if (v[i][loc] != v[0][loc]){
flag = false;
break;
}
}
if (flag){
rs += v[0][loc];
}
}
if (rs.empty()){
cout <<"nai" <<endl;
}else{
reverse(rs.begin(), rs.end());
cout <<rs <<endl;
}
return 0;
}

1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise的更多相关文章

  1. 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise

    题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...

  2. PAT (Advanced Level) Practise - 1092. To Buy or Not to Buy (20)

    http://www.patest.cn/contests/pat-a-practise/1092 Eva would like to make a string of beads with her ...

  3. 1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise

    题目信息 1069. The Black Hole of Numbers (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B For any 4-digit inte ...

  4. PAT (Advanced Level) Practise - 1096. Consecutive Factors (20)

    http://www.patest.cn/contests/pat-a-practise/1096 Among all the factors of a positive integer N, the ...

  5. PAT (Advanced Level) Practise - 1094. The Largest Generation (25)

    http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...

  6. PAT (Advanced Level) Practise - 1095. Cars on Campus (30)

    http://www.patest.cn/contests/pat-a-practise/1095 Zhejiang University has 6 campuses and a lot of ga ...

  7. PAT (Advanced Level) Practise 1001 解题报告

    GiHub markdown PDF 问题描述 解题思路 代码 提交记录 问题描述 A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判 ...

  8. PAT (Advanced Level) Practise 1004 解题报告

    GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...

  9. PAT (Advanced Level) Practise - 1093. Count PAT's (25)

    http://www.patest.cn/contests/pat-a-practise/1093 The string APPAPT contains two PAT's as substrings ...

随机推荐

  1. unity c# script error CS0664: Literal of type double cannot be implicitly converted to type `float'. Add suffix `f' to create a literal of this type

    例如在unity c# script中定义 private float x=0.0; 则会报 error CS0664: Literal of type double cannot be implic ...

  2. Java web中listener、 filter、servlet 加载顺序

    真正的加载顺序为:context-param -> listener -> filter -> servlet 加载顺序与它们在 web.xml 文件中的先后顺序无关.即不会因为 f ...

  3. JAVA:认识多线程

    曾经古老的DOS操作系统是单任务的.还没有线程的概念,系统在每次仅仅能做一件事情.比方你在copy东西的时候不能rename文件名称. 为了提高系统的利用效率,採用批处理来批量运行任务. 如今的操作系 ...

  4. VS2015预览版体验

    .NET开源了,JAVA颤抖吧... 据说VS2015可以开发android,ios,wp应用程序了,还可以开发能运行在mac,linux上的ASP.NET网站,如果真是这样就太爽啦,上微软官网下载了 ...

  5. ISE联合modelsim功能仿真和综合后仿真1

    1.代码输入 (1).新建一个ISE工程,名字为count4. (2).新建一个verilog文件 (3).选择verilog module 输入file name为count4,单击next默认知道 ...

  6. CocoaPods did not set the base configuration of your project 问题解决方式

    今天在使用pod install的时候.出现了 [!] CocoaPods did not set the base configuration of your project because you ...

  7. JDK自带工具之问题排查场景示例

    最近看到了大量关于java性能调优.故障排查的文章,自己也写了一篇< Java调优经验谈 >.接着此篇文章,其实一直打算写写一些常用调优工具以及它们的惯常用法的.后来在http://jav ...

  8. Oracle PLSQL Demo - 10.For Loop遍历游标[FOR LOOP CURSOR]

    declare cursor cur_emp is select t.* from scott.emp t; begin for r_emp in cur_emp loop dbms_output.p ...

  9. solr进阶九:solr对数字和单个字符的搜索

    solr中配有分词器,但分词器里面有大写转换为小写的过滤器时,数字就会被过滤.比如123中国ABC.123就会被过滤掉了,所以才查1|12|123都会失败. <Solr 数字字符不能搜索的一个问 ...

  10. Kibana查询说明

    elasticsearch构建在Lucene之上,过滤器语法和Lucene相同 Kibana接口概述 Kibana接口分为四个主要部分: 发现 可视化 仪表板 设置 我们将按照列出的顺序浏览每个部分的 ...