交换输出
Time Limit:1000MS Memory Limit:65536K
Total Submit:75 Accepted:57
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
Source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1166 {
class Program {
static void Main(string[] args) {
string sb;
while ((sb = Console.ReadLine()) != null) {
string[] s = sb.Split();
int n = int.Parse(s[0]);
if (n == 0) break;
int[] a = new int[105];
int min = 100000000, x = 0;
for (int i = 1; i <= n; i++) {
a[i] = int.Parse(s[i]);
if (a[i] < min) { min = a[i]; x = i; }
}
a[x] = a[1];
a[1] = min;
for (int i = 1; i <= n; i++)
Console.Write(a[i] + " ");
Console.WriteLine();
}
}
}
}