-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackNum.cpp
54 lines (51 loc) · 1.26 KB
/
backNum.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
//
// Created by kurum on 9/25/2022.
//
#include <iostream>
#include <string>
using namespace std;
int reverse(int num)
{
return num/10+num%10*10;
}
string to2(int num)
{
if (num<10)
return "0"+ to_string(num);
else
return to_string(num);
}
void backNum(string a)
{
auto centry = stoi(a.substr(0, 2));
auto reCen = reverse(centry);
auto year = stoi(a.substr(2, 2));
auto reYear = reverse(year);
auto mouth = stoi(a.substr(4, 2));
auto day = stoi(a.substr(6, 2));
if (reYear <= 12) {
if (mouth < reYear)//in same year
cout << a.substr(0, 4) << a.substr(3, 1) << a.substr(2, 1) << a.substr(1, 1) << a.substr(0, 1) << endl;
else if (mouth == reYear && day <= reCen)
cout << a.substr(0, 4) << a.substr(3, 1) << a.substr(2, 1) << a.substr(1, 1) << a.substr(0, 1) << endl;
else {
cout << a.substr(0, 2);
}
} else
{
if (reCen>31)// the gewei of centry number > 3
{
cout<<(centry/10)+1<<"001100"<<(centry/10)+1<<endl;
}else
{
cout<<centry<<(year/10)+1<<"00"<<(year/10)+1<<to2(reCen);
}
}
}
int main() {
cout << to2(reverse(20)) << endl;
string a;
cin >> a;
backNum(a);
return 0;
}