zoukankan      html  css  js  c++  java
  • HDU 1238 Substrings

     1 #include <iostream>
     2 #include <cstring>
     3 #include <string>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 const int INF = 1e6;
     8 
     9 vector<string> a;
    10 string suba;
    11 string rsuba;
    12 
    13 int main(void)
    14 {
    15     int cas;
    16     cin >> cas;
    17     while (cas--)
    18     {
    19         int n;
    20         cin >> n;
    21         for (int i = 0; i < n; ++i)
    22         {
    23             string temp;
    24             cin >> temp;
    25             for (int i = 0; i < temp.size(); ++i)
    26                 temp[i] = tolower(temp[i]);
    27             a.push_back(temp);
    28         }
    29 
    30         int p;
    31         int minSize = INF;
    32         for (int i = 0; i < n; ++i)
    33         {
    34             if (a[i].size() < minSize)
    35             {
    36                 minSize = a[i].size();
    37                 p = i;
    38             }
    39         }
    40 
    41         int result = 0;
    42         for (int i = 0; i < minSize; ++i)
    43         {
    44             for (int j = 1; i + j <= minSize; ++j)
    45             {
    46                 suba = a[p].substr(i, j);
    47                 rsuba = suba;
    48                 reverse(rsuba.begin(), rsuba.end());
    49                 int k;
    50                 for (k = 0; k < n; ++k)
    51                 {
    52                     if (k != p)
    53                     {
    54                         if (a[k].find(suba) == -1 && a[k].find(rsuba, 0) == -1)
    55                             break;
    56                     }
    57                 }
    58                 if (k == n)// match the case
    59                 {
    60                     if (j > result)
    61                         result = j;
    62                 }
    63             }
    64         }
    65         cout << result << endl;
    66         a.clear();
    67     }
    68 
    69     return 0;
    70 }
  • 相关阅读:
    面向对象编程思想(一)
    IT第十九天
    IT第十八天
    关于面试,来自无锡一位尊者的建议
    IT第十一天、第十二天、第十三天
    数据结构 3动态规划
    java 零碎1
    数据结构 2.迭代与递归
    数据结构 1.算法分析
    java 字符串(正则表达式)未完
  • 原文地址:https://www.cnblogs.com/ducklu/p/9010502.html
Copyright © 2011-2022 走看看