-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1306_Sorting_Algorithm.cpp
More file actions
38 lines (36 loc) · 935 Bytes
/
Copy path1306_Sorting_Algorithm.cpp
File metadata and controls
38 lines (36 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Problem#: 1306
// Submission#: 985229
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string array[100000];
bool cmp(string a,string b)
{
if(a.length() != b.length())return(a.length() < b.length());
else return(a < b);
}
void input(int n,int m)
{
for(int i = 0;i < n;i ++)
{
cin >> array[i];
}
sort(array,array + n,cmp);
for(int i = 0;i < n;i +=m)
{
if(i + m < n)cout << array[i] << " ";
else cout << array[i] << endl;
}
}
int main()
{
int n,m;
while(cin >> n >> m && !(n==0 && m == 0))
{
input(n,m);
}
}