笔试题目



#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

bool compare(string str1, string str2) {

	int len1 = str1.size();
	int len2 = str2.size();
	int i = 0;

	while (1) {
		if (i >= len1 || i >= len2)
			break;
		
		if (str1[i] < str2[i])
			return true;
		else if (str1[i] > str2[i])
			return false;
		else 
			i++;
	}

	if (str1.size() < str2.size())
		return true;
	else
		return false;
}

int main()
{
	string input;
	vector <string> str_vec;
	vector <int> num_vec;
	string tmp;
	int count;
	int max_len;
	vector <string> elem_vec;

	while (cin >> input) {

		str_vec.clear();
		num_vec.clear();
		tmp.clear();
		count = 0;
		max_len = 0;

		for (int i = 0; i < input.size(); i++) {
			if (input[i] >= 'a' && input[i] <= 'z') {
				if (count > 0) {
					str_vec.push_back(tmp);
					num_vec.push_back(count);
					tmp.clear();
					count = 0;
				}
				tmp += input[i];
			}
			else if (input[i] >= '0' && input[i] <= '9'){			
				count += (count * 10 + input[i] - '0');
				if (count > max_len)
					max_len = count;
			}
			else {
				continue;
			}
		}
		 
		if (tmp.size() > 0 && count > 0) {
			str_vec.push_back(tmp);
			num_vec.push_back(count);
			tmp.clear();
			count = 0;
			if (count > max_len)
				max_len = count;
		}

		elem_vec.clear();
		string elem;

		for (int i = 0; i <= max_len; i++) {
			for (int j = 0; j < str_vec.size(); j++) {
				if (num_vec[j] == i) {
					elem_vec.push_back(str_vec[j]);
				}	
			}
			sort(elem_vec.begin(), elem_vec.end(), compare);
			//sort(elem_vec.begin(), elem_vec.end());
			for (int m = 0; m < elem_vec.size(); m++) {
				for (int n = 0; n < i; n++)
					cout << elem_vec[m];
			}
			elem_vec.clear();
		}
		cout << endl;
		cout << "---------------------------" << endl;
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值