65,189
社区成员




Input
Output
2
3
1 3 -5
-2 4 1
5
1 2 3 4 5
1 0 1 0 1
Case #1: -25
Case #2: 6
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
int nCases = 0;
cin >> nCases;
cin.get();
for (int i = 0; i < nCases; i++)
{
vector<int> X;
vector<int> Y;
int nSize = 0;
cin >> nSize;
for (int j = 0; j < nSize; j++)
{
int n = 0;
cin >> n;
X.push_back(n);
}
for (int j = 0; j < nSize; j++)
{
int n = 0;
cin >> n;
Y.push_back(n);
}
sort(X.begin(), X.end(), std::greater<int>());
sort(Y.begin(), Y.end(), std::less<int>());
int scalar = 0;
for (int j = 0; j < nSize; j++)
{
scalar += X[j] * Y[j];
}
cout << "Case #" << i + 1 << ": ";
cout << scalar << endl;
}
fclose(stdin);
fclose(stdout);
return 0;
}
///////////////////////////End Sub//////////////////////////////////