help!
查看原帖
help!
1230506
OIer_bcx_楼主2023/12/24 21:00
#include <iostream>
using namespace std;

bool hasLuckyNumber(unsigned long long n) {
    string numStr = to_string(n);
    return (numStr[0] == '2'||numStr[numStr.size()-1]=='2');
}

int main() {
    unsigned long long l, r;
    cin >> l >> r;
    bool foundLuckyNumber = false;
    for (unsigned long long i = l; i <= r; ++i) {
        if (hasLuckyNumber(i)) {
            foundLuckyNumber = true;
            break;
        }
    }
    if (foundLuckyNumber) {
        cout << 2 << endl;
    } else {
        cout << 1 << endl;
    }
    return 0;
}
2023/12/24 21:00
加载中...