Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 第一次 1AC

Posted by 264314 at 2018-10-06 20:59:26 on Problem 1007
```# include <iostream>
# include <string>

using namespace std;

struct sort
{
int num,pre;
};

int GetRevNum(string s);
sort* SortStr(string s[],int n);

int main()
{
int len,n;
cin>>len>>n;
string *s = new string[n];
for(int i = 0;i<n;++i)
cin>>s[i];
sort* a = SortStr(s,n);
for(int i = 0;i<n;++i)
{
cout<<s[a[i].pre]<<endl;
}
return 0;
}

int GetRevNum(string s)
{
int count = 0;
for(int i = 0;i<s.length()-1;++i)
{
for(int j = i+1;j<s.length();++j)
if(s[i] > s[j])
count++;
}
return count;
}

sort* SortStr(string s[],int n)
{
sort *a = (sort*)malloc(sizeof(sort)*n);
for(int i = 0;i<n;++i)
{
a[i].pre = i;
a[i].num = GetRevNum(s[i]);
}
for(int i = 0;i<n-1;++i)
{
int index = i;
int min = a[i].num;
for(int j = i+1;j<n;++j)
{
if(a[j].num < min)
{
index = j;
min = a[j].num;
}
}
if(index != i)
{
sort t = a[i];
a[i] = a[index];
a[index] = t;
}
}
return a;
}```

Followed by: