110205 Stack 'em Up ( Stack em Up )


#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <stdlib.h>
using namespace std;

#define POKER_CNT 52
#define LINE_BUF_CNT 6

static char s_Line[LINE_BUF_CNT];

void ShuffleOnPokers(int* target, int* shuffleMethod)
{
	static int tmp[POKER_CNT + 1];
	for (int i = 1; i <= POKER_CNT; ++i)
	{
		tmp[i] = target[shuffleMethod[i]];
	}
	for (int i = 1; i <= POKER_CNT; ++i)
	{
		target[i] = tmp[i];
	}
}

char* s_PokerType[] = {"Clubs", "Diamonds", "Hearts", "Spades"};

void OutputPoker(int poker)
{
	int typeIndex = (poker - 1) / 13;
	poker = poker - 13 * typeIndex;
	if (poker <= 9)
		cout << (poker + 1);
	else if (poker == 10)
		cout << "Jack";
	else if (poker == 11)
		cout << "Queen";
	else if (poker == 12)
		cout << "King";
	else if (poker == 13)
		cout << "Ace";

	cout << " of " << s_PokerType[typeIndex] << endl;
}

void OutputPokers(int* pokers)
{
	for (int i = 1; i <= POKER_CNT; ++i)
	{
		OutputPoker(pokers[i]);
	}
}

void DoShuffle(const vector<int*>& shuffleVec, const vector<int>& shuffleSteps)
{
	int target[POKER_CNT + 1];
	for (int i = 1; i <= POKER_CNT; ++i)
		target[i] = i;

	for(int i = 0; i < shuffleSteps.size(); ++i)
	{
		ShuffleOnPokers(target, shuffleVec[shuffleSteps[i]]);
	}
	OutputPokers(target);
}

void HandleDataSet()
{
	int shuffleTypes = 0;
	cin >> shuffleTypes;

	// Init
	vector<int*> shuffleVec;
	for (int i = 0; i < shuffleTypes; ++i)
	{
		shuffleVec.push_back(new int[POKER_CNT + 1]);
		for (int j = 1; j <= POKER_CNT; ++j)
		{
			int tmp;
			cin >> tmp;
			shuffleVec[i][j] = tmp;
		}
	}

	// Get ShuffleSteps
	vector<int> shuffleSteps;
	char* tmp = fgets(s_Line, LINE_BUF_CNT, stdin); // Consume the '\n' right after the last poker of the last shuffle type.
	while(tmp)
	{
		tmp = fgets(s_Line, LINE_BUF_CNT, stdin);
		if (!tmp)
			break;
		if (s_Line[0] == '\n') // Check whether it is an empty line.
			break;

		int nLen = strlen(s_Line);
		s_Line[nLen] = '\0';
		shuffleSteps.push_back(atoi(s_Line) - 1);
	}

	DoShuffle(shuffleVec, shuffleSteps);


	// Clear
	for (int i = 0; i < shuffleTypes; ++i)
	{
		delete[] shuffleVec[i];
	}
}

void DoWork()
{
	int nDataSetCnt;
	cin >> nDataSetCnt;
	fgets(s_Line, LINE_BUF_CNT, stdin); // Consume the '\n' right after the test case count.
	fgets(s_Line, LINE_BUF_CNT, stdin); // Consume the empty line after the test case count.

	int i = 1;
	while(i <= nDataSetCnt)
	{
		HandleDataSet();
		if (i < nDataSetCnt)
			cout << endl;
		++i;
	}
}


int main(int argc, char* argv[])
{
	DoWork();
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
网络栈(networking stack)是指操作系统内核中的一组网络协议和功能,用于处理网络通信。Linux网络栈的架构如下所示:顶部是用户空间层或应用层,负责定义网络栈的用户接口;底部是物理设备层,提供与网络连接的物理设备,例如以太网;中间是网络子系统,是网络栈的核心部分。网络子系统通过sk_buffs(socket缓冲区)在源和目的地之间传输数据包。 在Linux网络栈中,驱动程序(Driver)层负责数据的收发,而上层负责网络栈的处理。如果不想发送TCP/IP数据帧,可以创建原始套接字(raw socket),自己构造以太网协议头部,并通过驱动程序层发送数据。 此外,网络栈还涉及到协议和协议操作(prot/prot_ops)。协议操作位于inet(即prot_ops)层,它在socket和具体协议之间起到桥梁的作用。协议(prot)层是具体的协议实现,例如tcp_v4_connect。在调用connect函数时,先经过inet层的bind操作,然后才是具体协议的connect操作。 因此,Linux网络栈是一个由驱动程序、网络子系统、协议和协议操作组成的网络协议栈,用于处理网络通信。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Networking Stack & Simple Network Driver 实现 & 以太网协议数据包结构](https://blog.csdn.net/GW569453350game/article/details/53127800)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Linux网络栈解剖(Anatomy of the Linux networking stack)](https://blog.csdn.net/maimang1001/article/details/123276405)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值