2 askmingcle askmingcle 于 2016.03.16 23:14 提问

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

#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

5个回答

askmingcle
askmingcle   2016.03.16 23:15

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

askmingcle
askmingcle   2016.03.16 23:16

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

askmingcle
askmingcle   2016.03.16 23:21

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

liruoteng
liruoteng   2016.03.16 23:21

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++
一年多之前 回复
askmingcle
askmingcle   2016.03.16 23:23

大神,我没学过C++

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!