编辑代码

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 4; // 职工的数量
const int M = 5; // 币值的数量

// 职工的工资
string actors[N] = {"王红","李言","赵林","张军"};
int salaries[N] = {2135, 1862, 2639, 2581};
// 各种币值的数量
int bills[M] = {0};
// 币值的面额
int values[M] = {100, 50, 10, 5, 1};

int main() {
  // 对工资进行排序
  sort(salaries, salaries + N, greater<int>());

  // 遍历每个职工
  for (int i = 0; i < N; i++) {
    // 当前职工的工资
    int salary = salaries[i];
    cout << actors[i] << "的工资:" << salary << "元" << endl;

    // 从大到小枚举各种币值
    for (int j = 0; j < M; j++) {
      // 当前币值的数量
      int count = salary / values[j];
      if (count > 0) {
        // 取出相应的币值
        salary -= count * values[j];
        //
bills[j] += count;
}
}
}

// 输出各种币值的数量
for (int i = 0; i < M;

i++) {
cout << values[i] << "元的数量:" << bills[i] << "张" << endl;
}

return 0;
}