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

Re:为何temp[100][50]改成temp[100][51]就行了呢,

Posted by hanshumajia at 2008-08-07 23:25:03 on Problem 1007
In Reply To:为何temp[100][50]改成temp[100][51]就行了呢, Posted by:ekoi at 2008-08-07 12:32:06
> 我的代码,跟你的差不多,wa
#include <cstdlib>
#include <iostream>

using namespace std;

int count_inver(char *str, int len);

int main(int argc, char *argv[])
{
    int m,n;
    int i,j;
    cin>>m>>n;
    char **sort=new char *[n];
    for(i=0;i<n;i++)
    {
        sort[i]=new char[m+1];
        } 
    int *ress=new int[n];//存放每一行的unsortedness值
    for(i=0;i<n;i++)//输入数据
    {
		cin>>sort[i];
	}
	char *temp;
	for(i=0;i<n;i++)
		ress[i]=count_inver(sort[i],m);
	for(i=0;i<n;i++)
	{
	//	cout<<ress[i]<<endl;
		for(j=i;j<n;j++)
			if(ress[i]<ress[j])
			{
				temp=sort[i];
				sort[i]=sort[j];
				sort[j]=sort[i];
			}
	}
	for(i=0;i<n;i++)
		cout<<sort[i]<<endl;

}


int count_inver(char *str, int len)
{
	int i;  
	int cnt = 0;
	int a[4] = {0};
	for(i = len - 1; i >= 0; i--) {
		switch (str[i]) {
		case 'A':
			a[1]++; 
			a[2]++; 
			a[3]++; 
			break;  
		case 'C':
			a[2]++; 
			a[3]++; 
			cnt += a[1];
			break;  
		case 'G':
			a[3]++; 
			cnt += a[2];
			break;  
		case 'T':
			cnt += a[3];
		}
	}
	return cnt;
}


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