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
/*从末尾开始检测,一直检测到不一样的地方,提取出那个字符串*/
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
int n,num;
cin>>n;
cin.get();
vector<string> vi;
string s;
string a="";
num=n;
while(num--)
{
getline(cin,s);
vi.push_back(s);
}
for(int i=vi[0].size()-1,j=vi[1].size()-1;i>=0&&j>=0;i--,j--)//因为初始,最小也有2
{
if(vi[0][i]!=vi[1][j])//如果末尾2个不相等
{
break;
}
else
{
a+=vi[0][i];
}
}//这样就得到了末尾最长的可能性的语气词
reverse(a.begin(),a.end());//这里要注意得到的字符串是倒叙的,需要用到algorithm里面的反转字符串的函数
if(n==2&&a.size()==0)
{
cout<<"nai"<<endl;
return 0;
}
if(n==2&&a.size()>0)
{
cout<<a<<endl;
return 0;
}
//接下去就是大于2的情况了,全在a上面做文章
string cun=a;
for(int t=2;t<vi.size();t++)//剩下那么多的string,进行比较
{
a="";
for(int i=cun.size()-1,j=vi[t].size()-1;i>=0&&j>=0;i--,j--)//这里出错了,调试的发现问题,在于第二个判断条件,应该是都成立的情况下
{
if(cun[i]!=vi[t][j])
{
break;
}
else
{
a+=cun[i];
}
}
reverse(a.begin(),a.end());
cun=a;
}//最后得到的cun,就是最后要的语气词
if(cun.size()==0)
{
cout<<"nai"<<endl;
return 0;
}
else
{
cout<<cun<<endl;
}
return 0;
}
转眼之间,我转行已经7个月了,自学了4个月,试用了3个月,总算顺利的转正成功了。算是正式迈向了程序员的道路上。如果恰好你也是转行看到我这段话,我希望你不要担心,低下头往前走,就行了。心里的焦虑,不安,都会随着时间,流去。努力下,时间会给你想要的答案。
转行而已,不简单,也不难。因为是在国企,下班有足够的学习时间,这段时间刷完了pat,再去刷TCP/IP,数据结构和算法。再补一补C++的模板类范例编程之类的吧。感觉工作中,这种用的都不是太多。
1077. Kuchiguse (20)的更多相关文章
- 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 ...
- PAT Advanced 1077 Kuchiguse (20 分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT甲级——1077.Kuchiguse(20分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT (Advanced Level) 1077. Kuchiguse (20)
最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...
- PAT甲题题解-1077. Kuchiguse (20)-找相同后缀
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)
题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...
- PAT 1077 Kuchiguse
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 ...
随机推荐
- 在Ubuntu 中使用Source Code Pro字体
1.下载字体 推荐GitHub上面的项目主页上下载 Source Code Pro 2.解压 unzip SourceCodePro_FontsOnly-1.013.zip 3. 打开SourceCo ...
- Caused by: java.lang.ClassNotFoundException: com.mchange.v2.ser.Indirector
1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...
- AHCI模式安装XP以及驱动下载
一.准备AHCI驱动 1.关于AHCI基础知识,请参考<AHCI模式的驱动下载.安装及蓝屏问题综合>一文. 2.安装AHCI驱动之前,请先确认桌面上.系统盘没有重要的东西需要备份,因为如果 ...
- 基于jQuery的一个提示功能的实现
最近有点忙,没有时间更新自己的博客,只能说我在原地踏步了,不知道你们进步了没有? 今天给大家分享一个提示的实现,有点简单,适合小白同学学习.下面是效果图 提示的功能: 当鼠标进入“我的菜单”的子菜单时 ...
- 芝麻HTTP:PhantomJS的安装
PhantomJS是一个无界面的.可脚本编程的WebKit浏览器引擎,它原生支持多种Web标准:DOM操作.CSS选择器.JSON.Canvas以及SVG. Selenium支持PhantomJS,这 ...
- python version 2. required,which was not found in the registry 解决方案
不能在注册表中识别python2.7 新建一个register.py 文件 import sys from _winreg import * # tweak as necessary version ...
- Scrapyd日志输出优化
现在维护着一个新浪微博爬虫,爬取量已经5亿+,使用了Scrapyd部署分布式. Scrapyd运行时会输出日志到本地,导致日志文件会越来越大,这个其实就是Scrapy控制台的输出.但是这个日志其实有用 ...
- Windows DLL资料整理
1.使用Visual C++ 6.0创建dll 2. 函数的调用规则(__cdecl,__stdcall,__fastcall,__pascal) 要点: 1. 如果你的程序中没有涉及可变参数,最好使 ...
- RobotFramework下的http接口自动化Create Http Context关键字的使用
要想使用HttpLibrary,Create Http Context 关键字的作用相当于是创建了一个http 调用的环境,是必不可少的一个关键字. Create Http Context 关键字需要 ...
- View的平移、缩放、旋转以及位置、坐标系
原创 2015年05月12日 13:15:29 标签: Android / Scroll / Scale / Translation / Rotation 24733 Android开发中,经常会接触 ...