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