文章目录
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;
}