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). 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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int main(){ int t;scanf("%d",&t);
vector<string> vec;
int minlenn = INT_MAX;
string temp;getline(cin,temp);
while(t--){
string s;getline(cin,s);
string temp="";
for(int i=;i < s.size();i++){
temp = s[i]+temp;
}
vec.push_back(temp);
int len = s.size();
minlenn = min(minlenn,len); //直接把s.size()放进去不对???
}
// cout << vec.size(); string res = "";
for(int i=;i < minlenn;i++){
char sx = vec[][i];
bool flag = ;
for(int j=;j < vec.size();j++){
if(vec[j][i] != sx){
flag = ;
break;
}
}
if(flag){
res = sx+res;
}
else break;
}
if(res == "")cout << "nai";
else cout << res; return ;
}

——遇到情况多样的题目,可以大胆的猜测,只要先过样例就行。

在getline前如果有cin 会读取结尾的\0

PAT 1077 Kuchiguse的更多相关文章

  1. PAT 1077 Kuchiguse [一般]

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

  2. pat 1077 Kuchiguse(20 分) (字典树)

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

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

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

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

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

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

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

  6. 1077 Kuchiguse (20 分)

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

  7. PAT 1077. 互评成绩计算

    PAT 1077. 互评成绩计算 在浙大的计算机专业课中,经常有互评分组报告这个环节.一个组上台介绍自己的工作,其他组在台下为其表现评分.最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个 ...

  8. PAT 甲级 1077 Kuchiguse

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

  9. PAT Advanced 1077 Kuchiguse (20 分)

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

随机推荐

  1. caffe报错:cudnn.hpp:86] Check failed: status == CUDNN_STATUS_SUCCESS (3 vs. 0) CUDNN_STATUS_BAD_PARAM 原因

    在实际项目中出现的该问题,起初以为是cudnn版本的问题,后来才定位到在网络进行reshape操作的时候 input_layer->Reshape({(), input_layer->sh ...

  2. iptables精通

    前提基础: 当主机收到一个数据包后,数据包先在内核空间中处理,若发现目的地址是自身,则传到用户空间中交给对应的应用程序处理,若发现目的不是自身,则会将包丢弃或进行转发. iptables实现防火墙功能 ...

  3. Py中查看数据类型【转载】

    转自:https://www.jianshu.com/p/bb5cc438e3b2 1.内置函数isinstance(object, (type1,type2...)) isinstance('con ...

  4. python 转换容量单位 实现ls -h功能

    功能1 把字节转换自适应转为其他单位(ls -h),超过1024投入高一级的区间,不足1024投入本级区间,如1000K是一个合理值,1030K就应该转换为1M,2050K应该转换为2M 功能2 把其 ...

  5. chrome下调试安卓app 之 ionic

    打开chrome浏览器,输入chrome://inspect/#devices,将安卓手机插入电脑上,打开手机设置 打开 开发者调试usb调试 ,网页上会出现 input 点击, 就会看见consol ...

  6. C工程 交互 ceph 分布式存储系统

    网上看到有人问,如何在C项目里调用ceph系统对外提供的API,实现分布式存储. 我在网上搜到了相关信息,但是因为不是会员无法追加答案,故而,贴于此. 赠予有缘人:) ———————————————— ...

  7. Chrome调试WebView时Inspect出现空白的解决方法(使用离线包不Fan墙)

    起因 使用HTML5开发Android应用时,少不了调试WebView.做前端的还是习惯Chrome的开发者工具,以前都是输入Chrome://inspect就可以调试WebView了,太方便了. 最 ...

  8. 对字符串md5加密

    public String getMD5(String str) { try { // 生成一个MD5加密计算摘要 MessageDigest md = MessageDigest.getInstan ...

  9. C#窗体程序与sql sever 数据库链接

    一.所用工具 Visual Studio 2017和SQL Server Management Studio 2012 二.连接 打开SQL Server Management Studio 2012 ...

  10. flask 定义数据库关系(一对一)

    一对一 我们将使用国家和首都来演示一对一关系:每个国家只有一个首都.反过来,一个城市也只能作为一个国家的首都.一对一关系如下: 在示例程序中,Country类表示国家,Capital类表示首都.建立一 ...