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

这么 简单明了的代码为何总是 WA

Posted by zlm8680 at 2015-12-14 22:31:26 on Problem 1007
#include <iostream>
#include <string>

using namespace std;

int calcInverseCount(string str)
{
	int nums = 0;
	int temp[4] = {0};
	for(int i=str.length()-1; i>=0; i--)
	{
		switch(str[i])
		{
		case 'A':
			temp[1]++;  //C
			temp[2]++;  //G
			temp[3]++;  //T
			break;
		case 'C':
			temp[2]++;
			temp[3]++;
			nums += temp[1];
			break;
		case 'G':
			temp[3]++;
			nums += temp[2];
			break;
		case 'T':
			nums += temp[3];
			break;
		}
	}
	return nums;
}

int cmp(const void* a, const void* b)
{
	return ( *(int*)a - *(int*)b);
}
int main()
{
	int n, m;
	int i, j;
	cin >> n >> m;
	if(m <= 0 || n <= 0)
		return 0;

	string* arrayInput = new string[m]; // m strings new string[m]
	int* InverseNum = new int(m);

	for(i=0; i<m; i++) //nums of string
	{
		cin >> arrayInput[i];

		//calculate inverse count
		InverseNum[i] = calcInverseCount(arrayInput[i]) * 1000 + i;
	}

	qsort(InverseNum, m, sizeof(int), cmp);
	
	for(i=0; i<m; i++)
	{
		cout << arrayInput[InverseNum[i] % 1000] << 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