算法也太难了吧


私信TA

用户名:17306366773

访问量:11366

签 名:

我口袋只剩玫瑰一片,此行又山高路远

等  级
排  名 419
经  验 4785
参赛次数 0
文章发表 41
年  龄 0
在职情况 学生
学  校 天津工业大学
专  业

  自我简介:

TA的其他文章

修剪灌木(C++)
浏览:507
X进制减法(C++)
浏览:1237
积木画(c++)
浏览:1075


参考代码:

#include using namespace std;
struct nodea{ 
    int id,w;  
}
a[100005];struct nodeb{ 
    int id,w;
}b[100005];
bool cmp1(nodea a,nodea b){    
    if(a.w != b.w) return a.w < b.w;    
    else return a.id < b.id;           
}
bool cmp2(nodeb a,nodeb b){           
    if(a.w != b.w) return a.w > b.w;    
    else return a.id < b.id;
}
int main(){    
    int n1,n2;
    cin >> n1 >> n2;    
    for(int i = 1; i > a[i].w,  a[i].id = i;    
    for(int i = 1; i > b[i].w,  b[i].id = i;    
    sort(a+1,a+n1+1,cmp1);    
    sort(b+1,b+n2+1,cmp2);
    string s;
    cin >> s;    
    int idx1 = 1,idx2 = 1;    
    for(int i=0;i<s.length();i++){        
        if(s[i] == '1'){
            cout << "B";
            cout << b[idx1++].id << endl;
        } else{
            cout << "A";
            cout << a[idx2++].id << endl;
        }
    }
    cout << "E" << endl;    
    return 0;
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区