Since the Wu space on the Grand holy, Monkey Monkey Sun on the Huaguoshan can also taste all kinds of heavenly fruit God wine, so monkey Monkey Sun's physique also got a very good improvement, height age also got a great increase. One day Goku is OK, to lead his monkey monkey grandchildren go out to travel, in order to maintain the image of Huaguoshan, an elder monkey suggested that the monkeys are ranked by the height of a team.
The monkeys are so anxious to start, how to quickly arrange the team so that the magic of the Great holy headache unceasingly. Now ask you to be the king of the King of the King of Goku to help him sort.
-
-
Input
-
-
the first line of data consists of an integer T (0<t<=50), which represents a T-group test data;
The next group of data in the first row has two integers, n,m (0<n<=1000000), respectively, representing the number of monkeys and the maximum height (height in centimeters, assuming that all monkeys are not more than 1 meters tall). Second act n the height of a monkey, separated by a space.
1 2 3 4 51 2 3 4 5 8 8 9 9 10
Problem Solving Ideas:
Careful observation of the topic, you will find that the topic gave a maximum height m, if not to the data this problem can also be done, why to give this data?
The answer must be that this data is useful, which is the critical point of the array tag. We can use the array subscript to mark height, array values to store the number of monkeys corresponding to the height, and then the other is to pay attention to how to output the required format, I believe everyone will this format!
Code
#include <stdio.h> #include <string.h>int high[110];int main () {int t;int n,m;int i,j,k;int now;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n,&m), memset (high,0,sizeof), and for (i=0;i<n;i++) {scanf ("%d", &now); high[now]++;} for (i=0;i<=m;i++)//To add m to the range {while (High[i]) {printf ("%d", I), High[i]--;if (n!=0) printf (""); n--;}} printf ("\ n");} return 0;}