网易游戏笔试【2020暑期实习生】游戏研发工程师第二批在线笔试4月6日

1、顺子

AC代码(C++)

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

using namespace std;

int main()
{
	int T, N;
	string c;
	cin >> T;
	while (T--)
	{
		vector<string> cards;
		cin >> N;
		while (N--)
		{
			cin >> c;
			cards.push_back(c);
		}
		int nums[13] = {0};
		for (auto x : cards)
		{
			if(x == "A") nums[0]++;
			else if(x == "10") nums[9]++;
			else if(x == "J") nums[10]++;
			else if(x == "Q") nums[11]++;
			else if(x == "K") nums[12]++;
			else if(x[0] >= '2' && x[0] <= '9'){
				nums[x[0] - '0' - 1]++;
			}
		}
		int count = 0, temp, series = 0;
		for (int i = 0; i < 13; i++)
		{
			if(nums[i] != 0)
			{
				temp = nums[i];
				series = 1;
				int j = i + 1;
				while (j < 13 && nums[j] != 0)
				{
					series++;
					temp *= nums[j];
					if(series >= 5)
						count += temp;
					j++;
				}
			}
		}
		cout << count << endl;

	}
	system("pause");
	return 0;
}

2、大整数编码

AC代码(C++)

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

using namespace std;

string toBinary(string s)
{
	string res;
	int num = atoi(s.data());
	while (num)
	{
		res += to_string(num % 2);
		num /= 2;
	}
	if(res.size() < 10)
	{
		int t = 10 - res.size();
		while (t--)
		{
			res += "0";
		}
	}
	//reverse(res.begin(), res.end());
	return res;
}

int toNum(string s)
{
	int res = 0;
	for (int i = s.size() - 1; i >= 0; i--)
	{
		res += (s[i] - '0') * (int)pow(2, s.size() - i - 1);
	}
	return res;
}

char toChar(int number)
{
	if(number >= 0 && number <= 9) return number + '0';
	else{
		return 'A' + number - 10;
	}
}

int main()
{
	int T, N;
	cin >> T;
	while (T--)
	{
		string bignum;
		cin >> bignum;
		int t = bignum.size();
		string binStr;
		while (t >= 3)
		{
			string group = bignum.substr(t - 3, 3);
			binStr += toBinary(group);
			t -= 3;
		}
		if(t > 0)
		{
			string lastgroup = bignum.substr(0, t);
			binStr += toBinary(lastgroup);
		}
		reverse(binStr.begin(), binStr.end());
		while (binStr[0] == '0')
			binStr.erase(0, 1);

		int i = binStr.size();
		string result;
		while (i >= 5)
		{
			string five = binStr.substr(i - 5, 5);
			result += toChar(toNum(five));
			i -= 5;
		}
		if(i > 0)
		{
			string lastFive = binStr.substr(0, i);
			result += toChar(toNum(lastFive));
		}
		reverse(result.begin(), result.end());
		cout << result << endl;
	}

	system("pause");
	return 0;
}

3、没时间做了,就没管

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值