ZeroJudge D659: Cost Cutting

UVa 11727 – Cost Cutting

XYZ Corporation has been hit hard by the massive financial crisis and is forced to cut expenses. These measures include downsizing office space, open-sourcing resources, reducing incentives, cutting down on luxury spending, and layoffs.

The company currently has 3 employees, and it needs to lay off 2 of them. After a series of interviews, the company aims to let go of the two employees—one with the highest salary and the other with the lowest. This approach seems to be a trend nowadays.

If there are three employees and two need to be laid off—one with the highest salary and the other with the lowest—then the employee with the middle salary won't be laid off.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The first line contains an integer T (T < 20) representing the number of test cases to follow. Each test case consists of three integers representing the salaries of three individuals. Their salaries range from 1000 to 10000.For each test case, output a line in the format 'Case X: Y', where X represents the test case number, and Y represents the salary of the employee who won't be laid off.
3
1000 2000 3000
3000 2500 1500
1500 1200 1800
Case 1: 2000
Case 2: 2500
Case 3: 1500

Thought Process

Store the three numbers into a vector or array, then proceed to sort them. Finally, output the data at the first position (the middle value).

Sample Code-ZeroJudge D659: Cost Cutting

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    for (int i = 0; i<T; i++)
    {
        vector<int>num;
        for (int j = 0; j<3; j++)
        {
            int tmp;
            cin >> tmp;
            num.push_back(tmp);
        }
        sort(num.begin(), num.end());
        cout << "Case " << i+1 << ": " << num[1] << "\n";
    }
}

//ZeroJudge D659
//Dr. SeanXD

Comments