Easy Code With Concise Explanation C++
We divide the entire log into two vectors:-\n1) letter-logs, this is basically a pair of two strings, first containing the pair and the second containing the co
We divide the entire log into two vectors:-\n1) **letter-logs**, this is basically a pair of two strings, first containing the pair and the second containing the content\n2) **digit-logs**, this contains the digit-logs in their relative ordering.\n\nWe loop through the logs and take a string variable that will keep the identifier, we keep on adding chars till we reach a space, hence we get the identifier. Now we check the next character of the string, if it\'s a digit we put the entire log into digit-logs else we make a pair of <identifier, content> and push it into the letter-logs.\n\nAfter this we sort the letter-logs, with the help of a comparator function, i.e, if second pairs are equal we sort it by identifiers else we sort it by contents in the ascending order.\n\nAt last we make an answer vector and put the sorted letter-logs first then the digit-logs.\n\nHere\'s the code for better understanding:-\n```\nclass Solution {\npublic:\n    static bool comp(pair<string, string> a, pair<string, string> b) {\n        if(a.second == b.second) return a.first < b.first;\n        return a.second < b.second;\n    }\n    vector<string> reorderLogFiles(vector<string>& logs) {\n        vector< pair<string, string> > letter_logs;\n        vector<string> digit_logs;\n        vector<string> ans;\n        for(int i = 0; i < logs.size(); i++) {\n            string identifier = "";\n            for(int j = 0; j < logs[i].length(); j++) {\n                if(logs[i][j] == \' \') {\n                    if(logs[i][j+1] >= \'a\' && logs[i][j+1] <= \'z\') \n                        letter_logs.push_back({identifier, logs[i].substr(j+1, logs[i].size() - j + 1)});\n                    else\n                        digit_logs.push_back(logs[i]);\n                    break;\n                } else {\n                    identifier.push_back(logs[i][j]);\n                }\n            }\n        }\n        sort(letter_logs.begin(), letter_logs.end(), comp);\n        for(auto it: letter_logs) {\n            cout<<it.first + " " + it.second<<endl;\n            ans.push_back(it.first + " " + it.second);\n        }\n        for(auto it: digit_logs) {\n            cout<<it<<endl;\n            ans.push_back(it);\n        }\n        return ans;\n    }\n};\n```\n\nThanking you for stumbling on my content, do upvote :).\nHappy Coding \uD83D\uDE01.
['Array', 'C', 'Sorting']