Always feel that csdn notifications and private messages often look strange, the homepage tips have a private message, open but can not see, and sometimes turn back a few pages to see.
This is the case again today. So study, just start still did not find the law, until see "3 days Ago" message in the last "3 years ago" news, suddenly understand, then turned to the beginning, found "11 months ago" ranked first, followed by "1 years ago", and then "2 years ago", Then it is "3 years ago", then "3 days Ago", then "4 days ago", until "26 days ago", followed by "3 months ago", and then "4 months ago".
I was the first picture of unrestrained
I am the second picture of reason
It's very sensitive to the algorithm. I would like to know what kind of sorting algorithm this is? Is it difficult to sort by time string? So to "11 months ago", "2 years Ago", "3 years Ago", "3 months ago", "3 days Ago" and "4 days ago" several strings are sorted in ascending order of the string:
voidPrintConst STD::string& E) {STD::cout<< e <<STD:: Endl;}intMainintargcChar* argv[]) {Char*ssts[] = {"11 months ago","3 years ago","2 years ago","3 months ago","3 days Ago","4 days Ago"};STD:: Vector<std::string>Cpths (ssts, SSTs +6);STD:: Sort (Cpths.begin (), Cpths.end (),STD::less<STD::string> ());STD:: For_each (Cpths.begin (), Cpths.end (), print);return 0;} I'm a sexy source.
The result after sorting is:
"11 months ago"
"2 years ago"
"3 months ago"
"3 years ago"
"3 days Ago"
"4 days Ago"
What do you think about that?
I studied the sort of csdn private messages, and I was drunk.