晴神书中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)的更多相关文章

  1. 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise

    题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...

  2. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  3. PAT 1077 Kuchiguse

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  4. pat 1077 Kuchiguse(20 分) (字典树)

    1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

  5. PAT Advanced 1077 Kuchiguse (20 分)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  6. PAT甲级——A1077 Kuchiguse

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  7. PAT甲级——1077.Kuchiguse(20分)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  8. PAT (Advanced Level) 1077. Kuchiguse (20)

    最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...

  9. PAT甲题题解-1077. Kuchiguse (20)-找相同后缀

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

随机推荐

  1. Python数据抓取(1) —数据处理前的准备

    (一)数据抓取概要 为什么要学会抓取网络数据? 对公司或对自己有价值的数据,80%都不在本地的数据库,它们都散落在广大的网络数据,这些数据通常都伴随着网页的形式呈现,这样的数据我们称为非结构化数据 如 ...

  2. CDQ分治的嵌套

    CDQ的嵌套 上一篇博客介绍了一下CDQ的入门思想.这里再介绍一下它的进阶,CDQ套CDQ.其实如果对入门思想掌握的透彻,嵌套也是很容易掌握的,思想是一样的. 什么是嵌套 简单地说,有的问题,如果用一 ...

  3. [51nod1789] 跑得比谁都快

    题面 题解 设\(f[i]\)为根节点到\(i\)的最小耗时 设\(S\)为\(i\)的祖先集合, 可以得到 \[ f[i] = min(f[j] + (i - j)^p),j \in S \] 对于 ...

  4. redis redis-cli

    默认无权限控制: 远程服务连接: $ redis-cli -h 127.0.0.1 -p 6379 windows下 :redis-cli.exe -h 127.0.0.1 -p 6379 redis ...

  5. java面试题,转载自http://www.cnblogs.com/nnngu/p/8471043.html#3914167

    Java面试题库及答案解析   1.面向对象编程(OOP)有哪些优点? 代码开发模块化,更易维护和修改. 代码复用. 增强代码的可靠性和灵活性. 增加代码的可理解性. 2.面向对象编程有哪些特性? 封 ...

  6. Final阶段贡献分配规则

    此次作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/10063 贡献分分配规则: 组内一共五名同学,贡献分共计50分. 1.每 ...

  7. yield and send的使用详细解释

    https://blog.csdn.net/mieleizhi0522/article/details/82142856 虽然并不完全正确,但是能在使用中帮我们拨开迷雾 再结合另外一篇文章理解了htt ...

  8. ELMO及前期工作 and Transformer及相关论文

    论文1 https://arxiv.org/pdf/1705.00108.pdf Semi-supervised sequence tagging with bidirectional languag ...

  9. redis---set类型常用命令

    添加元素:sadd key value1 value2 查看指定key包含的元素:smembers key 判断指定元素是否存在于key的value中(0表示不存在,1表示存在):sismember ...

  10. Vue项目打包后背景图片路径错误

    vue项目打包之后背景图片出错的解决方案如下: 1,找到 config->index.js里面,如下修改 默认配置: env: require('./prod.env'), index: pat ...