竞赛讨论区 > C++ 版本
头像
XTher
发布于 2020-04-01 22:38
+ 关注

C++ 版本

#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) 回帖
加载中...
话题 回帖

本文相关内容

等你来战

查看全部

热门推荐