forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOJ1007(AC).cpp
64 lines (57 loc) · 859 Bytes
/
POJ1007(AC).cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
int main()
{
int n;
int m;
char *a;
vector<string> str;
int *inverCount;
int inver;
int i;
int j;
int k;
int temp;
string t;
cin>>n>>m;
a = new char[n+1];
inverCount = new int[m];
for(i = 0; i < m; i++)
{
cin>>a;
str.push_back(a);
inver = 0;
for (j = 0; j < n; j++)
{
for (k = j + 1; k < n; k++)
{
if (a[j] > a[k])
inver++;
}
}
inverCount[i] = inver;
}
for(i = 0; i <= m - 2; i++)
{
for(j = m - 1; j >= i + 1; j--)
{
if(inverCount[j] < inverCount[j - 1])
{
temp = inverCount[j];
inverCount[j] = inverCount[j - 1];
inverCount[j - 1] = temp;
t = str[j];
str[j] = str[j -1];
str[j - 1] = t;
}
}
}
for (i = 0; i < m; i++)
{
cout << str[i] << endl;
}
return 0;
}