Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
第一次 1AC# 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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator