为什么过不了?求助
查看原帖
为什么过不了?求助
1191598
theocode楼主2023/12/6 17:22
#include<iostream>
#include<iomanip>
using namespace std;
double coin[105][5];
int main() {
	double n,m,sum_value=0;
	cin >> n>>m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 2; j++) {
			cin >>coin[i][j] ;
		}
		coin[i][2] = coin[i][1] / coin[i][0];
	}
	for (int x = 0; x<n; x++) {
		int max = 0, point = 0;
		for (int w = 0; w < n; w++) {
			if (max < coin[w][2]) {
				max = coin[w][2];
				point = w;
			}
		}
		if (m >= coin[point][0]) {
			sum_value += coin[point][1];
			m -= coin[point][0];
			coin[point][2] = 0;
		}
		else {
			sum_value += coin[point][1] * (m/coin[point][0]);
			break;
		}
	}
	cout <<fixed<< setprecision(2) << sum_value;
	return 0;
}
2023/12/6 17:22
加载中...