晴神书中AC代码

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. using namespace std;
  5. int n, minLen = 256, ans = 0;
  6. char s[100][260];
  7. int main() {
  8. #ifdef ONLINE_JUDGE
  9. #else
  10. freopen("1.txt", "r", stdin);
  11. #endif // ONLINE_JUDGE
  12. scanf("%d", &n); //n是字符串的个数
  13. getchar();
  14. for(int i = 0; i < n; i++) {
  15. cin.getline(s[i], 260);
  16. int len = strlen(s[i]);
  17. if(len < minLen) minLen = len; //取最小长度
  18. for(int j = 0; j < len / 2; j++) { //反转字符串s[i], 转化为求公共后缀
  19. char temp = s[i][j]; //交换str[i]与str[len - i - 1]
  20. s[i][j] = s[i][len - j - 1];
  21. s[i][len - j - 1] = temp;
  22. }
  23. }
  24. for(int i = 0; i < minLen; i++) { //判断所有字符串的第i个字符是否全部相等
  25. char c = s[0][i]; //取第一个字符串的第i个字符
  26. bool same = true;
  27. for(int j = 1; j < n; j++) { //判断其余字符串的第i个字符是否等于c
  28. if(c != s[j][i]) { //只要有一个不等,就停止枚举,说明公共后缀到处为止
  29. same = false;
  30. break;
  31. }
  32. }
  33. if(same) ans++; //若所有字符串的第i位相等,则计数器ans加1
  34. else break;
  35. }
  36. if(ans) {
  37. for(int i = ans - 1; i >= 0; i--) {
  38. printf("%c", s[0][i]);
  39. }
  40. } else {
  41. printf("nai"); //不存在公共后缀
  42. }
  43. return 0;
  44. }

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. tensorflow 框架图

  2. 对AM信号FFT的matlab仿真

    普通调幅波AM的频谱,大信号包络检波频谱分析 u(t)=Ucm(1+macos t)cos ct ma称为调幅系数 它的频谱由载波,上下边频组成 , 包络检波中二极管截去负半周再用电容低通滤波,可 ...

  3. AGC033D Complexity

    题意 给出一个\(n*m\)的\(0,1\)矩阵,若一个矩阵中的所有元素都相同,则这个矩阵的代价为\(0\),如果不是则选择一种将它分成两个子矩阵的方案,代价为所有方案中(两个子矩阵的代价的较大值+\ ...

  4. 牛券Cow Coupons

    USACO12FEB 久违的奶牛题. 题意: FJ准备买一些新奶牛,市场上有 $ N $ 头奶牛 $ (1 \leq N \leq 50000) $ ,第i头奶牛价格为 $ P_i (1 \leq P ...

  5. js 继承的一个例子

    <script type="text/javascript"> function Animal(){ this.species = "动物"; th ...

  6. web工程中添加自建userLibary与将jar包放到lib文件夹下的区别

    纯 java项目 使用的本地自己的JRE,那么classLoader在加载jar和class时候是分开的,对于我们自己编写的class,会在 APP_HOME/bin下.导入的jar包或者user l ...

  7. Nginx-HTTP之ngx_http_top_body_filter

    1. ngx_http_top_body_filter 该链表用于构造响应消息的响应正文. 大致有以下模块在该链表中插入了自己的函数: ngx_http_range_filter_module: ng ...

  8. Unity通过世界坐标系转换到界面坐标位置

    public static Vector2 WorldToCanvasPoint(Canvas canvas, Vector3 worldPos) { Vector2 pos; RectTransfo ...

  9. HearthBuddy CSharpCodeProvider 如何编译cs文件

    源码 源码1 namespace Hearthbuddy.Windows{    // Token: 0x02000041 RID: 65    public class MainWindow : W ...

  10. 删除ELK的索引

    终于找到一个工具,curator,可以搜索相关信息. 记录一下: 1,查询索引:   curator_cli --host 10.2.16.191 --port 9200 show_indices - ...