北大ACM(1007 DNA-sorting)代码

/*
	Memory 187K Time 0MS
*/
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

bool cmpReverseCount(const pair<string, int> &lhs, const pair<string, int>& rhs)
{
	return lhs.second < rhs.second;
}
int main()
{
	int n, m;
	int i, j,z;
	int reverseCount;
	multimap<int, string> AllDNA;
	pair<int, string> p;
	string DNA;				
	multimap<int, string>::const_iterator beg;
	

	cin >> n >> m;

	for (i = 0; i < m; ++i)
	{
		cin >> DNA;
		reverseCount = 0;
		for (j = 0; j < n - 1; ++j)
		{
			
			for (z = j + 1; z < n; ++z)
			{
				if (DNA[j] > DNA[z])
					++reverseCount;
			}

		}
		p = pair<int, string>(reverseCount, DNA);;
		AllDNA.insert(p);
	}
	
	for (beg = AllDNA.begin(); beg != AllDNA.end(); ++beg)
		cout << beg->second << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/David_TD/article/details/83655725
今日推荐