沐里纷纷


私信TA

用户名:Epoch

访问量:62968

签 名:

我不会算法

等  级
排  名 37
经  验 12828
参赛次数 1
文章发表 172
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

不会算法

解题思路:

注意事项:

参考代码:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string>

using namespace std;

void splitStr(string str, char c, vector<string>& strList)
{
	int index1 = 0;
	int index2 = index1;
	int len = str.length();
	while (index1 < len && (index2 = str.find(c,index1)) != string::npos)
	{
		string temp = str.substr(index1, index2 - index1);
		strList.push_back(temp);
		index1 = index2 + 1;
	}
	if (index1 < len)
	{
		string temp = str.substr(index1, len - index1);
		strList.push_back(temp);
	}
	remove(strList.begin(), strList.end(), "");
	//strList.shrink_to_fit();
}

int main()
{
	string temp;
	vector<string> cardArr, washedCardArr;
	
	while (getline(cin, temp))
		splitStr(temp, ' ', cardArr);

	if (cardArr.size() < 52)
	{
		cout << -1;
		return 1;
	}

	for (int i = 0; i < 52; i++)
	{
		string curCard = cardArr[i];
		int curCardNo = 0;
		if (curCard == "10")
			curCardNo = 10;
		else if (curCard == "J")
			curCardNo = 11;
		else if (curCard == "Q")
			curCardNo = 12;
		else if (curCard == "K")
			curCardNo = 13;
		else
			curCardNo = curCard[0] - '0';

		if (washedCardArr.size() >= curCardNo)
			washedCardArr.insert(washedCardArr.begin() + curCardNo, curCard);
		else
			washedCardArr.push_back(curCard);
	}

	for (vector<string>::iterator it = washedCardArr.begin(); it < washedCardArr.end(); it++)
		cout << *it << " ";
	cout << endl;

	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区