C 语言实例 - 字符串排序
C 语言教程
· 2019-02-21 10:11:31
按字典顺序排序。
实例
#include<stdio.h>
#include <string.h>
int main()
{
int i, j;
char str[10][50], temp[50];
printf("输入10个单词:\n");
for(i=0; i<10; ++i)
scanf("%s[^\n]",str[i]);
for(i=0; i<9; ++i)
for(j=i+1; j<10 ; ++j)
{
if(strcmp(str[i], str[j])>0)
{
strcpy(temp, str[i]);
strcpy(str[i], str[j]);
strcpy(str[j], temp);
}
}
printf("\n排序后: \n");
for(i=0; i<10; ++i)
{
puts(str[i]);
}
return 0;
}
输出结果为:
输入10个单词: C C++ Java PHP Python Perl Ruby R JavaScript PHP 排序后: C C++ Java JavaScript PHP PHP Perl Python R Ruby
点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html
Computational Advertising
by Kushal Dave、Vasudeva Varma / Now Publishers Inc / 2014
Computational Advertising (CA), popularly known as online advertising or Web advertising, refers to finding the most relevant ads matching a particular context on the Web. The context depends on the t......一起来看看 《Computational Advertising》 这本书的介绍吧!