zoukankan      html  css  js  c++  java
  • 题目1066:字符串排序-----------单个字符可以比较大小,用了冒泡排序;另一种用了qsort()

    AC:

    #include<stdio.h>
    #include<stdlib.h>
    #include <cstring>
    
    int main()
    {
        char *str=(char *)malloc (sizeof(char));
        while(scanf("%s",str)!=EOF)
        {
            int i,j,k;
            int len=strlen(str);
            char s;
            for (i=0;i<len;i++)
             for(j=i;j<len;j++)
              if (str[i]>str[j])
              {
                  s=str[i];
                  str[i]=str[j];
                  str[j]=s;
              } 
            printf("%s
    ",str);
        }
        return 0;
    } 

    AC:

    #include<stdio.h>
    #include<stdlib.h>
    #include<cstring>
    int cmp(void const *a,void const *b);
    int main()
    {
        char *str=(char *)malloc (sizeof (char)); 
        while(scanf("%s",str)!=EOF)
        {
            int len=strlen(str);
            qsort(str,len,sizeof(char),cmp);
            printf("%s
    ",str);
        }
        return 0; 
    }
    
    int cmp(void const *a,void const *b)
    {
        return *(char *)a-*(char*)b;
    }
  • 相关阅读:
    网络协议 22
    网络协议 21
    网络协议 20
    网络协议 19
    网络协议 18
    网络协议 17
    网络协议 16
    网络协议 15
    网络协议 14
    .net 4.0 中的特性总结(五):并行编程
  • 原文地址:https://www.cnblogs.com/jianrenguo/p/6543189.html
Copyright © 2011-2022 走看看