题目信息

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. C 指针使用误区

    /** *错误给指针赋常量 *知识点:指针存储内存地址 **/ #include <stdio.h>void main(){ //int *p_int = 123; //错误,不能直接给指 ...

  2. js左侧三级菜单导航实例代码

    在左侧三级菜单导航想必大家都见到过吧,它的实现过程也并不复杂,下面有个不错的示例,感兴趣的朋友可以了解下 实例代码:   <!DOCTYPE html PUBLIC "-//W3C// ...

  3. 【Android】7.7 以后改为在Win10下开发了

    分类:C#.Android.VS2015: 创建日期:2016-02-12 修改日期:2016-02-13 一.鼠标点击时千万别一心二用 在Win10升级提醒不厌其烦的持续轰炸下,今天看手机时一不留神 ...

  4. Linux系统中 Sublime Text 中文 GBK 文件乱码问题

    Sublime Text 是一个很不错编辑器,具有漂亮的界面和强大的功能.再加上丰富的插件,而且还跨平台,绝对是一款实打实的神器啊! 众所周知,Sublime Text 对中文支持的极差,可以说几乎就 ...

  5. iOS-ARC-环境下如何查看引用计数的变化

    iOS-ARC-环境下如何查看引用计数的变化 一,新建立一个工程,用于测试引用计数的变化. 二,找到如下路径Build Phases---->Compile Sources---->App ...

  6. vue实现复制粘贴的两种形式

    方式一: 1.安装clipboard:npm install clipboard 2.src/utils/clipboard.js import Vue from 'vue' import Clipb ...

  7. maven引入ojdbc

    http://blog.csdn.net/linminqin/article/details/17922413 ******************************************** ...

  8. Python2 获取两日期之间的每一天

    import datetime def getEveryDay(begin_date,end_date): date_list = [] begin_date = datetime.datetime. ...

  9. 利用GDB对程序进行调试

    第一章初涉调试会话 调试工具 GDB,Unix下最常用的调试工具 DDD,基于GUI的调试器,大多数工具都是GDB的GUI前端. Eclipse,IDE也是一种调试工具 atoi( )把字符串变为整数 ...

  10. Ubuntu下安装Apache

    Ubuntu为我们提供了 su apt-get install 命令,通过它你可以很方便地安装一些软件,这些软件是放在Ubuntu放置在各个地方的服务器上面,如果你想安装的软件是比较常见的,一般都可以 ...