Submission

Status:

PPTTT-TTTT

Subtask/Task Score:

20/100

Score: 20

User: Karatat007

Problemset: Strobogrammatic Numbers

Language: cpp

Time: 1.094 second

Submitted On: 2026-10-10 09:41:21

#include <bits/stdc++.h>
using namespace std;

bool isstrobogrammatic(int n){
    bool strobogrammatic = true;
    string s;
    s = to_string(n);
    for(int i = 0;i < (s.size()+1)/2;++i){
        if(!strobogrammatic) break;
        if(s[i] == '7' or (s[i] >= '2' and s[i] <= '5')) strobogrammatic = false;
        else{
            if(s[i] == '1' and s[s.size() - i - 1] != '1') strobogrammatic = false;
            if(s[i] == '0' and s[s.size() - i - 1] != '0') strobogrammatic = false;
            if(s[i] == '8' and s[s.size() - i - 1] != '8') strobogrammatic = false;
            if(s[i] == '6' and s[s.size() - i - 1] != '9') strobogrammatic = false;
            if(s[i] == '9' and s[s.size() - i - 1] != '6') strobogrammatic = false;
        }
    }
    return strobogrammatic;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int low,high;
    cin >> low >> high;
    int count = 0;
    for(int i = low;i <= high;++i){
        if(isstrobogrammatic(i)) count++;
    }
    cout << count;
}