编辑代码

#include <iostream>
#include <string.h>

using namespace std;
int main() {
 string cgroup_list[6] = {"top-app", "foreground", "audio", "system-backgroud", "other", "backgroud"};

string cgroup_name = "backgroud";

        int CGROUP_WEIGHT = 30;
        int CGROUP_LEVEL = 6;
        int weight_level = CGROUP_WEIGHT/CGROUP_LEVEL;
        int cgroup_weight = CGROUP_WEIGHT;
        int other_weight = 0;
        int weight = 0;
        string ot ="other";

        for(int i = 0; i < 6; i++)
        {
                if (!strcmp(cgroup_name.c_str(), cgroup_list[i].c_str())) {
                       weight += cgroup_weight;
                       cout<< weight<<endl;
                        return 0;
                } else if (!strcmp(cgroup_list[i].c_str(),ot.c_str())) {
                        other_weight = cgroup_weight;
                }
                cgroup_weight -= weight_level;
        }
        weight += other_weight;

        cout<< weight<<endl;



	return 0;
}