-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1507. Reformat Date.cpp
More file actions
49 lines (37 loc) · 1.07 KB
/
1507. Reformat Date.cpp
File metadata and controls
49 lines (37 loc) · 1.07 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
/*
problem link :https://leetcode.com/problems/reformat-date/
problem name: 1507. Reformat Date
Status: Accepted.
Author : Mohand sakr.
** *
class Solution {
public:
string reformatDate(string date) {
string answer="";
map<string,string> month;
month["Jan"]="01";
month["Feb"]="02";
month["Mar"]="03";
month["Apr"]="04";
month["May"]="05";
month["Jun"]="06";
month["Jul"]="07";
month["Aug"]="08";
month["Sep"]="09";
month["Oct"]="10";
month["Nov"]="11";
month["Dec"]="12";
string day=date.substr(0,date.find(" "));
day=(day.substr(0,day.length()-2));
if(day.length()<2){
day="0"+day;
}
date.erase(0,date.find(" ")+1);
string months=month[date.substr(0,date.find(" "))];
date.erase(0,date.find(" ")+1);
answer+=date+"-";
answer+=months+"-";
answer+=day;
return answer;
}
};