题目描述 小可今天接到了一个重要的任务,就是为可达的办公室采购一批新的设备(新电脑、新显示屏、新键鼠),这批设备给不同的老师的配置也不一样,采购单上标注了 � n 名老师对应的工号和各种设备的采购价格,现在小可想知道,本次采购为哪位老师花费最多,为哪位老师花费最少。 输入格式 输入第一行为一个正整数 � n 接下来 � n 行,每行四个整数,分别是教师工号,新电脑采购价格,新显示屏采购价格,新键鼠采购价格。 输出格式 输出两行 第一行为采购花费最多的老师的工号及花费数额 第二行为采购花费最少的老师的工号及花费数额 输入数据 1 5 30108 48358 1588 500 30408 32487 788 350 30111 68686 3856 799 30000 100000 10000 1000 31435 8999 1228 556 输出数据 1 30000 111000 31435 10783c++
时间: 2024-04-11 07:30:16 浏览: 21
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> teacherIds(n);
vector<int> computerPrices(n);
vector<int> screenPrices(n);
vector<int> mousePrices(n);
for (int i = 0; i < n; i++) {
cin >> teacherIds[i] >> computerPrices[i] >> screenPrices[i] >> mousePrices[i];
}
int maxTeacherId = teacherIds[0];
int minTeacherId = teacherIds[0];
int maxTotalPrice = computerPrices[0] + screenPrices[0] + mousePrices[0];
int minTotalPrice = computerPrices[0] + screenPrices[0] + mousePrices[0];
for (int i = 1; i < n; i++) {
int totalPrice = computerPrices[i] + screenPrices[i] + mousePrices[i];
if (totalPrice > maxTotalPrice) {
maxTotalPrice = totalPrice;
maxTeacherId = teacherIds[i];
}
if (totalPrice < minTotalPrice) {
minTotalPrice = totalPrice;
minTeacherId = teacherIds[i];
}
}
cout << maxTeacherId << " " << maxTotalPrice << endl;
cout << minTeacherId << " " << minTotalPrice << endl;
return 0;
}
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)