zoukankan      html  css  js  c++  java
  • 每日一题:华为初级题库——图片整理

      <题目要求>

        丽丽要教小朋友识字母和数字,她需要先对图片从小到大排列(按照ASCII码排列),请你帮帮她。要求输入不超过1024个字符(只能取大写字母、小写字母和数字),输出排好序的字符串。

      思路:对字符进行排序即可。此处采用简单插入排序。

    #include <iostream>
    
    using namespace std;
    void InsertSort(char *a,int len)
    {
        int min;
        char tmp;
        for(int i=0;i<len;i++)
        {
            min=i;
            for(int j=i+1;j<len;j++)
            {
                if(a[j]<a[min])
                    min=j;
            }
            if(i!=min)
            {
                tmp=a[i];
                a[i]=a[min];
                a[min]=tmp;
            }
        }
    }
    int main()
    {
        char a[1024];
        int i=0;
        cin>>a;
        while(a[i]!='')
            i++;
        InsertSort(a,i);
        for(int j=0;j<i;j++)
        cout<<a[j];
        return 0;
    }
  • 相关阅读:
    寒假学习进度7
    寒假学习进度3
    寒假学习进度6
    寒假学习进度5
    寒假学习进度8
    加分项
    每日博客
    每日博客
    每日博客
    每日博客
  • 原文地址:https://www.cnblogs.com/Sophie-nature/p/3676031.html
Copyright © 2011-2022 走看看