【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)
题意:
输入一个正整数N(<=100),接着输入N行字符串。输出N行字符串的最长公共后缀,否则输出nai。
AAAAAccepted code:
#include<bits/stdc++.h>
using namespace std;
string s[];
int length[];
char ans[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
cin.ignore();
int mn=;
for(int i=;i<=n;++i){
getline(cin,s[i]);
length[i]=s[i].size();
mn=min(mn,length[i]);
}
int cnt=;
for(int x=;x<=mn;++x){
int flag=;
for(int i=;i<=n;++i)
if(s[i][length[i]-x]!=s[i-][length[i-]-x]){
flag=;
break;
}
if(flag)
break;
ans[++cnt]=s[][length[]-x];
}
if(!cnt)
cout<<"nai";
else
for(int i=cnt;i;--i)
cout<<ans[i];
return ;
}
【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)的更多相关文章
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT甲级——1077.Kuchiguse(20分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT Advanced 1077 Kuchiguse (20 分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)
1061 Dating (20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...
- PAT甲级——1035 Password (20分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- PAT 甲级 1077 Kuchiguse
https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...
- PAT甲级——1061 Dating (20分)
Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkg ...
- PAT甲级——1005.SpellItRight(20分)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...
随机推荐
- goland 2019.1.1破解
https://blog.csdn.net/hi_liuxiansheng/article/details/89078405
- Linux(Mac)常用命令
df -B[G,M,K]查看磁盘剩余空间 free -mh查看内存 netstat -ntlp查看当前监听的网络端口 mount -t auto /dev/cdrom /media/cdrom挂载cd ...
- HTML5学习(2)语义化
什么是语义化? 1.每一个HTML元素都有具体的含义,例: a元素:超链接,p元素:段落 2.所有的元素与展示效果无关 元素内容展示到页面中的效果,应该由CSS决定. 因为浏览器带有默认的CSS样式, ...
- (转)Java中的String与常量池
Java中的String与常量池 转自:http://developer.51cto.com/art/201106/266454.htm string是java中的字符串.String类是不可变的,对 ...
- Wx-公众号-关闭内置浏览器页面,返回公众号橱窗
方法一: pushHistory(); function pushHistory() { var state = { title: "title", url: "#&qu ...
- Flask 教程 第二十章:加点JavaScript魔法
本文翻译自The Flask Mega-Tutorial Part XX: Some JavaScript Magic 这是Flask Mega-Tutorial系列的第二十部分,我将添加一个功能,当 ...
- 2.1 【配置环境】 JDK + eclipse + selenium
1.jdk以及eclipse的具体安装详见 http://www.cnblogs.com/ericazy/p/6082194.html 安装1.7 jdk即可 2.selenium 旧版本安装: s ...
- glog与gflags的windows编译
参考博客:https://kezunlin.me/post/bb64e398/
- UVA 10881 Piotr's Ants(模拟)
题目链接:https://vjudge.net/problem/UVA-10881 其实这道题的关键只有一句话: 当两个蚂蚁因碰撞而掉头的时候,我们完全可以认为是两个点对穿而过. 这时候我们的主要任务 ...
- tomcat服务器启动执行的两个方法
第一 SetApplicationContext(需要继承ApplicationContextAware)重写 第二 ContextInitialize(需要继承servleContet)重写,(co ...