-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day_047.cpp
51 lines (40 loc) · 839 Bytes
/
Day_047.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
*Problem Statement: a Program to find longest palindrome in an array.
*Author: Kunal Kathpal (https://github.com/kunal-2002)
*/
#include <bits/stdc++.h>
using namespace std;
bool ispalindrome(int num){
int rev_num = 0, temp = num;
while(temp>0){
rev_num = rev_num*10 + temp%10;
temp = temp/10;
}
if(rev_num == num)
return true;
else
return false;
}
int main(){
cout<<"Enter number of test cases:\t";
int T;
cin>>T;
while(T--){
int size;
cout<<"Enter size of array:\n";
cin>>size;
int arr[size];
cout<<"Enter the elements:\n";
for(int i=0;i<size;i++)
cin>>arr[i];
int res = INT_MIN;
for(int i=0; i<size;i++){
if(ispalindrome(arr[i]) && res<arr[i])
res = arr[i];
}
if(res == INT_MIN)
res = -1;
cout<<"Longest palindrome: "<<res<<endl;
}
return 0;
}