zoukankan      html  css  js  c++  java
  • UVA 10887 Concatenation of Languages

    UVA_10887

    要不是在一个网站上看到了输入字符串可能为空的这一提示,我估计我又要郁闷死了……

    #include<stdio.h>
    #include
    <string.h>
    int head[10000017],next[3000000];
    char st[3000000][25],b[25];
    int hash(char *str)
    {
    int seed=31,v=0;
    while(*str)
    {
    v
    =v*seed+*(str++);
    }
    return (v&0x7FFFFFFF)%10000017;
    }
    int insert(int s)
    {
    int i,h;
    h
    =hash(st[s]);
    for(i=head[h];i!=-1;i=next[i])
    if(strcmp(st[i],st[s])==0)
    break;
    if(i==-1)
    {
    next[s]
    =head[h];
    head[h]
    =s;
    return 1;
    }
    else
    return 0;
    }
    int main()
    {
    int i,j,k,M,N,ans,t,tt;
    gets(b);
    sscanf(b,
    "%d",&t);
    for(tt=0;tt<t;tt++)
    {
    gets(b);
    sscanf(b,
    "%d%d",&M,&N);
    ans
    =0;
    memset(head,
    -1,sizeof(head));
    for(i=0;i<M;i++)
    gets(st[i]);
    for(j=0;j<N;j++)
    {
    gets(st[i]);
    for(k=0;k<M;k++)
    {
    strcpy(st[i
    +k+1],st[k]);
    strcpy(st[i
    +k+1]+strlen(st[i+k+1]),st[i]);
    if(insert(i+k+1))
    ans
    ++;
    }
    i
    =i+M+1;
    }
    printf(
    "Case %d: %d\n",tt+1,ans);
    }
    return 0;
    }

      

  • 相关阅读:
    linux-vi/vim
    Linux性能监控-ss
    Linux性能监控-netstat
    Linux性能监控-sar
    Linux性能监控-htop
    Linux性能监控-pstree
    Linux性能监控-ps
    查看linux占用内存/CPU最多的进程
    Linux性能监控-top
    Linux-cpu-socket/core/processor
  • 原文地址:https://www.cnblogs.com/staginner/p/2180058.html
Copyright © 2011-2022 走看看