01 String Sort

Source: Internet
Author: User

Title Description:

Reference code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #defineM 3006 using namespacestd;7 CharA[m][m];8 voidFunintJintk)9 {Ten     CharTemp[m]; One strcpy (Temp,a[j]); A strcpy (A[j],a[k]); - strcpy (a[k],temp); - } the intMain () - { -     inti =0; -      while(Cin >>A[i]) +i + +; -      for(intj =0; J < I; J + +) +     { A          for(intK = j +1; K < I; K + +) at         { -             if(Strlen (a[j]) > strlen (a[k]))//Sort by string length - Fun (j,k); -             Else if(Strlen (a[j]) = =strlen (A[k])) -             { -                 intSUMJ =0, SUMK =0; in                  for(intt =0; T < strlen (a[j]); T + +)//ask for the number of 1 -SUMJ = SUMJ + a[j][t]-'0'; to                  for(intt =0; T < strlen (a[k]); T + +)//ask for the number of 1 +SUMK = Sumk + a[k][t]-'0'; -                 if(Sumj > Sumk)//Sort by the number of one the Fun (j,k); *                 Else if(SUMJ = =sumk) $                     if(strcmp (a[j],a[k]) >0)//ASCII sortingPanax Notoginseng Fun (j,k); -             } the         } +     } A      for(intj =0; J < I; J + +) thecout << A[j] <<Endl; +     return 0; -}

01 String Sort

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.