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

找不出问题,谁帮忙看看我的代码……

Posted by MinWh at 2006-11-13 19:08:03 on Problem 1007
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

struct node
{
	int inversion;
	string str;
}s[100];

int compare(const void *a,const void *b)
{
	node* m = (node*)a;
	node* n = (node*)b;
	return (m->inversion >= n->inversion);
}


// A,C,G,T
int main()
{
	int m, n, c[3];
	cin >>n >>m;
	
	string str;
	for (int i = 0; i < m; i++)
	{
		cin >>str;

		s[i].inversion = 0;
		s[i].str = str;
		c[0] = c[1] = c[2] = 0;
		for (int j = n-1; j >= 0; j--)
		{
			switch (str[j])
			{
			case 'A':
				c[0]++;
				c[1]++;
				c[2]++;
				break;
			case 'C':
				c[1]++;
				c[2]++;
				s[i].inversion += c[0];
				break;
			case 'G':
				c[2]++;
				s[i].inversion += c[1];
				break;
			case 'T':
				s[i].inversion += c[2];
				break;
			default:
				break;
			}
		}
	}

	qsort(s, m, sizeof(node), compare);

	for (i = 0; i < m; i++)
	{
		cout <<s[i].str <<endl;
	}

	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