`
阿尔萨斯
  • 浏览: 4142040 次
社区版块
存档分类
最新评论

Codeforces 437A The Child and Homework(水题)

 
阅读更多

题目链接: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;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics