Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator