Studied the sort of csdn private messages, and I was drunk.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.