C++
#include<iostream> #include<string.h> #include<algorithm> using namespace std; int main() { int n, index; string stemp; cin >> n; string *a= new string[n]; //接受键盘输入,用字符串数组 for (int i = 0; i < n; i++) cin >> a[i]; //选择排序,找到最小的元素下标,交换 for (int i = 0; i < n; i++) { index = i; for (int j = i + 1; j < n; j++) if (a[j] < a[index]) index = j; if (a[index] < a[i]) { stemp = a[index]; a[index] = a[i]; a[i] = stemp; } } //输出结果 for (int i = 0; i < n-1; i++) cout <<a[i]<<' '; cout<<a[n-1]<<endl; return 0; }