题解 | #字符串排序#

字符串排序

http://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
    int n,count=0;
    scanf("%d",&n);
    char words[1001][101] = {0};
    for(int i=0;i<n;i++){
        scanf("%s",words[i]);
    }
    
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            if(strcmp(words[i],words[j])>0){
                char temp_word[100];
                strcpy(temp_word,words[i]);
                strcpy(words[i],words[j]);
                strcpy(words[j],temp_word);
            }
        }
    }
    
    for(int i=0;i<n;i++){
        printf("%s\n",words[i]);
    }
    return 0;
}
全部评论

相关推荐

12-26 14:44
复旦大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务