| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
找不出问题,谁帮忙看看我的代码……#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
struct node
{
int inversion;
string str;
}s[100];
int compare(const void *a,const void *b)
{
node* m = (node*)a;
node* n = (node*)b;
return (m->inversion >= n->inversion);
}
// A,C,G,T
int main()
{
int m, n, c[3];
cin >>n >>m;
string str;
for (int i = 0; i < m; i++)
{
cin >>str;
s[i].inversion = 0;
s[i].str = str;
c[0] = c[1] = c[2] = 0;
for (int j = n-1; j >= 0; j--)
{
switch (str[j])
{
case 'A':
c[0]++;
c[1]++;
c[2]++;
break;
case 'C':
c[1]++;
c[2]++;
s[i].inversion += c[0];
break;
case 'G':
c[2]++;
s[i].inversion += c[1];
break;
case 'T':
s[i].inversion += c[2];
break;
default:
break;
}
}
}
qsort(s, m, sizeof(node), compare);
for (i = 0; i < m; i++)
{
cout <<s[i].str <<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator