题解:P16436 [XJTUPC 2026] 幽灵×毕业

· · 题解

题目传送门 & 更好的阅读体验

题目大意

给定六个整数 x_1,x_2,\cdots,x_6 \in \{0,1\},若其中有至少三个 0 和至少三个 1,则输出 Congratulations on graduation!,否则输出 Songfes in Japan...

解题思路

很显然这是一道语法基础题,我们分别计算 01 的数量,并在最后进行判断和输出即可,上代码。

:::success[AC 代码(赛时)]{open}

#include <bits/stdc++.h>
#define Code using
#define By namespace
#define Alexlulu std;

Code By Alexlulu

int x, cnt1, cnt2;
// cnt1 计算 1 的数量
// cnt2 计算 0 的数量

int main()
{
    cin.tie(0) -> sync_with_stdio(false);
    for (int i = 1; i <= 6; i++)
    {
        cin >> x; // 输入
        cnt1 += x;
        // x=1 时等价于 cnt1 += 1;
        // x=0 时等价于 cnt1 += 0;
        cnt2 += (!x);
        // (!x) 等价于 (x == 0):
        // 在 x=0 时返回 true (1)
        // 在 x≠0 时返回 false(0)
    }
    if (cnt1 >= 3 && cnt2 >= 3) puts("Congratulations on graduation!"); // 满足条件时输出
    else puts("Songfes in Japan..."); // 不满足条件时输出
    return 0; // 不要抄袭
}

:::

蒟蒻第 7 篇题解,求过求赞 qwq