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)