如何输入多组测试数据

来源:互联网 发布:市场上主流单片机 编辑:程序博客网 时间:2024/06/06 14:26
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
 

Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
 

Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
 

Sample Input
qweasdzxc
 

Sample Output
e q wa d sc x z 
对于这个输入多组数据的问题,可以使用以下方式来解决:
#include<stdio.h>
int main(){    char a[3],t;    int i,j;    while(scanf(" %c %c %c",&a[0],&a[1],&a[2])!=EOF)//这里数组元素前应该加&    {        for (i = 0; i < 2; i++)        {            for (j = 0; j < 2 - i; j++)            {                if(a[j]>a[j+1])                {                    t=a[j];                    a[j]=a[j+1];                    a[j+1]=t;                }            }        }    printf("%c %c %c\n", a[0], a[1], a[2]);    }
return 0;
}