问题描述
- 跪求大神啊,帮忙看看我POJ1007到底拿错了,纠结好几天啦
-
#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 %dn",A[i].xulie,A[i].count); return 0; //n是字符串的长度,而m是测试的数据
}
我的测试结果和正确答案一样,为什么显示WA
解决方案
后面的 输出长度是我自己加的,奇怪的是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 sequence
DAABEC'', 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 sequence
ZWQM'' 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'', from
most 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'' to
least 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;
}
解决方案五:
大神,我没学过C++