晴神书中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. 【BZOJ3098】 Hash Killer II

    BZOJ3098 Hash Killer II Solution 这道题目好像题面里面给了提示(当然没给就有点难想了.) 曾经讲过一个叫做生日悖论的,不知道还有多少人记得 考虑相同的可能性大概是\(\ ...

  2. Could not initialize class sun.awt.X11GraphicsEnvironment异常处理

    原因导致: 经过Google发现很多人也出现同样的问题.从了解了X11GraphicEnvironment这个类的功能入手, 一个Java服务器来处理图片的API基本上是需要运行一个X-server以 ...

  3. C#调用新浪微博API

    WebRequest wq = WebRequest.Create(this.address); HttpWebRequest hq = wq as HttpWebRequest; string us ...

  4. centos 如何查看命令是由哪个包提供的

    yum whatprovides */ifconfig Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile ...

  5. Graphics 使用一点点注意

    Form_Load 事件下绘制的结果会被 paint 刷新掉.也就等于没有绘制一样. Graphics g = this.CreateGraphics(); g.DrawRectangle(new P ...

  6. LC 934. Shortest Bridge

    In a given 2D binary array A, there are two islands.  (An island is a 4-directionally connected grou ...

  7. 关闭tslint

    只需要在tslint.config里配置一行 "defaultSeverity": "none",

  8. Hibernate3疑惑解决

    1.session的get()和load()有什么区别?     # get()如果没有找到持久化类返回null,有可能导致空指针异常.     # load()如果没有找到持久化类直接抛出异常.   ...

  9. 使用Selenium时解决方案: Exception: Failed to find firefox binary. You can set it by specifying the ······

    问题描述: Firefox在自动升级之后,在使用selenium的时候出现了如下错误: Exception: Failed to find firefox binary. You can set it ...

  10. java ldap用户密码md5加密

    在这里不过多介绍ldap,因为这样的文章特别多,这里就简单直接的记录这一个问题. 在springboot中通过引入spring-boot-starter-data-ldap,使用LdapTemplat ...