求帮助,
  • 板块学术版
  • 楼主JSSL9718
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/11/26 18:24
  • 上次更新2024/11/26 20:24:36
查看原帖
求帮助,
1459616
JSSL9718楼主2024/11/26 18:24

#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <string>
#include <ctype.h>
using namespace std;


vector<long long> splitString(string& str, char ch)
{
	vector<long long> res;
	string tmp;
	for (int i = 0; i < str.size(); i++)
	{
		
		if (str[i] == ch)
		{
			while (!tmp.empty() && tmp[0] == '0')
			{
				tmp.erase(tmp.begin());
			}
			if (!tmp.empty())
			{
				res.push_back(stoll(tmp));
			}
			tmp.clear();
		}
		else
		{
			tmp += str[i];
		}
	}

	while (!tmp.empty() && tmp[0] == '0')
	{
		tmp.erase(tmp.begin());
	}
	if (!tmp.empty())
	{
		res.push_back(stoll(tmp));
	}

	return res;
}



int main()
{
	int T;
	cin >> T;

	while (T--)
	{
		int len;
		string str;
		cin >> len >> str;

		vector<long long> res = splitString(str, '6');

		sort(res.begin(), res.end());

		cout << res.size() << endl;
		for (int i = 0; i < res.size(); i++)
		{
			cout << res[i]<<endl;
		}
	}

	return 0;
}

测试样例过了但还是wa,有没有大佬救一下

2024/11/26 18:24
加载中...