Leetcode problem Reformat Date

I am new to leetcode,
And don’t know how to code in leetcode,
Please help

Is this query about Input/Output or you want solution ?

1 Like

I don’t know how to code in class

Consider you are writing in a function and instead of printing output use return.

2 Likes

You don’t have to. Your input will be the argument passed in the function and after processing it you have to return result.

1 Like

Please provide its solution in leetcode ide using class for reference
Please

I just copied it, I felt that coding it will be lengthy.

 string reformatDate(string date) {
        string res;
        if(date.length()==13)
            res=date.substr(9,4)+'-'+ret(date.substr(5,3))+'-'+date.substr(0,2);
        else
            res=date.substr(8,4)+'-'+ret(date.substr(4,3))+'-'+'0'+date.substr(0,1);
        return res;
    }
    string ret(string s){
        if(s=="Jan")    return "01";
        else if(s=="Feb")   return "02";
        else if(s=="Mar")   return "03";
        else if(s=="Apr")   return "04";
        else if(s=="May")   return "05";
        else if(s=="Jun")   return "06";
        else if(s=="Jul")   return "07";
        else if(s=="Aug")   return "08";
        else if(s=="Sep")   return "09";
        else if(s=="Oct")   return "10";
        else if(s=="Nov")   return "11";
        else        return "12";
    }

feel free to ask if you didn’t understand something in this code.

1 Like

Thanx,:blush:
Actually i am learning CP and new to it

Please like, if it helped you. :wink:

1 Like

Okay

1 Like