测试用例执行计划(C++)

该篇文章描述了一个C++程序,通过定义一个名为T的结构体,包含id和value属性,用于表示具有不同权重的用例。程序读取特性数量和用例数量,计算每个用例的权重,然后根据权重和ID对用例进行排序并输出。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct T{
    string id;
    int value;
};//用例

bool compare_texts(const T& a,const T& b){
    if(a.value!=b.value){
        return a.value > b.value;
    }
    else{
        return a.id < b.id;
    }
}

int main() {
    int N,M;//n为特性数量,m为用例数量
    cin >> N >> M;
    vector<int> arr(N+1,0);
    for(int i = 1;i <= N;i++){
        cin >> arr[i];
    }
    cin.ignore();
    vector<T> texts;
    string s;
    for(int i = 1;i <= M;i++){
        string name = "T" + to_string(i);
        getline(cin, s);
        istringstream iss(s);
        int value = 0;
        int index;
        while(iss >> index){
            value += arr[index];//计算权重
        }
        texts.push_back({name, value});
    }
    //排序
    sort(texts.begin(),texts.end(),compare_texts);
    for(const auto& text : texts){
        cout << text.id << endl;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值