zoukankan      html  css  js  c++  java
  • test

    #include<cstdio>
    #include<cstring>
    using namespace std;
    char a[10000005];
    int tmp[30],pd,s,ans=100,n,cha;
    //tmp数组每次加到2就和前一个比对,然后回1,来回往复代替vector
    int main()
    {
        gets(a);
        n=strlen(a);
        for(int i=0;i<n;i++)
        {
            tmp[a[i]-'A']++;
            if(tmp[a[i]-'A']==2)
            {
                pd=1;
                for(int j=s;j<i;j++)
                {
                    if(a[i]==a[j])
                    {
                        cha=i-j;
                        if(cha<ans)//两个元素差的最小值
                        {
                            ans=cha;
                        }
                        s=j+1;//从下一个开始再次比对最小值
                        break;
                    }
                }
                tmp[a[i]-'A']=1;
            }
        }
        if(pd==0)
        {
            printf("-1 ");
            return 0;
        }
        printf("%d ",ans);
        return 0;
    }

  • 相关阅读:
    hdu 4474 大整数取模+bfs
    Codeforces Mafia
    hdu 4750 Count The Pairs(并查集)
    zoj 3659 Conquer a New Region(并查集)
    zoj 3656
    poj 3678 Katu Puzzle(Two Sat)
    UVa 11235 RMQ
    hdu 4768 Flyer (二分)
    hdu 4762 Cut the Cake概率公式
    Ural 1046 Geometrical Dreams(解方程+计算几何)
  • 原文地址:https://www.cnblogs.com/vercont/p/10920122.html
Copyright © 2011-2022 走看看