Submission
Status:
PPTTT-TTTT
Score: 20
User: 1669
Problemset: Strobogrammatic Numbers
Language: cpp
Time: 1.093 second
Submitted On: 2024-12-09 14:35:22
#include <bits/stdc++.h>
using namespace std;
bool isStrobogrammatic(string num) {
unordered_map<char, char> strobogrammaticMap = {
{'0', '0'}, {'1', '1'}, {'6', '9'}, {'8', '8'}, {'9', '6'}
};
int left = 0, right = num.size() - 1;
while (left <= right) {
if (strobogrammaticMap.find(num[left]) == strobogrammaticMap.end() ||
strobogrammaticMap[num[left]] != num[right]) {
return false;
}
left++;
right--;
}
return true;
}
int countStrobogrammatic(int a, int b) {
int count = 0;
for (int i = a; i <= b; i++) {
if (isStrobogrammatic(to_string(i))) {
count++;
}
}
return count;
}
int main() {
int a, b;
cin >> a >> b;
int result = countStrobogrammatic(a, b);
cout << result << endl;
return 0;
}
//code by chat gpt