zoukankan      html  css  js  c++  java
  • Phone List

    http://poj.org/problem?id=3630

    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 struct node
     4 {
     5     int count ;
     6     int next[11] ;
     7 }tr[100010] ;
     8 int flag, num ;
     9 void node()
    10 {
    11     tr[num].count = 0 ;
    12     memset(tr[num].next,0,sizeof(tr[num].next)) ;
    13 }
    14 void creat(char *s)
    15 {
    16     int i ;
    17     int f = 0 , x = 0 ;
    18     int len = strlen(s) ;
    19     for(i=0; i<len; i++)
    20     {
    21         int t = s[i] - 48 ;
    22         if(!f&&tr[x].count==1)
    23         {
    24             flag = 0 ;
    25         }
    26         if(tr[x].next[t]==0)
    27         {
    28             num++ ;
    29             node();
    30             tr[x].next[t] = num ;
    31             f = 1 ;
    32         }
    33         x = tr[x].next[t] ;
    34     }
    35     if(!f)
    36     flag = 0 ;
    37     tr[num].count = 1 ;
    38 }
    39 int main()
    40 {
    41      int T, n;
    42      char c[11] ;
    43      scanf("%d", &T) ;
    44      while(T--)
    45      {
    46          scanf("%d", &n) ;
    47          getchar() ;
    48          memset(tr,0,sizeof(tr)) ;
    49          flag = 1 ;
    50          num = 0 ;
    51          while(n--)
    52          {
    53              gets(c) ;
    54              if(flag)
    55              creat(c) ;
    56          }
    57          if(flag)
    58          printf("YES\n") ;
    59          else printf("NO\n") ;
    60      }
    61      return 0 ;
    62 }

    静态写的,动态会超时

  • 相关阅读:
    个人所得税避税的10种方法
    营业税
    融资租赁
    会计等式
    公司公积金
    fixed语句
    自由之路
    $or操作符
    $in 操作符
    Redis 字典的实现
  • 原文地址:https://www.cnblogs.com/yelan/p/2921252.html
Copyright © 2011-2022 走看看