问题 A: 谁是你的潜在朋友
#include <iostream>
using namespace std;
int main()
{
int n, m;
while (cin >> n >> m)
{
int a[205], h[205] = { 0 };
for (int i = 0; i < n; i++)
{
cin >> a[i];
h[a[i]]++;
}
for (int i = 0; i < n; i++)
{
if (h[a[i]] > 1)
{
cout << a[i] - 1 << endl;;
}
else
{
cout << "BeiJu" << endl;
}
}
}
return 0;
}
问题 B: 分组统计
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
int n, m, max;
cin >> m;
while (m--)
{
cin >> n;
vector<int> v[1005];
set<int> s;
int a[1005], b[1005];
for (int i = 0; i < 1005; i++)
{
v[i].clear();
}
for (int i = 0; i < n; i++)
{
cin >> a[i];
s.insert(a[i]);
}
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
v[x].push_back(a[i]);
}
for (int i = 0; i < 105; i++)
{
if (v[i].size())
{
memset(b, 0, sizeof(b));
for (int j = 0; j < v[i].size(); j++)
{
b[v[i][j]]++;
}
cout << i << "=" << "{";
int flag = 0;
int k = 1;
for (auto j = s.begin(); j != s.end(); j++)
{
if (flag == 0)
{
cout << *j << "=" << b[*j];
flag = 1;
}
else
{
cout << "," << *j << "=" << b[*j];
}
}
cout << "}" << endl;
}
}
}
return 0;
}
问题 C: Be Unique
#include<iostream>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
while(cin >> n)
{
int a[10005] = { 0 };
int bets[10005] = { 0 };
for(int i = 0; i < n; i++)
{
cin >> a[i];
bets[a[i]]++;
}
int ans = -1;
for(int i = 0; i < n; i++)
{
if(bets[a[i]] == 1)
{
ans = a[i];
break;
}
}
if(ans == -1)
{
cout << "None" << endl;
}
else
{
cout << ans << endl;
}
}
}
问题 D: String Subtraction
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1, s2;
getline(cin, s1);
getline(cin, s2);
for (int i = 0; i < s1.length(); i++)
{
if (s2.find(s1[i]) == string::npos)
{
cout << s1[i];
}
}
return 0;
}