PTA (Advanced Level)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≤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
思路
- 读进来的时候反转字符串,然后找最长公共前缀就好了
代码
#include<bits/stdc++.h>
using namespace std;
vector<string> v;
int main()
{
int n;
scanf("%d\n", &n); //注意要把换行符也读进来
int shortest = 500;
string s;
for(int i=0;i<n;i++)
{
getline(cin, s);
if(s.size() < shortest) shortest = s.size();
reverse(s.begin(), s.end());
v.push_back(s);
}
bool right;
int index = 0;
for(int i=0;i<shortest;i++)
{
char ch = v[0][i];
right = true;
for(int j=1;j<n;j++)
{
if(v[j][i] != ch)
{
right = false;
break;
}
}
if(right) index++;
else break;
}
if(index == 0)
cout << "nai";
else
for(int i=index-1;i>=0;i--)
cout << v[0][i];
return 0;
}
引用
https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096
PTA (Advanced Level)1077.Kuchiguse的更多相关文章
- PAT (Advanced Level) 1077. Kuchiguse (20)
最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...
- PTA(Advanced Level)1036.Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- PTA (Advanced Level) 1004 Counting Leaves
Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...
- PTA (Advanced Level) 1020 Tree Traversals
Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...
- PTA(Advanced Level)1025.PAT Ranking
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PTA (Advanced Level) 1009 Product of Polynomials
1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...
- PTA (Advanced Level) 1008 Elevator
Elevator The highest building in our city has only one elevator. A request list is made up with Npos ...
- PTA (Advanced Level) 1007 Maximum Subsequence Sum
Maximum Subsequence Sum Given a sequence of K integers { N1, N2, ..., NK }. A continuous su ...
- PTA (Advanced Level) 1006 Sign In and Sign Out
Sign In and Sign Out At the beginning of every day, the first person who signs in the computer room ...
随机推荐
- 路由器配置——OSPF协议(2)
一.实验目的:使用OSPF协议达到全网互通的效果 二.拓扑图 三.具体步骤配置 (1)R1路由器配置 Router>enableRouter#configure terminalEnter co ...
- 【线性代数】3-6:四个子空间的维度(Dimensions of the Four Subspaces)
title: [线性代数]3-6:四个子空间的维度(Dimensions of the Four Subspaces) categories: Mathematic Linear Algebra ke ...
- Unicode 和utf-8的转换以及深拷贝和浅拷贝的区别
必须掌握的点 一. (内存)Unicode二进制字符>>>>>>编码(encode)>>>>>>(硬盘)utf-8二进制字符 ( ...
- 【java设计模式】-04单例模式
单例模式 定义: 确保一个类只有一个实例,而且自行实例化并向整个系统提供这个实例. 类型: 创建类模式 类图: 单例模式特点 1.单例类只能有一个实例. 2.单例类必须自己创建自己的唯一实例. 3.单 ...
- redis redis-cli
默认无权限控制: 远程服务连接: $ redis-cli -h 127.0.0.1 -p 6379 windows下 :redis-cli.exe -h 127.0.0.1 -p 6379 redis ...
- godaddy SSL证书不信任
在使用网上教程的部署godaddy证书,会出现证书不受信任的情况. 各别审核比较严格的浏览器会阻止或者要求添加例外.情况如下: 利用在线证书测试工具会提示根证书的内容为空.从而导致证书不受信任. 解决 ...
- fastadmin 全手动添加规则
全手动的话 你需要在规则管理里面添加规则 然后角色组就可以设置权限了如果是自动的话 应该就都生成了权限设置 1.增删改查的规则也要添加哦 2.角色组勾选相应的规则 https://ask.fastad ...
- 数据可视化界面UI设计大屏展示
- shapefile 输出的地理处理注意事项
多年来,ESRI 为存储地理信息开发了三种主要数据格式 - coverage 格式.shapefile 格式及地理数据库格式.其中,所开发的 Shapefile 为存储地理及属性信息提供了一种简单的非 ...
- PHPStorm2017去掉函数参数提示
今天升级到 PHPStorm 2017.1 发现增加了好些新功能, 有个默认开启的参数名和类型提示功能, 虽然功能挺强大的, 不过我用不着, 还是关掉的好, 有同样需求的同学可以看看 例子比较特殊这么 ...