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;
    
    }
  • 相关阅读:
    关于c:fakepath的解决办法
    golang channel 源码剖析
    深入虚拟内存(Virtual Memory,VM)
    浅析 golang module
    浅析 golang interface 实现原理
    Golang channel实现
    LCS(最长公共字序列)实现
    Golang令牌桶-频率限制
    OpenGL(3)-三角形
    OpenGL(2)-窗口
  • 原文地址:https://www.cnblogs.com/xiongqiangcs/p/3779653.html
Copyright © 2011-2022 走看看