编辑代码

#include <iostream>
using namespace std;


int prio_map_to_weight(int prio_min, int prio_max, int weight_beg, int weight_end, int prio)
{
         int weight;
         weight =  weight_beg - (prio - prio_min)*(weight_beg - weight_end +1)/(prio_max - prio_min + 1);
         return weight;
}


int main() {
    //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
	cout << "Hello world!    - cpp.jsrun.net." << endl;

int prio_list[2][9] = {{139, 129, 119, 109, 99, 89, 79, 49, -1}, {1, 6, 11, 16, 21, 26, 31, 36, 41}};
int out=0;


        int prio = 0;

        int prio_min = 0;
        int prio_max = 0;
        int weight_beg= 0;
        int weight_end = 0;
        int PRIO_RT_MAX = sizeof(prio_list[0])/sizeof(prio_list[0][0]);
        cout<<PRIO_RT_MAX<<endl;
    for (prio =100; prio < 140; prio ++) {
        for (int i = 0; i < PRIO_RT_MAX; i++) {
                if (prio == prio_list[0][i]) {
                        out = prio_list[1][i];
                        cout <<"prio: "<< prio << "    weight: "<<out<<endl;
                        break; 
                } else if (prio > prio_list[0][i]) {
                        prio_min = prio_list[0][i] + 1;
                        prio_max = prio_list[0][i-1];
                        weight_beg = prio_list[1][i] - 1;
                        weight_end = prio_list[1][i-1];
                        break;
                }
        }

        out = prio_map_to_weight(prio_min, prio_max, weight_beg, weight_end, prio);
        //cout<<prio_min<<"    "<<prio_max<<"    "<<weight_beg<<"    "<<weight_end<<endl;
        cout << "test----prio: " << prio << "    weight: "<< out<<endl;
}   


	return 0;
}