• POJ3080Blue Jeans(暴力)


    开始做字符串专题,地址

    第一题水题,暴力就可以做

     1 #include <map>
     2 #include <set>
     3 #include <stack>
     4 #include <queue>
     5 #include <cmath>
     6 #include <ctime>
     7 #include <vector>
     8 #include <cstdio>
     9 #include <cctype>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <iostream>
    13 #include <algorithm>
    14 using namespace std;
    15 #define INF 0x3f3f3f3f
    16 #define inf (-((LL)1<<40))
    17 #define lson k<<1, L, mid
    18 #define rson k<<1|1, mid+1, R
    19 #define mem0(a) memset(a,0,sizeof(a))
    20 #define mem1(a) memset(a,-1,sizeof(a))
    21 #define mem(a, b) memset(a, b, sizeof(a))
    22 #define FOPENIN(IN) freopen(IN, "r", stdin)
    23 #define FOPENOUT(OUT) freopen(OUT, "w", stdout)
    24 
    25 template<class T> T CMP_MIN(T a, T b) { return a < b; }
    26 template<class T> T CMP_MAX(T a, T b) { return a > b; }
    27 template<class T> T MAX(T a, T b) { return a > b ? a : b; }
    28 template<class T> T MIN(T a, T b) { return a < b ? a : b; }
    29 template<class T> T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
    30 template<class T> T LCM(T a, T b) { return a / GCD(a,b) * b;    }
    31 
    32 //typedef __int64 LL;
    33 typedef long long LL;
    34 const int MAXN = 1000;
    35 const int MAXM = 100005;
    36 const double eps = 1e-12;
    37 
    38 char str[20][100], ansStr[100];
    39 int T, N;
    40 
    41 int maxLen(char* s1, char* s2)
    42 {
    43     int ans = 0;
    44     for(int i=0;s2[i];i++)
    45     {
    46         int len = 0;
    47         for(int j=0;s1[j];j++)
    48         {
    49             if(s2[i+j] == s1[j]) len++;
    50             else break;
    51         }
    52         ans = max(ans, len);
    53     }
    54     return ans;
    55 }
    56 
    57 int main()
    58 {
    59     while(~scanf("%d", &T))while(T--)
    60     {
    61         mem0(str); mem0(ansStr);
    62         scanf("%d%*c", &N);
    63         for(int i=0;i<N;i++) scanf("%s", str[i]);
    64         int ans = 0;
    65         for(int i=0;str[0][i];i++)
    66         {
    67             int len = INF;
    68             for(int j=1;j<N;j++)
    69             {
    70                 len = min( len, maxLen(&str[0][i], str[j]) );
    71             }
    72             if(ans < len)
    73             {
    74                 ans = len;
    75                 for(int j=i;j<i+ans;j++) ansStr[j-i] = str[0][j];
    76                 ansStr[i+ans] = 0;
    77             }
    78             else if(ans == len)
    79             {
    80                 int ok = 0;
    81                 for(int j=0;j<ans;j++)
    82                 {
    83                     if(ok) ansStr[j] = str[0][i+j];
    84                     else if(ansStr[j] != str[0][i+j])
    85                     {
    86                         if(ansStr[j] < str[0][i+j]) break;
    87                         else { ansStr[j] = str[0][i+j]; ok = 1; }
    88                     }
    89                 }
    90             }
    91         }
    92         if(ans >= 3)
    93             printf("%s
    ", ansStr  );
    94         else printf("no significant commonalities
    ");
    95     }
    96     return 0;
    97 }
  • 相关阅读:
    Java实现对zip和rar文件的解压缩
    executssql 函数的每一句代码的意思
    ConnectString ()函数的介绍
    ADODB——RecordSet对象
    Mrc.EOF
    论数据库
    uniGUI之新窗口uniForm(19)
    uniGUI之学习方法(18)
    uniGUI之换肤(17)
    uniGUI之多页面框架(16)
  • 原文地址:https://www.cnblogs.com/gj-Acit/p/3622887.html
Copyright © 2020-2023  润新知