My issue
help me
My code
#include <iostream>
#include <string>
using namespace std;
bool isLovely(const string &num) {
string mirrored = ""; // String to hold the mirrored version
for (char digit : num) {
switch (digit) {
case '0':
case '1':
case '8':
mirrored += digit; // These digits remain the same
break;
case '6':
mirrored += '9'; // 6 becomes 9
break;
case '9':
mirrored += '6'; // 9 becomes 6
break;
default:
return false; // Any other digit means it's not lovely
}
}
// Compare the mirrored version with the original number
return mirrored == string(num.rbegin(), num.rend());
}
int main() {
int T;
cin >> T; // Number of test cases
while (T--) {
string N;
cin >> N; // Read the number as a string
cout << (isLovely(N) ? "LOVELY" : "NOT LOVELY") << endl;
}
return 0;
}
Problem Link: Lovely Numbers Practice Coding Problem