题目要求:
从键盘上输入N个字符串(约定:每个字符串中字符数≤80字节),对其进行升序排序并输出。
函数接口定义:
void sort_Str(char *str[]);
裁判测试程序样例:
#include<stdio.h>
#include<string.h>
#define N 5
void sort_Str(char *src[]);
int main(void)
{
int i;
char *pstr[N], str[N][81];
for (i=0; i<N; i++)
{
pstr[i] = str[i];
}
for (i=0; i<N; i++)
{
gets(pstr[i]);
}
sort_Str(pstr);
for (i=0; i<N; i++)
{
printf("%s\n", pstr[i]);
}
return 0;
}
输入样例:
hello
My
Friend
Are you ok?
help me!
输出样例:
Are you ok?
Friend
My
hello
help me!
/* 请在这里填写答案 */
void sort_Str(char *src[]){
char t[81],*p[N];
int i,j;
for(i=0;i<N;i++){
p[i]=src[i];
} //别忘了依次赋值!!
for(i=0;i<N;i++){
for(j=i;j<N;j++){
if(strcmp(p[i],p[j])>0){
strcpy(t,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],t);
}
}
}
}
这篇博客主要探讨如何对一组字符串进行升序排序。根据题目要求,输入包含N个字符数不超过80字节的字符串,需要实现一个排序算法来对它们进行排序。函数接口已给出,需要填写相应的代码实现。博客内容将围绕字符串排序算法展开,可能涉及指针操作和比较函数的设计。
1124

被折叠的 条评论
为什么被折叠?



