noip2010-Universal group Semi-finals simulation test-second question-Digital building blocks

Source: Internet
Author: User
Tags array sort

Title Description Description

Xiao Ming has a new type of building blocks, each building has a number, one day Xiao Ming whim, if all the building blocks
In a row, what is the maximum number of forms?
Your task is to read n number bricks to find out the maximum number that can be formed.
input/output format input/output Input Format:
The first line is an integer n (n≤1000), and the next n rows are a positive integer for each row. output Format:
The maximum number of integers that can be formed input and Output sample sample Input/output sample Test point # #

Input Sample:

3
13
131
343

Sample output:

34313131

Description Description

30% of the data, n≤l0, each number <10^3. 50% of the data, n≤l00. 100% of the data, n≤1000, each number <10^200.

Idea: This question at first glance, wow, is quite simple oh. My train of thought was: put these numbers in order each row, compare the size, but this method is very slow, dozens of burst.

But you can carefully observe the following rules: to make a number larger, first of all to make the first place as large as possible, and to make a number of digits as large as possible !

Great, this is the right idea, how to achieve it? At this point, it is very quick to think, eh, this is not a string comparison method?! Great, just use string to solve!

This problem evolved into a simple string two-bit array sort, great!

The code is as follows:

1#include <stdio.h>2#include <string.h>3 voidSortChararray[][1001],intN//sort function4 {5     Chartemp[202];6     inti,j,k;7      for(i=0; i<n-1; i++)8     {9k=i;Ten          for(j=i+1; j<n;j++) One             if(strcmp (Array[k],array[j]) <0)//big to small sort Ak=J; -         if(k!=i) -         { thestrcpy (Temp,array[i]);//String Exchange Order - strcpy (Array[i],array[k]); - strcpy (array[k],temp); -         } +     } - } + intMain () A { at     intn,i; -     Charstr[1001][1001]; -scanf"%d",&n); -      for(i=0; i<n;i++) -     { -scanf"%s", Str[i]);//Enter n string in     } -Sort (str,n);//sort the string of the input to      for(i=0; i<n;i++) +     { -printf"%s", Str[i]); the     } *printf"\ n");  $     return 0;Panax Notoginseng}

noip2010-Universal group Semi-finals simulation test-second question-Digital building blocks

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.