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

Re:multimap比较好吧O.O

Posted by 3Dnn at 2013-03-17 00:21:03 on Problem 1007
In Reply To:用map做的应该还满容易理解的 Posted by:foreverlin at 2008-11-13 08:54:11
#include<stdio.h>
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

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

int main()
{
	int l,n;
	char s[100];
	string str;
	multimap<int,string>DNA;
	multimap<int,string>::iterator it;
	while(scanf("%d%d",&l,&n)!=EOF)
	{
		while(n--)
		{
			scanf("%s",s);
			str=s;
			DNA.insert(pair<int,string>(reorder(str),str));
		}
		it=DNA.begin();
		while(it!=DNA.end())
		{
			cout<<it->second<<endl;
			it++;
		}
		DNA.clear();
	}
	return 0;
}

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