-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtidy.cpp
More file actions
47 lines (37 loc) · 851 Bytes
/
Copy pathtidy.cpp
File metadata and controls
47 lines (37 loc) · 851 Bytes
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
#include <iostream>
#include <cstdlib>
#include <limits>
using namespace std;
bool isTidy(unsigned long long n)
{
unsigned long long p = n%10;
n = n/10;
if (n == 0) return true;
while(n)
{
unsigned long long k = n%10;
if (k > p) return false;
n = n/10;
}
return true;
}
template <typename T>
void printlimits(const char* name)
{
cout << name << " " << numeric_limits<T>::max() << " " << numeric_limits<T>::min() << endl;
}
int main(int argc, char* argv[])
{
printlimits<int>("int");
printlimits<unsigned long long>("unsigned long long");
printlimits<long>("long");
printlimits<double>("double");
printlimits<float>("float");
unsigned long long n = atoi(argv[1]);
while (n)
{
if (isTidy(n)) break;
n = n-1;
}
cout << n << endl;
}