SK


私信TA

用户名:1973231998

访问量:18528

签 名:

成功只是一时的,失败才是主旋律,笑着面对失败是主要的。

等  级
排  名 261
经  验 5688
参赛次数 0
文章发表 59
年  龄 0
在职情况 学生
学  校 *
专  业

  自我简介:

解题思路:

排序很简单直接sort(),主要是输入输出;留作笔记;


参考代码:

#include<bits/stdc++.h>
using namespace std;
struct cards {
	int num;
	int color;
}a[5];
bool ordn(struct cards& x, struct cards& y)
{
	if (x.num < y.num)
	{
		return true;
	}
	else if (x.num == y.num)
	{
		if (x.color < y.color) return true;
		else return false;
	}
	else return false;
}
void fx(int x)
{
	if (x == 1) cout<< 'd';
	else if (x == 2) cout<< 'c';
	else if (x == 3) cout<<'h';
	else if (x == 4) cout<<'s';
}
bool strcmp(char d,  char f )
{
	return d==f;
}
int main()
{
	char *nu;
	char s[11];
	nu = s;
	cin >> s;

	for (int i = 0; i < 5; i++)
	{
		if (strcmp(*nu, '1')) { a[i].num = 10; nu += 2; }
		else if (strcmp(*nu, 'J')) { a[i].num = 11; nu++; }
		else if (strcmp(*nu, 'Q')) { a[i].num = 12; nu++; }
		else if (strcmp(*nu, 'K')) { a[i].num = 13; nu++; }
		else if (strcmp(*nu, 'A')) { a[i].num = 14; nu++; }
		else if(*nu>='2'&&*nu<='9')
		{
			a[i].num =(int)(*nu - '0');
			nu++;
		}
		if (strcmp(*nu, 'd')) { a[i].color = 1; nu++; }
		else if (strcmp(*nu, 'c')) { a[i].color = 2; nu++; }
		else if (strcmp(*nu, 'h')) { a[i].color = 3; nu++; }
		else if (strcmp(*nu, 's')) { a[i].color = 4; nu++; }
	}

	sort(a, a + 5, ordn);
	
	for (int i = 0; i < 5; i++)
	{
		if (a[i].num == 11) { cout << 'J'; fx(a[i].color); }
		else if (a[i].num == 12) { cout << 'Q'; fx(a[i].color); }
		else if (a[i].num == 13) { cout << 'K'; fx(a[i].color); }
		else if (a[i].num == 14) { cout << 'A'; fx(a[i].color); }
		else { cout << a[i].num; fx(a[i].color); }
		if(i!=4)cout << " ";
	}
	
	
}


 

0.0分

4 人评分

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

编程语言转换

万能编程问答

代码解释器

  评论区