⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prog11_1.cpp

📁 浙大颜晖视频课件
💻 CPP
字号:
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
    int i,j, n = 0;
    char *temp,*color[20], str[10];

    printf("请输入颜色名称,每行一个,#结束输入:\n");
    /*动态输入*/
 scanf("%s", str);
    while(str[0] != '#') {
        color[n] = (char *)malloc(sizeof(char)*(strlen(str)+1));  
        strcpy(color[n], str);
	        n++;
        scanf("%s", str);
    }
/*排序*/
    for(i = 1; i < n; i++)
         for(j = 0; j < n-i; j++)  
           if(strcmp(color[j],color[j+1])>0){    
             temp = color[j];
             color[j] = color[j+1];
             color[j+1] = temp;
           }
        /*输出*/
    for(i = 0; i < n; i++) 
        printf("%s  ", color[i]);
    printf(“\n”);
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -