intensify, sympathetic, further (v.), personnel, invest, substantial, briefing, staff, at the end of day, in the view of, interlock, in vain, play the devil’s advocate for, hinder, infancy, condition(v.), not least, be subjected to, at every turn, dominate, pervasive, conditioner, adhere to, anthropologist, distinct from, Spaniard, Briton, channel (v.), groove, kaleidoscopic, by means of, fair play 假如我粘贴输入上列单词,输出按照字母表顺序,以首字母(首字母相同则参照第二个字母)排序。请问如何通过C语言实现?
我只会编写 输入的单词的字母量已知的情况,但是显然有一些单词少的有几个,多的十几个字母。这种情况该如何编写呢?请不要写得太难,能否用基础知识编写呢?
我看到觉得不错就会采纳的,请放心。
你好!
给你举个例子,如有帮助,请采纳。
你把字符串替换成你的就可以了。才用的是冒泡排序
#include<stdio.h>
#include<string.h>
void sort(char *a[]);
void print(char *a[]);
int main()
{
char *a[] ={"ceo","define","basic","abc","empty"};
printf("原来的序列是:\n");
print(a);
sort(a);
printf("\n排序后的序列是:\n");
print(a);
printf("\n");
return 0;
}
void sort(char *a[])
{
int i,j;
char *temp;
for(i=0;i<4;i++)//注意是i<4
{
for(j=0;j<4;j++)//注意是j<4,由于以下要+1和后面的那个字符串比較
{
if(strcmp(a[j],a[j+1])>0)//字符串比較:>0表示前面的字符串比后面的大则交换
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
void print(char *a[])
{
int i;
for(i=0;i<5;i++)
{
printf("%s ",a[i]);
}
}