题解 | #字符串内排序#
字符串内排序
https://www.nowcoder.com/practice/cc2291ab56ee4e919efef2f4d2473bac
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
int main() {
void bubble_sort(char s[], int len);
char s[200] = { 0 };
while ((scanf("%s", s)) != EOF)
{
int lengh = strlen(s);
//开始排序
bubble_sort(s, lengh);
printf("%s", s);
}
return 0;
}
//编写冒泡排序
void bubble_sort(char s[], int len)
{
int i, j;
int temp;
for (i = 0; i < len-1; i++)//len个元素,外层需要n-1次循环;
{
for (j = 0; j < len - 1 - i; j++)//内层循环的循环次数是递减的;
{
if (s[j] > s[j + 1])
{
temp = s[j];
s[j] = s[j + 1];
s[j + 1] = temp;
}
}
}
}
#C笔试面试##C语言#
#include<stdio.h>
#include<string.h>
int main() {
void bubble_sort(char s[], int len);
char s[200] = { 0 };
while ((scanf("%s", s)) != EOF)
{
int lengh = strlen(s);
//开始排序
bubble_sort(s, lengh);
printf("%s", s);
}
return 0;
}
//编写冒泡排序
void bubble_sort(char s[], int len)
{
int i, j;
int temp;
for (i = 0; i < len-1; i++)//len个元素,外层需要n-1次循环;
{
for (j = 0; j < len - 1 - i; j++)//内层循环的循环次数是递减的;
{
if (s[j] > s[j + 1])
{
temp = s[j];
s[j] = s[j + 1];
s[j + 1] = temp;
}
}
}
}
#C笔试面试##C语言#