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

水题一道,0msAC,小规模数据排序还是用inset sort好,附代码。

Posted by zycxy at 2011-09-19 22:15:16 on Problem 1007 and last updated at 2011-09-19 22:15:50
#include <stdio.h>

char s[100][51] = {0};
int cnt[4] = {0};
int total = 0;
int count[100] = {0};
int pos[100] = {0};

int main()
{
	int n = 0, m = 0;
	int i = 0, j = 0, k = 0;

	scanf("%d %d", &n, &m);

	for(i = 0; i < m; i++)
	{
		scanf("%s", s[i]);
	}
	
	for(i = 0; i < m; i++)
	{
		for(j = 0; j < 4; j++)
		{
			cnt[j] = 0;
		}

		for(j = 0; j < n; j++)
		{
			switch(s[i][j])
			{
			case 'A':
				{
					cnt[0]++;
					break;
				}
			case 'C':
				{
					cnt[1]++;
					break;
				}
			case 'G':
				{
					cnt[2]++;
					break;
				}
			case 'T':
				{
					cnt[3]++;
					break;
				}
			}
		}
		total = 0;
		for(j = 0; j < n; j++)
		{
			switch(s[i][j])
			{
			case 'A':
				{
					cnt[0]--;
					break;
				}
			case 'C':
				{
					cnt[1]--;
					total += cnt[0];
					break;
				}
			case 'G':
				{
					cnt[2]--;
					total += (cnt[0]+cnt[1]);
					break;
				}
			case 'T':
				{
					cnt[3]--;
					total += (cnt[0]+cnt[1]+cnt[2]);
					break;
				}
			}
		}
		count[i] = total;
	}

	for(i = 0; i < n; i++)
	{
		pos[i] = i;
	}

	for(i = 1; i < m; i++)
	{
		j = i;
		k = count[j];
		while(k < count[j-1] && j > 0)
		{
			count[j] = count[j-1];
			pos[j] = pos[j-1];
			j--;
		}
		count[j] = k;
		pos[j] = i;
	}

	for(i = 0; i < m; i++)
	{
		printf("%s\n", s[pos[i]]);
	}

	return 1;
}

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