1830. 【Normal】米斯琪的夜雀食堂之营业结束算大米

#include <bits/stdc++.h> using namespace std; double PI = 3.1415926; int main(void) { int N; cin >> N; int Price[21] = { 0 }; for (int i = 0; i < N; i++) { cin >> Price[i];//输入每个菜品的价格 } int SellCount = 0;//销售数量统计 int Money = 0;//总销售额 int Dish[21] = { 0 };//每道菜品的出菜量 int Sell[21] = { 0 };//销售额统计 int Best; int Bad; int temp = 0;//保存单个菜品的销售额 int flag = 0; for(int k = 0; k < N; k++) { cin >> Dish[k]; SellCount += Dish[k];//出售数量 temp= Dish[k] * Price[k];//单个菜品的销售额 Money += temp;//计算总销售额 Sell[k] = temp; if (flag == 0)//将第一个菜品的销售额赋值给Best和Bad,方便比较,取得最大最小值 { Best = Dish[k] * Price[k]; Bad = Dish[k] * Price[k]; flag = 1; } if (Best < temp) { Best = temp; } if (Bad > temp) { Bad = temp; } } cout << Money << " " << SellCount << endl; //经过完上面的循环,已经找到了营业额最大最小值,此时还得判断是否存在多个 for (int i = 0; i < N; i++) { if (Best == Sell[i]) { cout << i << " "; } } cout << endl; for (int i = 0; i < N; i++) { if (Bad == Sell[i]) { cout << i << " "; } } cout << endl; return 0; }