/*
题目: Lily上课时使用字母数字图片教小朋友们学习英语单词,每次都需要把这些图片按照大小(ASCII码值从小到大)排列收好。
请大家给Lily帮忙,通过C语言解决。
输入: Lily使用的图片包括"A"到"Z"、"a"到"z"、"0"到"9"。输入字母或数字个数不超过1024。
Lily的所有图片按照从小到大的顺序输出
样例: Ihave1nose2hands10fingers
输出: 0112Iaadeeefghhinnnorsssv
*/
#include<iostream>
#include<string>
#include<cstring>
const int Maxnum = 1024;
char * sequenASII(char* str,int N)
{
char* str2 = str;
char temp;
for(int i = 0;i<N-1;i++)//冒泡排序
for(int j = i+1;j<N;j++){
if(str[i]>str[j]) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
return str2;
}
int main()
{
char A[Maxnum];
std::cin.get(A,Maxnum);
int N = strlen(A);//区别sizeof和strlen
//N--;
//std::cout<< N;
char* str3 = sequenASII(A,N);
std::cout << str3;
}
华为机试训练:图片排序
最新推荐文章于 2025-03-04 11:25:23 发布