Wage Scheduling

Title Description

A company by the N employees, given all wages inventory, and financial officers to arrange the wages of employees in a particular order, his order of decreasing frequency of wages, that is given a list of all the frequency higher wages will be less in frequency low wages appear before. If the same number of employees have the same salary, will be arranged in the order given in the list of the first occurrence of the wages.

Write an algorithm to help arrange finance staff wages order.

Entry

The input function / method includes two parameters -
NUM, an integer representing the number of employees.
salaries, a positive integer list, N wage employees.

Export

It returns a positive integer list, sorted by frequency of employee wages.

Restrictions

1<=num<=10^5
1<=salaries[i]<=10^9
0<=i<=num

Code

#include <iostream>
#include <vector>
#include<algorithm>

using namespace std;

int main() {
    int workerNum = 19;
    //cin >> workerNum;
    vector<int> salaries = { 1,2,4,3,3,3,4,2,5,5,5,5,6,6,6,7,8,9,10 };
    //for (int i = 0; i < workerNum; i++) {
    //  int ss;
    //  cin >> ss;
    //  salaries.push_back(ss);
    //}
    vector<vector<int> > SalariesCount(workerNum, vector<int>(2));
    int count = 0;
    for (int i = 0; i < workerNum; i++) {
        bool flag = false;
        if (i == 0) {
            SalariesCount[count][0] = salaries[i];
            SalariesCount[count][1] = 1;
        }
        else {
            for (int j = 0; j < SalariesCount.size(); j++) {
                if (salaries[i] == SalariesCount[j][0])
                {
                    SalariesCount[j][1] = SalariesCount[j][1] + 1;
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                count = count + 1;
                SalariesCount[count][0] = salaries[i];
                SalariesCount[count][1] = 1;
            }
        }   
    }
    //使用冒泡排序进行排序
    for (int k = 0; k < SalariesCount.size() - 1; k++) {
        for (int m = 0; m < SalariesCount.size() - k - 1; m++) {
            if (SalariesCount[m][1] < SalariesCount[m + 1][1]) {
                vector<int> temp;
                temp = SalariesCount[m + 1];
                SalariesCount[m + 1] = SalariesCount[m];
                SalariesCount[m] = temp;
            }
        }
    }
    for (int l = 0; l < SalariesCount.size(); l++) {
        if (SalariesCount[l][1] > 0) {
            for (int n = 1; n <= SalariesCount[l][1]; n++) {
                cout << SalariesCount[l][0] << endl;
            }
        }
    }
    return 0;
}

Output

Guess you like

Origin www.cnblogs.com/hellovan/p/11409643.html