PAT 1077 Kuchiguse
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的更多相关文章
- PAT 1077 Kuchiguse [一般]
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- pat 1077 Kuchiguse(20 分) (字典树)
1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise
题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- 1077 Kuchiguse (20 分)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- PAT 1077. 互评成绩计算
PAT 1077. 互评成绩计算 在浙大的计算机专业课中,经常有互评分组报告这个环节.一个组上台介绍自己的工作,其他组在台下为其表现评分.最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个 ...
- PAT 甲级 1077 Kuchiguse
https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...
- PAT Advanced 1077 Kuchiguse (20 分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
随机推荐
- python类型错误:'NoneType' object is not subscriptable
TypeError: 'NoneType' object is not subscriptable --> 原因:变量使用了系统内置的关键字list 解决:重新定义下这个变量
- linux环境如何配置repo
(1)下载repo mkdir ~/bin curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo ...
- #WEB安全基础 : HTTP协议 | 0x4 各种协议与HTTP协议的关系(一个报文的旅行)
报文是怎么旅行的呢? 在网络中有很多引路人,如HTTP协议,IP协议.TCP协议.DNS协议以及ARP协议. 请看下图,演绎一个报文的旅程 这就是一个报文的完整请求过程,请加以理解并记忆 //本系列教 ...
- day04 一个简单的代码优化案例
import random punches = ['石头','剪刀','布'] computer_choice = random.choice(punches) user_choice = input ...
- mecacheq的配置
在处理业务逻辑时有可能遇到高并发问题,例如商城秒杀.微博评论等.如果不做任何措施可能在高瞬间造成服务器瘫痪,如何解决这个问题呢?队列是个不错的选择.队列(Queue)又称先进先出(First In F ...
- ECMAScript6 入门教程 初学记录let命令 块级作用域
一.基本语法-let命令 (1)ES6新增了let命令,用来声明变量.所声明的变量,只在let命令所在的代码块内有效. 循环的计数器,就很合适使用let命令.计数器i只在for循环体内有效,在循环体外 ...
- 玩转spring boot——war部署
前言 之前部署spring boot应用是通过直接输入命令“java -jar”来实现的.而有些情况,由于部署环境的制约,只能把项目从jar转换成war才能部署,如新浪云sae的java环境容器.那怎 ...
- Spring Boot 的 application.properties
更改默认端口:8080 server.port = 8081 更改context-path :/server.context-path = /springboot #server.address= # ...
- flask重要点
django与flask的区别 django: 大而全的框架,包含了很多组件,例如:ORM.form.ModelForm.session... flask: 轻量级的可扩展强的框架.有丰富的第三方组件 ...
- Linux系统命令 3
1.vmstat命令监控系统资源[root@localhost ~]#vmstat [刷新延时 刷新次数] 例如:[root@localhost proc]#vmstat 1 3 2.dmesg开机时 ...