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、没时间做了,就没管