zoukankan      html  css  js  c++  java
  • UVA10815 Andy's First Dictionary

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756

    这个题错了十几次 runtime 占了10次 错了一天  最后终于改对了 用一个小数组把单词存起来 然后把这个单词复制给一个二维数组,复制的时候查找一下前面是否有重复的 如果没有就复制给它,然后用快排对所有的进行排序。

    View Code
     1 #include <stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 int cmp(const void *a, const void *b)
     5 {
     6    return strcmp((char *)a, (char *)b);
     7 }
     8 int main()
     9 {
    10     int i, g = 0, s,q,in;
    11     char c,x[5005][21],w[21];
    12     s = 0;
    13     while((c = getchar())!=EOF)
    14     {
    15         if(c>='a'&&c<='z')
    16         {
    17             w[g++] = c;
    18         }
    19         else
    20         if(c>='A'&&c<='Z')
    21         {
    22             w[g++] = c+32;
    23         }
    24         else
    25         {
    26             if(g!=0)
    27             {
    28                 w[g] = '\0';
    29                 for (in = i = 0; i < s; ++i)
    30                 if (strcmp(x[i], w) == 0)
    31                 {
    32                     in = 1;
    33                     break;
    34                 }
    35                 if (!in)
    36                 {
    37 
    38                     strcpy(x[s], w);
    39                     s++;
    40                 }
    41                 g = 0;
    42             }
    43         }
    44     }
    45     qsort(x, s, sizeof(x[0]), cmp);
    46     for(i = 0 ; i < s ; i++)
    47     {
    48         puts(x[i]);
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    vector
    vector-back
    vector-back
    vector-begin
    vector-begin
    vector-at
    vector-at
    Vector-assign
    Vector-assign
    Vector-Constructors
  • 原文地址:https://www.cnblogs.com/shangyu/p/2533517.html
Copyright © 2011-2022 走看看