Xiao Zhang and his friends opened a supermarket, and ordered hundreds of kinds of goods to the supplier ready to shelves. Supermarket products need to be sorted and placed for easy management. Each category has a 8-digit code, of which the first three digits are Class I, the fourth and fifth digits are in English, the class two category, and the last three digits are numbers representing class three. Xiao Ming with the scanning machine input all the information of the goods, the requirements of the product according to barcode information sorted by order, for the product shelves to guide.
The rules are sorted by one, tertiary, and so on.
First: The first level by the number of positive sequence, from small to large,
Secondly: the second level in alphabetical order, from the back to the front,
Finally: The third level is numerically reversed, from large to small.
Compiler version : gcc 4.8.4
Please use standard input and output (stdin,stdout) ; Please write all the programs in a file, do not use disabled graphics, files, networks, system-related header files and operations, such as sys/stat.h, unistd.h, curl/curl.h, process.h
Time limit : 1S ( in languages other than C + +: 3 S) memory limit : 128M ( languages other than C + +: 640 M)
Input :
The data contains 1 lines: The first line: the encoding of all products, separated by commas (half-width)
Output :
List of sorted commodity barcodes, separated by commas (half-width)
Input Example :
004hi090,004hi091, 004hz091, 004ky026
Output Example :
004ky026,004hz091, 004hi091, 004hi090
1#include <iostream>2#include <stdio.h>3#include <string.h>4#include <string>5#include <stdlib.h>6#include <math.h>7#include <vector>8#include <stack>9 using namespacestd;Ten Onetypedefstructcate{ A stringA; - stringb; - }cate; the - BOOLCMP (Cate M, Cate N) - { - if(M.A <n.a) { + return true; -}Else if(M.A = =N.A) { + if(M.b >n.b) { A return true; at } - } - return false; - } - - intMain () in { - to stringstr; +Cate count[ -]; - getline (CIN, str); the inti =0; * intnum =0; $ while(1) {Panax Notoginseng if(Str[i] = =' /') Break; - if(Str[i] = =',') { thei++; + Continue; A } theCOUNT[NUM].A = Str.substr (i,3); +i + =3; -count[num].b = Str.substr (i,5); $i + =5; $num++; - } -Sort (count, Count +num, CMP); thecout<<"after sorting:"<<Endl; - for(i =0; i < num; i++) {Wuyicout<<count[i].a<<count[i].b<<Endl; the } - return 0; Wu}
Ali written test programming questions-Sort by product number (multilevel sort)