(HDU) 1040--as Easy as a+b (as simple as a+b)

Source: Internet
Author: User

Title Link: http://vjudge.net/problem/HDU-1040

Idea: Sorting algorithms for water problems. Note the output format, with spaces between the numbers.

1#include <iostream>2#include <cstdio>3#include <cstring>4     using namespacestd;5 6     intMain ()7     {8         intn,num,i,j,temp;9         ints[1010];Tenscanf"%d",&n); One          while(n--) A         { -scanf"%d",&num); -              for(i=1; i<=num;i++) thescanf"%d",&s[i]); -              for(i=1; i<num;i++) -                  for(j=i+1; j<=num;j++) -             { +                 if(s[i]>S[j]) -                 { +temp=S[i]; As[i]=S[j]; ats[j]=temp; -                 } -             } -              for(i=1; i<num;i++) -printf"%d", S[i]); -printf"%d\n", S[i]); in         } -         return 0; to}
View Code

Here's how to use the sort function directly (lazy ... )

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5     using namespacestd;6 7     intMain ()8     {9         intn,num,i;Ten         ints[1010]; Onescanf"%d",&n); A          while(n--) -         { -scanf"%d",&num); the              for(i=0; i<num;i++) -scanf"%d",&s[i]); -Sort (s,s+num); -              for(i=0; i<num-1; i++) +printf"%d", S[i]); -printf"%d\n", S[i]); +         } A         return 0; at}
View Code

(HDU) 1040--as Easy as a+b (as simple as a+b)

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.