forked from shruti170901/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reformat Date.cpp
30 lines (30 loc) · 883 Bytes
/
Reformat Date.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
class Solution {
public:
string reformatDate(string date) {
string word;
stringstream iss(date);
// date
iss >> word;
string dateo = word.substr(0, word.size()-2);
if(dateo.size()==1) dateo = "0" + dateo;
//month
iss >> word;
string month;
if(word=="Jan")month="01";
if(word=="Feb")month="02";
if(word=="Mar")month="03";
if(word=="Apr")month="04";
if(word=="May")month="05";
if(word=="Jun")month="06";
if(word=="Jul")month="07";
if(word=="Aug")month="08";
if(word=="Sep")month="09";
if(word=="Oct")month="10";
if(word=="Nov")month="11";
if(word=="Dec")month="12";
//year
iss >> word;
//cout << word << month << date;
return (word + "-" + month + "-" + dateo);
}
};