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

    刚开始错了六七次,不过后来调用了库函数,进行字符串排序,就AC了,看来还是要掌握一些库函数,才能更迅速的写出完美的代码啊

    下面是代码,聪明人一看就会懂得啦,对了,本体一个关键是,注意要把存储单词的数组开的大一些,我刚开始没注意到,导致RE了两次

    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<ctype.h>
     4 #include<stdlib.h>
     5 char word[100010][210] = {'\0'};
     6 int Comp(const void *p1,const void *p2)
     7 {
     8     return strcmp((char *)p2,(char *)p1);
     9 }
    10 int main()
    11 {
    12     int i, k = 0, top = 0;;
    13     char ch;
    14     while((ch = getchar()) != EOF)
    15     {
    16         if(isalpha(ch))
    17             word[top][k++] = tolower(ch);
    18         else
    19         {
    20             if(isalpha(word[top][0]))
    21             {
    22                 word[top++][k] = '\0';
    23                 k = 0;
    24             }
    25         }
    26     }
    27     qsort(word,top,sizeof(word[0]),Comp);
    28     for(i = top-1;i > -1; i--)
    29     {
    30         if(strcmp(word[i],word[i-1]) != 0)
    31         puts(word[i]);
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    元组tuple
    列表list
    day11---闭包函数
    day10函数对象,嵌套,名称空间,作用域
    day10函数对象,嵌套,名称空间,作用域
    day--函数
    day8--文件管理2
    day ---7,文件管理
    day7,文件编码
    day6---字典,集合内置方法
  • 原文地址:https://www.cnblogs.com/SDUTYST/p/2526662.html
Copyright © 2011-2022 走看看