今晚的360第二题编程题
今晚的360第二题编程题,考完后改了一下,现在是对的吗?
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int T;
long r, g, b;
vector<long> result;
cin >> T;
for (int i = 0; i < T; i++)
{
vector<long> num;
long count = 0;
cin >> r >> g >> b;
num.push_back(r);
num.push_back(g);
num.push_back(b);
sort(num.begin(), num.end());
if (num[2] == 0)
{
count = 0;
}
else
{
if (2 * (num[0] + num[1]) <= num[2])
count = num[0] + num[1];
else
{
long min_num = num[0];
long temp_max = 0;
long temp1 = num[2] - num[0];
long temp2 = num[1] - num[0];
if (temp1 >= 2 * temp2)
temp_max = temp2;
else
temp_max = temp1 / 2;
count = min_num + temp_max ;
}
}
result.push_back(count);
}
for (int i = 0; i < T; i++)
{
cout << result[i] << endl;
}
return 0;
}
#实习##笔试题目##include<vector>
#include<algorithm>
using namespace std;
int main()
{
int T;
long r, g, b;
vector<long> result;
cin >> T;
for (int i = 0; i < T; i++)
{
vector<long> num;
long count = 0;
cin >> r >> g >> b;
num.push_back(r);
num.push_back(g);
num.push_back(b);
sort(num.begin(), num.end());
if (num[2] == 0)
{
count = 0;
}
else
{
if (2 * (num[0] + num[1]) <= num[2])
count = num[0] + num[1];
else
{
long min_num = num[0];
long temp_max = 0;
long temp1 = num[2] - num[0];
long temp2 = num[1] - num[0];
if (temp1 >= 2 * temp2)
temp_max = temp2;
else
temp_max = temp1 / 2;
count = min_num + temp_max ;
}
}
result.push_back(count);
}
for (int i = 0; i < T; i++)
{
cout << result[i] << endl;
}
return 0;
}