杭电OJ2016

#include <iostream>
using namespace std;
int main()
{
	int n,a[105];
	while (cin >> n&&n)
	{
		int i;
		for (i = 0; i < n; i++)
			cin >> a[i];
		int j = 0,temp;
		for (i = 1; i < n; i++)
		{
			if (a[i] < a[j])
				j = i;
		}
		temp = a[0];
		a[0] = a[j];
		a[j] = temp;
		for (i = 0; i < n; i++)
		{
			if (i == 0)
				cout << a[i];
			if (i>0)
				cout << " " << a[i];
		}
		cout << endl; 
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42265486/article/details/83660501