Codeforces 437A The Child and Homework(水题)

来源:互联网 发布:cf手游刷枪软件不封号 编辑:程序博客网 时间:2024/06/01 07:15

题目链接:Codeforces 437A The Child and Homework

题目大意:有个小孩在考试,碰到一道题目不会做,所以用猜的,三长一短选最短,三短一长选最长,否则选C。就是看选项中是否有一个选项的长度是否小于其他三个选项长度的一半或者大于其他长度的两倍。如果有多个或是没有,就选择C。

解题思路:题目懂了就是水题了,不解释。

#include <cstdio>#include <cstring>int l[4];char str[105];bool judgeLonger (int x) {    for (int i = 0; i < 4; i++) {        if (i == x)            continue;        if (l[i] * 2 > l[x])            return false;    }    return true;}bool judgeShorter(int x) {    for (int i = 0; i < 4; i++) {        if (i == x)            continue;        if (l[i] < l[x] * 2)            return false;    }    return true;}int main () {    for (int i = 0; i < 4; i++) {        scanf("%s", str);        l[str[0]-'A'] = strlen(str+2);    }    int cnt = 0, ans = 0;    for (int i = 0; i < 4; i++) {        if (judgeLonger(i) || judgeShorter(i)) {            cnt++;            ans = i;        }    }    if (cnt == 1)        printf("%c\n", ans + 'A');    else        printf("C\n");    return 0;}
0 0
原创粉丝点击