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

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=1756
     这次主要学会了一个字符串的快速排序函数;
    int cmp_string(const void* _a,const void* _b)
    {
        char* a= (char*)_a;
        char* b= (char*)_b;
        return strcmp(a,b);
    }
    qsort(word,max,sizeof(word[0]),cmp_string);//word是我的字符串数组。
    还有一个取单词的写法很重要;
    for(j = j,m = k = 0;k <= len;k++)//是<=len而不是<len;
            {
                if(isalpha(s[k]))
                {
                    word[j][m++] = s[k];
                }
                else
                {
                    if(isalpha(word[j][0]))
                    {
                        word[j][m] = '\0';
                        m = 0;
                        j++;
                    }
                }

            }
    View Code
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    char word[100010][250];
    int cmp_string(const void* _a,const void* _b)
    {
        char* a= (char*)_a;
        char* b= (char*)_b;
        return strcmp(a,b);
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        char s[255];
        int i,j,count,k,m;
        j = 0;
        while(gets(s) != NULL)
        {
            for(i = 0;s[i] != '\0';i++)
            if(s[i] >= 'A' && s[i] <= 'Z')
            s[i] += 32;
            int len = strlen(s);
            for(j = j,m = k = 0;k <= len;k++)
            {
                if(isalpha(s[k]))
                {
                    word[j][m++] = s[k];
                }
                else
                {
                    if(isalpha(word[j][0]))
                    {
                        word[j][m] = '\0';
                        m = 0;
                        j++;
                    }
                }
    
            }
    
    
        }
        int max;
            max = j;
    
    
            qsort(word,max,sizeof(word[0]),cmp_string);
            for(i=0;i<max;i++)
            if(strcmp(word[i],word[i+1]))
            puts(word[i]);
    
                    return 0;
    }
  • 相关阅读:
    BZOJ1146:[CTSC2008]网络管理
    AtCoder Grand Contest 004 C:AND Grid
    BZOJ3295:[CQOI2011]动态逆序对
    AtCoder Regular Contest 070F:Honest Or Unkind
    BZOJ3110:[ZJOI2013]K大数查询
    BZOJ3196:二逼平衡树
    浅谈splay
    BZOJ3938:Robot
    浅谈标记永久化
    AtCoder Regular Contest 068E:Snuke Line
  • 原文地址:https://www.cnblogs.com/0803yijia/p/2526904.html
Copyright © 2011-2022 走看看