5-30 字符串的冒泡排序 (20分)

来源:互联网 发布:我的世界起床战争端口 编辑:程序博客网 时间:2024/05/16 01:10


#include <iostream>#include <sstream>#include <string.h>#include <map>#include <stdio.h>#include <algorithm>using namespace std;int main(){    int i,j,n,k;    char str[200][20];    scanf("%d %d",&n,&k);    for(i=0; i<n; i++)    {        scanf("%s",str[i]);        getchar();    }    for(i=0; i<k; i++)        for(j=1; j<n; j++)            if(strcmp(str[j-1],str[j])>0)            {                swap(str[j-1],str[j]);            }    for(int i=0; i<n; i++)        printf("%s\n",str[i]);    return 0;}


0 0
原创粉丝点击