Problem Description
输入n(n<100)个数,找出其中最小的数,将它与最前面的数交换后输出这些数。
 


Input
输入数据有多组,每组占一行,每行的开始是一个整数n,表示这个测试实例的数值的个数,跟着就是n个整数。n=0表示输入的结束,不做处理。
 


Output
对于每组输入数据,输出交换后的数列,每组输出占一行。
 


Sample Input
4 2 1 3 4 5 5 4 3 2 1 0
 


Sample Output
1 2 3 4 1 4 3 2 5
 
 
#include<stdio.h>
int main()
{
    int n, num[1000];
    int i, j, t, min, flag;
    while( scanf( "%d", &n ) == 1 )
    {
           flag = 0;
           if( n == 0 )
               break;
           else
           {
               for( i = 0 ; i < n ; i++ )
                    scanf( "%d", &num[i] );
               min = num[0];
               for( i = 0 ; i < n ; i++ )
               {
                   if( min > num[i] )
                   {
                       min = num[i];
                       flag = i;
                   }
               }
                       t = num[flag];
                       num[flag] = num[0];
                       num[0] = t;
               for( i = 0 ; i < n ; i++ )
               {
                  
                       printf( i == ( n - 1 )? "%d\n":"%d " ,num[i] );
                  
               }
            }
    }
    return 0;
}
posted on 2011-11-16 00:42  狸の舞  阅读(135)  评论(0编辑  收藏  举报