PAT A1077 Kuchiguse (20)
晴神书中AC代码
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, minLen = 256, ans = 0;
char s[100][260];
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
scanf("%d", &n); //n是字符串的个数
getchar();
for(int i = 0; i < n; i++) {
cin.getline(s[i], 260);
int len = strlen(s[i]);
if(len < minLen) minLen = len; //取最小长度
for(int j = 0; j < len / 2; j++) { //反转字符串s[i], 转化为求公共后缀
char temp = s[i][j]; //交换str[i]与str[len - i - 1]
s[i][j] = s[i][len - j - 1];
s[i][len - j - 1] = temp;
}
}
for(int i = 0; i < minLen; i++) { //判断所有字符串的第i个字符是否全部相等
char c = s[0][i]; //取第一个字符串的第i个字符
bool same = true;
for(int j = 1; j < n; j++) { //判断其余字符串的第i个字符是否等于c
if(c != s[j][i]) { //只要有一个不等,就停止枚举,说明公共后缀到处为止
same = false;
break;
}
}
if(same) ans++; //若所有字符串的第i位相等,则计数器ans加1
else break;
}
if(ans) {
for(int i = ans - 1; i >= 0; i--) {
printf("%c", s[0][i]);
}
} else {
printf("nai"); //不存在公共后缀
}
return 0;
}
PAT A1077 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 1077 Kuchiguse
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- pat 1077 Kuchiguse(20 分) (字典树)
1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- PAT Advanced 1077 Kuchiguse (20 分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT甲级——A1077 Kuchiguse
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 ...
随机推荐
- ImageSharp跨平台图片处理
添加nuget引用 SixLabors.ImageSharp 和SixLabors.ImageSharp.Drawing 暂时只实现了缩略图..<pre>using SixLabors.I ...
- html页面之间相互传值
常见的在页面登录过后会获得一个token值然后页面跳转时传给下一个页面 sessionStorage.setItem("token",result.token);//传输token ...
- easyExcel简介#
摘自:https://www.cnblogs.com/54chensongxia/p/11990312.html easyExcel简介# Java领域解析.生成Excel比较有名的框架有Apache ...
- Go http包执行流程
Go 语言实现的 Web 服务工作方式与其他形式下的 Web 工作方式并没有什么不同,具体流程如下: -- http包执行流程 Request:来自用户的请求信息,包括 post.get.Cookie ...
- Ajax传递复杂对象报415
特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...
- DataSet转换为实体类
/// <summary> /// DataSet转换为实体类 /// </summary> /// <typeparam name="T">实 ...
- LC 820. Short Encoding of Words
Given a list of words, we may encode it by writing a reference string S and a list of indexes A. For ...
- Oracle Database的基本概念
一个 Oracle 服务器:是一个关系数据库管理系统(RDBMS),它提供全面的, 近乎完整的信息管理由Oracle 实例和Oracle 数据库组成Oracle 数据库 和 Oracle 实例Orac ...
- hibernate关联总结
在一对多与多对一的关联关系中,保存数据最好的通过多的一方来维护关系,这样可以减少update语句的生成,从而提高hibernate的执行效率! 配置一对多与多对一,这种叫“双向关联” 只配置一对多, ...
- SoundPool 播放短声音
SoundPool 最大只能申请1M的内存空间,只能用一些很短的声音片段,而不是用它来播放歌曲或者做游戏背景音乐. 使用 SoundPool 播放短声音实现步骤如下: // 创建SoundPool实例 ...