Submission

Status:

PP--------

Subtask/Task Score:

20/100

Score: 20

User: letdown

Problemset: Strobogrammatic Numbers

Language: cpp

Time: 0.064 second

Submitted On: 2025-10-12 18:20:47

#include <iostream>
#include <vector>

using namespace std;
vector<string> createStrobo(int len) {
    vector<string> strobo = {"0", "1", "8", "69", "96", "88"};
    int l = 0, i = 0;
    while(1) {
        string mid = strobo[i];
        if (mid.length() >= len) break;
        if (mid.length() < l) strobo.push_back("0" + mid + "0");
        strobo.push_back("1" + mid + "1");
        strobo.push_back("6" + mid + "9");
        strobo.push_back("8" + mid + "8");
        strobo.push_back("9" + mid + "6");
        l+=2;
        i++;
    }
    return strobo;
}

int main() {
    long long low, high, ans=0;
    cin >> low >> high;

    int l = to_string(high).length();
    vector<string> strobo = createStrobo(l);
    for (auto s : strobo) {
        // cout << s << " ";
        if (s == "" || s[0] == '0') continue;
        long long sint = stoll(s);
        if (sint >= low && sint <= high) ans++;
    }
    cout << ans;
    // vector<string> strobo = createStrobo(15);
    // for (auto s : strobo) cout << s << " ";
}