-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem 4.cpp
More file actions
58 lines (54 loc) · 1.18 KB
/
Copy pathProblem 4.cpp
File metadata and controls
58 lines (54 loc) · 1.18 KB
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
#include<iostream>
#include<cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iomanip>
#include <locale>
#include <sstream>
using namespace std;
bool isPalin(string input);
string conString (double input);
int main(){
int greatVal = 0;
for (int x = 1; x < 1000; x++){
for (int y = 1; y < 1000; y++){
if (isPalin(conString(x*y)) && (x*y) > greatVal){
greatVal = x*y;
}
}
}
cout << greatVal;
system("PAUSE");
}
bool isPalin(string input){
int length;
if (input == ""){
return(false);
}
for (length = 0; input[length] != '\0'; length++);
if (length <= 0) {
return(false);
} else if (length == 1) {
return(true);
} else if (length % 2 == 0){
for (int i = 0; i < (length/2) ; i++){
if (input[i] != input[length - (i + 1)]){
return(false);
}
}
return(true);
} else {
for (int i = 0; i < ((length - 1) /2); i++){
if (input[i] != input[length - (i + 1)]){
return(false);
}
}
return(true);
}
}
string conString (double input){
ostringstream convert;
convert << input;
return (convert.str());
}