跪求大神啊,帮忙看看我POJ1007到底拿错了,纠结好几天啦 5C

#include
#include
typedef struct tagDNA
{
char xulie[51];
int count;
}DNA;
int cmp(const void*a,const void*b)
{
return (*(DNA )a).count>((DNA *)b).count?1:-1;
}
int main()
{
int n,m,i,j,k;
DNA A[101],t;
scanf("%d%d",&n,&m);

 for(i=0;i<m;i++)
 scanf("%s",A[i].xulie);

 for(i=0;i<m;i++)
 {  
     for(j=0;j<n-1;j++)
       for(k=j+1;k<n;k++)
           if(A[i].xulie[j]>A[i].xulie[k]) A[i].count+=1;
 }

qsort(A,m,sizeof(A[0]),cmp);

 for(i=0;i<m;i++)printf("%s %d\n",A[i].xulie,A[i].count);

 return 0;


        //n是字符串的长度,而m是测试的数据

}
我的测试结果和正确答案一样,为什么显示WA

poj

5个回答

后面的 输出长度是我自己加的,奇怪的是GGGGGGGGGG字符串的长度 居然是9;

Description

One measure of unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequenceDAABEC'', this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence AACEDGG'' has only one inversion (E and D)---it is nearly sorted---while the sequenceZWQM'' has 6 inversions (it is as unsorted as can be---exactly the reverse of sorted).

You are responsible for cataloguing a sequence of DNA strings (sequences containing only the four letters A, C, G, and T). However, you want to catalog them, not in alphabetical order, but rather in order of sortedness'', frommost sorted'' to ``least sorted''. All the strings are of the same length.

Input

The first line contains two integers: a positive integer n (0 < n <= 50) giving the length of the strings; and a positive integer m (0 < m <= 100) giving the number of strings. These are followed by m lines, each containing a string of length n.

Output

Output the list of input strings, arranged from most sorted'' toleast sorted''. Since two strings can be equally sorted, then output them according to the orginal order.

Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT

Sample Output

为何这题显示WA,难道我还有没有那个地方没有考虑到吗

using namespace std;
int main()
{
int a, b;
cin >> a >> b;
char c[50];
vector res[1225];
for(int i=0; i
{
cin >> c;
int re_num = 0;
int A=0, C=0, G=0, T=0;
for(int j=0; j
{
switch(c[j])
{
case 'A':
re_num += (C+G+T);
A++;
break;
case 'C':
re_num += (G+T);
C++;
break;
case 'G':
re_num += T;
G++;
break;
case 'T':
T++;
break;
break;
}
}
string temp = c;
res[re_num].push_back(temp);
}
for(int i=0; i<1225; i++)
{
if(!res[i].empty())
{
vector::iterator it = res[i].begin();
for(; it!=res[i].end(); it++)
{
cout << (*it) << endl;
}
}
}
return 0;
}

askmingcle
askmingcle 大神,我没学过C++
4 年多之前 回复

大神,我没学过C++

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐