# 笔试题0722

#include<iostream>
#include<vector>
#include<map>
using namespace std;
int main()
{

int num;
int a;
map<int, int>mp;
cin >> num;
vector<int>input(num);
for (int i = 0; i < num; i++)
{
cin >> input[i];
mp[input[i]]++;
}
int max_count = 1;
int first_number = -1;
int second_number = -1;
for (auto it = mp.begin(); it != mp.end(); it++)
{
if (it->second > max_count)
{
max_count = it->second;
first_number = it->first;
}
}
if (max_count >= 4)
{
cout << first_number*first_number << endl;
}
else if (max_count == 1)
cout << -1 << endl;
else
{
mp.erase(first_number);
max_count = 1;

for (auto it = mp.begin(); it != mp.end(); it++)
{
if (it->second > max_count)
{
max_count = it->second;
second_number = it->first;
}
}
if (max_count == 1)cout << -1 << endl;
else
cout << first_number*second_number << endl;
}

system("pause");
return 0;
}

#include<iostream>
#include<vector>
using namespace std;
int main()
{
int num;
cin >> num;
vector<int>input(num + 1, 0);
for (int i = 1; i <= num; i++)
{
cin >> input[i];
}
int res = 0;
for (int i = 0; i <= num; i++)
{
if (i != input[i])
{
swap(input[i], input[input[i]]);
res++;
}
}
cout << res << endl;
system("pause");
return 0;
}

12-28
01-30 18万+

09-08 1万+
07-09 1万+
04-12 2103
09-26 84
08-12 2万+
10-18 4030
03-19 7490
04-22 1万+