• cf437A The Child and Homework


    A. The Child and Homework
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: ABC and D. Each choice has a description, and the child should find out the only one that is correct.

    Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:

    • If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great.
    • If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).

    You are given a multiple-choice questions, can you predict child's choose?

    Input

    The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: BCDPlease note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.

    Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".

    Output

    Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).

    Sample test(s)
    input
    A.VFleaKing_is_the_author_of_this_problem
    B.Picks_is_the_author_of_this_problem
    C.Picking_is_the_author_of_this_problem
    D.Ftiasch_is_cute
    
    output
    D
    
    input
    A.ab
    B.abcde
    C.ab
    D.abc
    
    output
    C
    
    input
    A.c
    B.cc
    C.c
    D.c
    
    output
    B
    
    Note

    In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.

    In the second sample, no choice is great, so the child will choose the luckiest choice C.

    In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.

    模拟。只要判断是否有一个串长度比其他的长度两倍大或者比其他的长度的一半小。最后判断下有几个解即可。

     

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    struct sth
    {
       string s;int len,bh;
    }c[5];
    inline bool comp(sth a,sth b)
    {
       return a.len<b.len;
    }
    int gs;char Ans;
    int main()
    {
        for(int i=1;i<=4;i++) 
        {
           cin>>c[i].s;c[i].len=c[i].s.size()-2;
           c[i].bh=i;
        }
        sort(c+1,c+1+4,comp);
        if(c[1].len*2<=c[2].len) {gs++;Ans=c[1].bh-1+'A';}
        if(c[3].len*2<=c[4].len) {gs++;Ans=c[4].bh-1+'A';}
        if(gs==1) cout<<Ans<<endl;
        else cout<<"C"<<endl;
        return 0;
    }

     

    ——by zhber,转载请注明来源
  • 相关阅读:
    JavaScript AMD 模块加载器原理与实现
    nodejs之日志管理
    实时监测每秒上行下行流量,一款 iOS Today Widget 监测器Demo,还可以可以监测内存大小、存储空间等信息
    Swift 2.0基本语法
    【京东助手】滑稽东试用助手 V1.6.0
    我也秀秀windows phone版博客园客户端
    asp.net做的网站账号登陆后注销不管用了
    分享个自己做的CSDN刷下载积分软件
    推荐一个很好用的HTTP操作类
    新软件马上就要完成了,先发篇文章YY下
  • 原文地址:https://www.cnblogs.com/zhber/p/4036123.html
Copyright © 2020-2023  润新知