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

1A留念

Posted by jily16 at 2017-05-11 23:13:14 on Problem 1007
#include <map>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
map<string, int> m;
int cal(string const &s)
{
	int ans = 0;
	int a = 0, c = 0, g = 0, t = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		switch (s[i])
		{
		case 'A':
		{
			++a;
			ans += (c + g + t);
			break;
		}
		case 'C':
		{
			++c;
			ans += (g + t);
			break;
		}
		case 'G':
		{
			++g;
			ans += t;
			break;
		}
		case 'T':
		{
			++t;
			break;
		}
		default:
			break;
		}
	}
	return ans;
}
bool cmp(string const & s1, string const & s2)
{
	return m[s1] < m[s2];
}
int main()
{
#ifdef DEBUG
	freopen("C:\\Users\\admin\\Desktop\\编程\\in.txt", "r", stdin);
#endif

	int len, n;
	cin >> len >> n;
	vector<string> vs(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> vs[i];
		m[vs[i]] = cal(vs[i]);
	}
	sort(vs.begin(), vs.end(), cmp);
	for (int i = 0; i < n; ++i)
	{
		cout << vs[i] << endl;
	}

#ifdef DEBUG
	freopen("con", "r", stdin);
	system("pause");
#endif // DEBUG
	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