-
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.67 KB
/
Copy pathProblem 4.cpp
File metadata and controls
58 lines (54 loc) · 1.67 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 <string>
/*
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SOLVED
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
/*
Aufgabe:
Eine palindromische Zahl liest sich in beide Richtungen gleich. Das größte aus dem Produkt
zweier zweistelliger Zahlen hergestellte Palindrom ist 9009 = 91 × 99.
Finden Sie das größte Palindrom, das aus dem Produkt zweier dreistelliger Zahlen besteht.
*/
long long umgekehrt(long zahl){
long tmp = 0;
long ret = 0;
while(zahl>0){
tmp = zahl/10;
ret = ret + zahl - tmp*10;
zahl/=10;
if(zahl>0){
ret *= 10;
}
}
return ret;
}
int main(){
int max_stellen;
int max_zahl{0};
std::cout << "Wie viele Stellen/Ziffern soll der hoechste Faktor haben: ";
std::cin >> max_stellen;
for(int i{0}; i<max_stellen; i++){
max_zahl += 9;
max_zahl *= 10;
}max_zahl += 9;
std::cout << "Maximale Zahl: " << max_zahl << '\n';
max_zahl /= 10;
long long max{0};
int fak1{0};
int fak2{0};
for(long long i{0}; i<=max_zahl; i++){
for(long long a{0}; a<=max_zahl; a++){
if(umgekehrt(a*i) == a*i){
if(a*i > max){
max = a*i;
fak1 = i;
fak2 = a;
}
}
}
}
std::cout << fak1 << '*' << fak2 << '=' << max << '\n';
return 0;
}