月赛第一题求助
  • 板块学术版
  • 楼主lzy20091001
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/12/24 19:50
  • 上次更新2023/12/24 21:47:10
查看原帖
月赛第一题求助
932039
lzy20091001楼主2023/12/24 19:50

WA 了一个点,百思不得其解

#include <iostream>

bool check(int x)
{
    while (x % 10 == 9)
        x /= 10;
    return x % 10 == 2;
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    long long l, r;

    std::cin >> l >> r;

    if (r - l >= 10)
        std::cout << 2 << "\n";
    else
    {
        for (long long i = l; i < r; i++)
            if (i % 10 == 2 || check(i))
            {
                std::cout << 2 << "\n";
                return 0;
            }
        std::cout << 1 << "\n";
    }
    return 0;
}

2023/12/24 19:50
加载中...