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 tangbohu222 at 2010-08-04 16:34:08 on Problem 1007
#include"iostream"
int calculate(char* p,int len)
{
	int result=0;
	for(int i=0;i<len;i++)
	{
		char a=*(p+i*sizeof(char));
		for(int j=i+1;j<len;j++)
		{
			
				char b=*(p+j*sizeof(char));
				switch(a)
				{
				case 'A': break;
				case 'C':
					{
						if(b=='A') result++;
						 break;
					}
				case 'G':
					{
						if(b=='A'||b=='C') result++;
						break;
					
					}
				case 'T':
					{
						if(b!='T') result++;
						break;
					}
				}
		}
	}
return result;
}
void sort(char* p,int num,int len)
{
	for(int i=0;i<num;i++)
	{
		for(int j=i+1;j<num;j++)
		{
			if(calculate(p+i*sizeof(char)*50,len)>calculate(p+j*sizeof(char)*50,len))
			{
				char *p1=p+i*sizeof(char)*50;
				char *p2=p+j*sizeof(char)*50;
				for(int a=0;a<len;a++)
				{
					char temp=NULL;
					temp=*(p1+a*sizeof(char));
					*(p1+a*sizeof(char))=*(p2+a*sizeof(char));
					*(p2+a*sizeof(char))=temp;
				
				
				}

				
			}

		}
	}

}

int main()
{

	int m=0;
	int n=0;
	scanf("%d",&n);
	scanf("%d",&m);
	getchar();
	char  a[100][50]; 
	char* p=&a[0][0];
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			scanf("%c",&(a[i][j]));
			if(j==n-1) { a[i][n]='\0';getchar();break;}
		}
	}
	sort(p,m,n);
	for(int i1=0;i1<m;i1++)
	{
		for(int j1=0;j1<n;j1++)
		{
		printf("%c",a[i1][j1]);
		if(j1==n-1) printf("\n");
		}
	}


}

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