#include <bits/stdc++.h> using namespace std; int main() { string str; while (cin >> str) { string sz[100]; int index = 0; int last = 0; for (int i = 0; i < str.length(); ++i) { if (i == str.length() - 1) { string temp; for (int j = last; j <= i; ++j) { temp += str[j]; } sz[index++] = temp; break; } if (str[i] == ',') { string temp; for (int j = last; j < i; ++j) { temp += str[j]; } sz[index++] = temp; last = i + 1; } } int length = 0; for (int i = 0; i < 100; ++i) { if (sz[i] == "") { length = i; break; } } // 对 sz[] 进行冒泡排序 for (int i = 0; i < length - 1; ++i) { for (int j = i + 1; j < length; ++j) { if (sz[i] > sz[j]) { string temp = sz[i]; sz[i] = sz[j]; sz[j] = temp; } } } for (int i = 0; i < length - 1; ++i) { cout << sz[i] << ","; } cout << sz[length - 1] << "\n"; } }
全部评论
(0) 回帖