My issue
Please give a optimize solution of it. So that everyone can get easily understand. The Solution you have have provided is hardly to understand.
My code
#include <bits/stdc++.h>
using namespace std;
bool checkPalindrome(int x){
string s = to_string(x);
int n = s.length();
for(int i=0; i<n/2; i++){
if(s[i]!=s[n-i-1]){
return false;
}
}
return true;
}
int main() {
int t; cin>>t;
while(t--){
int n; cin>>n;
int arr[n];
int count = 0;
for(int i=0; i<n; i++){
cin>>arr[i];
}
for(int i=0; i<n; i++){
for(int j=i; j<n; j++){
int ans = arr[i]^arr[j];
if(checkPalindrome(ans)){
count++;
}
}
}
cout<<count<<endl;
}
return 0;
}
Learning course: 2000 to 2500 difficulty problems
Problem Link: NASA Practice Problem in - CodeChef