-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler112.cpp
56 lines (52 loc) · 878 Bytes
/
euler112.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
// bouncy. 112
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
bool Inc(int x)
{
std::ostringstream ss;
ss << x;
std::string s = ss.str();
int l = s.length();
bool sofar = true;
for (int x = 0; x < l - 1 && sofar; x ++)
{
if (s[x] > s[x+1])
sofar = false;
}
return sofar;
}
bool Dec(int x)
{
std::ostringstream ss;
ss << x;
std::string s = ss.str();
int l = s.length();
bool sofar = true;
for (int x = 0; x < l - 1 && sofar; x ++)
{
if (s[x] < s[x+1])
sofar = false;
}
return sofar;
}
int main()
{
int curr_bouncy_no = 0;
bool sofar = false;
int total = 99;
while (!sofar)
{
total += 1;
if (!Inc(total) && !Dec(total))
{
curr_bouncy_no += 1;
}
if (100*curr_bouncy_no == 99*total)
{
sofar = true;
}
}
std::cout << total << std::endl;
}