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:新手感觉这个代码好漂亮

Posted by yaohwu at 2016-04-15 21:37:40 on Problem 1007
In Reply To:AC code Posted by:Kindevil at 2012-07-16 00:38:32
> #include<iostream>
> using namespace std;
> 
> class DNA
> {
> public:
> 	int num;
> 	char str[51];
> };
> 
> int reverseorder(char* m,int n)
> {
> 	int i,answer=0;
> 	int A=0,C=0,G=0;
> 	for(i=n-1;i>=0;i--)
> 	{
> 		switch(m[i])
> 		{
> 		case 'A':
> 			A++;
> 			break;
> 		case 'C':
> 			C++;
> 			answer+=A;
> 			break;
> 		case 'G':
> 			G++;
> 			answer+=A+C;
> 			break;
> 		case 'T':
> 			answer+=A+C+G;
> 			break;
> 		}
> 	}
> 	return answer;
> }
> 
> int cmp(const void* a,const void* b)
> {
> 	DNA* x=(DNA*)a;
> 	DNA* y=(DNA*)b;
> 	return x->num-y->num;
> }
> 
> int main()
> {
> 	int i,n,m;
> 	cin>>n>>m;
> 	DNA* asd=new DNA[m];
> 	for(i=0;i<m;i++)
> 	{
> 		cin>>asd[i].str;
> 		asd[i].num=reverseorder(asd[i].str,n);	
> 	}
> 	qsort(asd,m,sizeof(DNA),cmp);
> 	for(i=0;i<m;i++) cout<<asd[i].str<<endl;
> }

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