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;
    }
  • 相关阅读:
    第六章:单元测试框架unittest
    Jenkins 使用 war包安装时,如果出现报离线错误解决方法
    Appium自动化封装教案
    yaml文件读取(5.1之前与5.1之后对比)
    appium-desktop配置运用方法
    postwoman 配置
    jwt解析
    pytest
    centos安装python3.8
    linux 查找命令
  • 原文地址:https://www.cnblogs.com/0803yijia/p/2526904.html
Copyright © 2011-2022 走看看