晴神书中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. Mybatis源码学习之类型转换(四)

    简述 JDBC数据类型与Java语言中的数据类型并不是完全对应的,所以在PreparedStatement为SQL语句绑定参数时,需要从Java类型转换成JDBC类型,而从结果集中获取数据时,则需要从 ...

  2. python上下文小记

    python访问数据库是日常编程中经常使用的,一般的代码如下: 可以看出样例代码还是比较多的,有没有办法优化一下呢?有! def send_msgs(conn_id=None, **kwargs): ...

  3. 【Eureka】Eureka 是什么

    Eureka是什么? Eureka 是 Netflix 的一个子模块,也是核心模块之一.Eureka 是一个基于 Rest 的服务,用于定位服务,以实现云端中间层服务发现和故障转移.服务注册和发现对于 ...

  4. torch学习中的难点

    https://github.com/zergtant/pytorch-handbook/blob/master/chapter2/2.1.4-pytorch-basics-data-lorder.i ...

  5. 异常值检验实战1--风控贷款年龄变量(附python代码)

    python风控评分卡建模和风控常识(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005214003&am ...

  6. 【Makefile】Makefile中的常用函数简介

    1. subst函数 格式:$(subst <from>, <to>, <text>)功能:把字串<text>中的<from>字符串替换成& ...

  7. for(foo('a') ; foo('b') && (i<2);foo('c'))的执行结果

    static boolean foo(char c) { System.out.println(c); return true; } public static void main(String[] ...

  8. [spring boot]idea中实现热部署的方法

    发生了任何修改之后,必须关闭后再启动Application类才能够生效,显得略微麻烦. Springboot提供了热部署的方式,当发现任何类发生了改变,马上通过JVM类加载的方式,加载最新的类到虚拟机 ...

  9. 代码格式化工具 AStyle

    Astyle是一个用来对C/C++代码进行格式化的工具,在windows或者linux都有对应的版本,下面介绍几个本人比较常用的参数 --style=linux  个人比较喜欢linux风格,即函数的 ...

  10. UNITY3D 添加预制的方法

    预制文件(Prefabs)的做法 我这里需要的图片 在hierarchy 视图下新建一个2D object->sprite 然后设置这个sprite的背景为需要的图片 新建一个prefabs目录 ...