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

分析: 求字符串的公共后缀。思路是先逆置字符串,然后从第一个开始比较。
 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-24-21.51.09
 * Description : A1077
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;
 ;
 string a[maxn];
 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     ;
     cin>>n;
     getchar();
     ;i<n;i++){
         getline(cin,a[i]);
         int len=a[i].size();
         if(minlen>len) minlen=len;
         reverse(a[i].begin(),a[i].end());
     }
     string ans="";
     ;i<minlen;i++){
         ][i];
         bool same=true;
         ;j<n;j++){
             if(c!=a[j][i]){
                 same=false;
                 break;
             }
         }
         if(same) ans+=c;
         else break;
     }
     if(ans.size()){
         reverse(ans.begin(),ans.end());
         cout<<ans;
     }
     else{
         cout<<"nai";
     }
     ;
 }

1077 Kuchiguse (20 分)的更多相关文章

  1. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

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

  2. PAT Advanced 1077 Kuchiguse (20 分)

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

  3. PAT甲级——1077.Kuchiguse(20分)

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

  4. 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)

    题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...

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

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

  6. 1077. Kuchiguse (20)

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

  7. PAT (Advanced Level) 1077. Kuchiguse (20)

    最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...

  8. PAT甲题题解-1077. Kuchiguse (20)-找相同后缀

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  9. PAT 1077 Kuchiguse

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

随机推荐

  1. ansible 删除路径下的多个文件[收集的参考]

    How to delete multiple files / directories in Ansible ansible - find, file modules to delete files a ...

  2. 量身打造自己的MyEclipse(多图)

    迎新年 贺元旦MyEclipse推新版 在线订购低至 7.5 折!截止1月31号(活动期间在线下单的客户才可享受此优惠,过期恢复原价) 立即抢购 1.量身打造你自己的MyEclipse MyEclip ...

  3. SWIFT中获取当前经伟度

    很多的APP中都会用到用户的当前位置信息,本文将实现这个小功能 import UIKit import CoreLocation //添加引用 class ViewController: UIView ...

  4. Linux文件共享(单进程之间、多进程之间)

    转载:https://www.cnblogs.com/frank-yxs/p/5925603.html 在同一个进程中,实现文件共享的方法有两种: 多次使用open函数打开相同文件 使用dup/dup ...

  5. SIM800C Couldn't pair with xxx because of an incorrect PIN or passkey

    /******************************************************************************* * SIM800C Couldn't ...

  6. hdu1165 规律递推

    题意:给了公式,求A(m,n). 并不知道为什么被杭电分类塞进了dp专题,但是我一开始显然看到这个题就觉得给那个公式用函数递归一下答案肯定能出来了,只不过既然放在了dp专题里面估计这样暴力求解会TLE ...

  7. IP相关的方法

    1.验证是否为IP地址 def isIP(ip, with_netmask=True): """ 判断IP的格式是否正确 :param ip: IP字符串 :param ...

  8. Eclipse+Spring学习(一)环境搭建(转)

    最近由于投了一家公司实习,他要java工程师,而我大学3年的精力都花到了ASP.NET和前端上面,到找工作的时候才发现大公司不要.NET的,所以马上转型java...由于网上的高手都不屑于写这类文章, ...

  9. oracle 变量作用域

    以下为测试 代码块DECLARE  v_i number := 100;  v_p VARCHAR2(200) := 'a';BEGIN  DECLARE    v_i number := 999;  ...

  10. mockito框架

    2016-04-09 15:56:26 参考自 http://www.cnblogs.com/silence-hust/p/5017233.html http://blog.csdn.net/sdyy ...