Parcourir la source

发工资--贪心算法

jal il y a 5 ans
Parent
commit
c9ec968467
1 fichiers modifiés avec 23 ajouts et 0 suppressions
  1. 23 0
      C.cpp

+ 23 - 0
C.cpp

@@ -0,0 +1,23 @@
+#include<bits/stdc++.h>
+using namespace std;
+int main(){
+	vector<int>v={100,50,20,10,5,2,1};
+	int n;
+	while(cin >> n && n){
+	int sum = 0;
+	for(int i = 1; i <= n; i++){
+		int x;
+		cin >> x;
+		int t = 0;
+		for(int j = 0; j < v.size(); j++){
+			while(x >= v[j]){
+				x -= v[j];
+				t++;
+			}
+		}
+		sum += t;
+	}
+	cout << sum << endl;
+}
+return 0;
+}