晴神书中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. Linux之GDB命令(二)

    gdb命令: 前提条件:可执行文件必须包含调试信息 gcc -g gdb 文件名 –启动gdb调试 查看代码命令   当前文件:     list 行号(函数名)   指定文件:     list 文 ...

  2. vue 监听键盘回车事件 @keyup.enter || @keyup.enter.native

    vue运行为v-on在监听键盘事件时,添加了特殊的键盘修饰符:\ <input v-on:keyup.13="submit"> vue还非常贴心地给出了常用按键的别名, ...

  3. 最新版Google Chrome 自动加载flash插件的方法

    我们在用Selenium做自动化测试时,有时候需要浏览器自动加载flash插件,69以前的谷歌浏览器,可以通过加载属性的方法自动运行flash插件,如下: prefs={ "profile. ...

  4. docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"ping\": executable file not found in $PATH": unknown.

    docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting cont ...

  5. PySpider的安装

    使用 Pip 安装,命令如下 pip install pyspider 命令执行完毕即可安装成功. 常见错误: Windows 下可能会出现这样的错误提示:Command "python s ...

  6. redis 数据类型详解 以及 redis适用场景场合(滴滴)

    滴滴的面试官问了个问题关于redis的: 我现在想服务器每分钟接收一个用户的请求小于60个,如何处理: 答:使用Redis 缓存服务器,可以设置key=用户ID value不停地加一到了60就停止,然 ...

  7. Qt多线程应用--QRunnable

    http://blog.csdn.net/lefttime/article/details/5717349 作为Qt类中少有的基类, QRunnable提供了简洁有效的可运行对象的创建.  用QRun ...

  8. MySQL有四种BLOB类型

    先说明一下Blob的类型,直接从网上摘抄了!!!1.MySQL有四种BLOB类型: ·tinyblob:仅255个字符 ·blob:最大限制到65K字节 ·mediumblob:限制到16M字节 ·l ...

  9. python安装gmpy2模块时出现错误的解决

    接下来表演的是安装Python模块gmpy2 此模块用来进行高精度计算的模块,个人根据需求常用来进行rsa加密算法的计算 作为一个资质浅淡的ubuntu玩家,这些知识当然是在网上搜索得到的,不过网上的 ...

  10. NaN情况下无法比较大小

    <pre name="code" class="java">package nan; /** * NaN情况下无法比较大小 * @author ro ...