zoukankan      html  css  js  c++  java
  • Codeforces Round #250 (Div. 2) A. The Child and Homework

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

    #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;
    
    }
  • 相关阅读:
    Vue-dialog(弹框组件)
    Vue封装select下拉组件
    RAID总结
    消息队列
    存储
    算法开始
    硬件杂记
    要看的
    关于kernel的疑问,不解
    杂技
  • 原文地址:https://www.cnblogs.com/xiongqiangcs/p/3779653.html
Copyright © 2011-2022 走看看