题目信息

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. python标准库介绍——18 StringIO 模块详解

    ==StringIO 模块== [Example 2-8 #eg-2-8] 展示了 ``StringIO`` 模块的使用. 它实现了一个工作在内存的文件对象 (内存文件). 在大多需要标准文件对象的地 ...

  2. jetty上传文件的时候报错显示文件过大

    这个时候我们需要修改jetty的参数文件 cd /data/java_web_app/news23456/etc vim jetty.xml 找到这一行 <Configure id=" ...

  3. php 多进程解决代码常驻内存的问题php 多进程解决代码常驻内存的问题

    PHP不适合做常驻的SHELl进程,因为它没有专门的gc例程,也没有有效的内存管理途径. 如果用PHP做常驻SHELL,会经常被内存耗尽导致abort而unhappy. 而且,如果输入数据非法,而脚本 ...

  4. php分割字符串方法速度比較(substr/sscanf/preg_match)

    固定長度的字串(假設是 06481a63041b578d702f159f520847f8), 要照固定格式做切割, 使用 PHP 要怎麼切會比較快? 註: 要將此字串切成 => 06 / 48 ...

  5. Spark1.4.1 编译与安装

    1.下载下载地址:http://spark.apache.org/downloads.html 选择下载源码 2.源码编译1)解压tar -zxvf spark-1.4.1.tgz2.编译spark有 ...

  6. Oracle学习笔记之四sp1,Oracle 11g的常用函数

    从Oracle学习笔记之四,SQL语言入门中摘出来的,独立成一章节 3.1 字符类函数 ASCII(c)和CHR(i)    分别用于返回一个字符的ASCII码和返回给定ASCII值所对应的字符. C ...

  7. 在 ASP.NET Web API 中,使用 命名空间(namespace) 来作为路由的参数

    这个问题来源于我想在 Web API 中使用相同的控制器名称(Controller)在不同的命名空间下,但是 Web API 的默认 路由(Route) 机制是会忽略命名空间的不同的,如果这样做,会看 ...

  8. 【转】SQL SERVER 获取存储过程返回值

    1.OUPUT参数返回值 CREATE PROCEDURE [dbo].[nb_order_insert]( @o_buyerid int , @o_id bigint OUTPUT ) AS BEG ...

  9. 2015小米暑期实习笔试题_风口的猪-中国牛市(dp)

    风口之下.猪都能飞.当今中国股市牛市,真可谓"错过等七年". 给你一个回想历史的机会,已知一支股票连续n天的价格走势,以长度为n的整数数组表示,数组中第i个元素(prices[i] ...

  10. js实现页面时间动态变化

    利用函数嵌套和setTimeout函数实现时间动态变化 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYe ...