首页 > 其他 > 详细

Codeforces Round #250 (Div. 2) A. The Child and Homework

时间:2014-06-10 19:30:33      阅读:368      评论:0      收藏:0      [点我收藏+]

注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C。

bubuko.com,布布扣
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct Answer{
    char item;
    int length;
    Answer(char item_ = A, int length_ = 0):item(item_),length(length_){}
    bool operator<(const Answer& a) const{
        return length < a.length;
    }
};

int main(){
    vector<Answer> ans;
    for(int i = 0 ; i < 4; ++ i){
        string str;
        cin >> str;
        ans.push_back(Answer(str[0],str.length()-2));
    }
    sort(ans.begin(),ans.end());
    int index = 1;
    char correct = C;
    for(index = 1;index < 4; ++ index){
        if(ans[index].length < 2*ans[0].length) break;
    }
    if(index>=4) correct = ans[0].item;
    for(index = 0; index < 3; ++ index){
        if(2*ans[index].length >ans[3].length) break;
    }
    if(index >= 3) {
        if(correct!=C) correct = C;
        else correct = ans[3].item;
    }
    cout<<correct<<endl;

}
bubuko.com,布布扣

 

 

Codeforces Round #250 (Div. 2) A. The Child and Homework,布布扣,bubuko.com

Codeforces Round #250 (Div. 2) A. The Child and Homework

原文:http://www.cnblogs.com/xiongqiangcs/p/3779653.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!