zoukankan      html  css  js  c++  java
  • poj3852

    简单题

    View Code
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    #define maxn 105
    #define inf 0x3f3f3f3f
    
    struct Elem
    {
        char *s;
        int len;
    }elem[maxn];
    
    int n;
    char st[maxn][maxn];
    
    bool cmp(const Elem &a, const Elem &b)
    {
        if (a.len == b.len)
            return strcmp(a.s, b.s) < 0;
        return a.len < b.len;
    }
    
    void scan(char *a)
    {
        scanf("%s", a);
    }
    
    void print(char *a)
    {
        printf("%s\n", a);
    }
    
    int mismatch(char *a, char *b, int len)
    {
        for (int i = 0; i < len; i++)
            if (a[i] != b[i])
                return i;
        return -1;
    }
    
    int main()
    {
        //freopen("t.txt", "r", stdin);
        while (scanf("%d", &n), n)
        {
            for_each(st, st + n, scan);
            //for_each(st, st + n, print);
            for (int i = 0; i < n; i++)
            {
                elem[i].s = st[i];
                elem[i].len = strlen(st[i]);
                reverse(elem[i].s, elem[i].s + elem[i].len);
            }
            sort(elem, elem + n, cmp);
            int ans = inf;
            for (int i = 0; i < n - 1; i++)
                if (elem[i].len == elem[i + 1].len)
                {
                    int temp = mismatch(elem[i].s, elem[i + 1].s, elem[i].len);
                    ans = min(ans, elem[i].len - temp - 1);
                }
            for (int i = 0; i < n; i++)
                ans = min(ans, elem[i].len - 1);
            printf("%d\n", ans);
        }
        return 0;
    }
  • 相关阅读:
    TF400916错误修复办法
    架构优化
    .net 动态代理的泛型方法支持问题
    解决Kafka-1194问题
    SOA服务总线设计
    SOA初探
    重构心法——提高代码复用率
    重构心法——拆分大对象
    重构心法——你应该这样写方法
    反爬虫那些事儿
  • 原文地址:https://www.cnblogs.com/rainydays/p/2736092.html
Copyright © 2011-2022 走看看