2020年2月25日 PAT

B1039/A1092 20’ 40mins 散列 easy

#include <iostream>
#include <string.h>
using namespace std;
void test()
{
	int hash[128];
	memset(hash,0,sizeof(hash));

	string a,b;
	getline(cin,a);
	int lena = a.size();
	int sum = 0;
	for (int i = 0; i < lena; ++i)
	{
		hash[a[i]] += 1;
		sum += 1;
	}
	getline(cin, b);
	int lenb = b.size();
	int find_ok = 0;
	for (int i = 0; i < lenb; ++i)
	{
		if (hash[b[i]] != 0)//如果找到
		{
			hash[a[i]] -= 1;
			sum--;
			find_ok++;
		}
	}
	if (find_ok == lenb)
		cout << "Yes " << sum << endl;
	else
		cout << "No " << lenb-find_ok << endl;
}
int main ()
{
	test();
	system("pause");
	return 0;
}

B1042 20’ 12min 散列 easy

#include <iostream>
#include <string>
using namespace std;


void test()
{
	int hash[256] = {0};
	string a;
	getline(cin,a);
	int len = a.size();
	int maxs = -1;
	for (int i = 0; i < len; ++i)
	{
		if (a[i] >= 'A'&& a[i] <= 'Z') hash[a[i] + 32] += 1;
		else
			hash[a[i]] += 1;

		
	}
	int flag_i = -1;
	for (int i='a'; i <='z'; i++)
	{
		if (maxs < hash[i])
		{
			maxs = hash[i];
			flag_i = i;
		}
	}
	printf("%c %d\n",flag_i,maxs);
}
int main()
{
	test();
	system("pause");
	return 0;
}

B1043 20’ 13min 散列 easy

#include <iostream>
#include <string>

using namespace std;

void test()
{
	char dict[6] = { 'P','A','T','e','s','t'};
	int hash[6] = { 0 };
	string a;
	getline(cin, a);
	int len = a.size();
	int sum = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = 0; j < 6; j++)
		{
			if (a[i] == dict[j])
			{
				hash[j]++;
				sum++;
			}
		}
	}
	while (sum--)
	{
		for (int i = 0; i < 6; ++i)
		{
			if (hash[i] > 0)
			{
				printf("%c", dict[i]);
				hash[i]--;
			}
		}
	}
}
int main()
{
	test();
	system("pause");
	return 0;
}

B1047 20’ 7min 散列 easy

#include <iostream>
using namespace std;
int main()
{
	int hash[10010] = { 0 };
	int n;
	cin >> n;
	int i, temp, score;
	while (n--)
	{
		scanf("%d-%d %d", &i, &temp, &score);
		hash[i] += score;
	}
	int maxs = -1;
	int flag = -1;
	for (int i = 0; i < 10005; ++i)
	{
		if (maxs < hash[i])
		{
			maxs = hash[i];
			flag = i;
		}
	}
	cout << flag << " " << hash[flag] << endl;
	system("pause");
	return 0;
}

A1041 20’ 15min 散列 easy

#include <iostream>
using namespace std;
int main()
{
	int hash[10010] = {0}, a[100010] = { 0 };
	int n;
	cin >> n;
	for(int i=0; i < n; ++i)
	{
		cin >> a[i];
		hash[a[i]]++;
	}
	int ans = -1;
	for (int i = 0; i < n; ++i)
	{
		if (hash[a[i]] == 1)
		{
			ans = a[i];
			break;
		}
	}
	if (ans == -1)
	{
		cout << "None";
	}
	else
		cout << ans << endl;
	system("pause");
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值