-
Notifications
You must be signed in to change notification settings - Fork 0
/
palguess.cpp
59 lines (49 loc) · 965 Bytes
/
palguess.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
52
53
54
55
56
57
58
59
//given a 4 digit number, guess a number that can be added
// either to the left of right of the number to make the number a pallendrome
#include<iostream>
#include<math.h>
using namespace std;
int pall(int n){
int n1 = n,sum = 0,rem;
while(n != 0){
rem = n%10;
sum = sum*10 + rem;
n/=10;
}
if(sum == n1)
return 1;
else
{
return 0;
}
return 0;
}
int main(){
int n,temp,i = 0;
cin >>n;
temp = n/10;
if(pall(temp)){
cout <<n%10;
return 0;
}
temp = n%1000;
cout << endl <<temp <<endl;
if(pall(temp)){
cout << n/1000;
return 0;
}
return 0;
/*LOGIC 2
int n,temp,temp2;
scanf("%d",&n);
temp = n/10;
temp2 = n%1000;
if(temp%10 == temp/100){
printf("%d",n%10);
return 0;
}
if(temp2%10 == temp2/100){
printf("%d",n/1000);
return 0;
} */
}