| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1180 人关注过本帖
标题:北大的poj 1007题目怎么一直WA
只看楼主 加入收藏
交相辉映
Rank: 2
等 级:论坛游民
帖 子:13
专家分:17
注 册:2010-11-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:6 
北大的poj 1007题目怎么一直WA
#include<stdio.h>
int main(void)
{
    int m,n,t;
    int i,j,k,num[100]={0};
    char b;
    char a[100][51];
    scanf("%d %d",&n,&m);
    fflush(stdin);
    if(m<=0 || m>100 || n<=0 || n>50)
        return 0;
  for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
            scanf("%c",&a[i][j]);
        fflush(stdin);
    }
    for(i=0;i<m;i++)
        for(j=0;j<n-1;j++)
            for(k=j+1;k<n;k++)
            {
                if(a[i][j]>a[i][k])
                    num[i]++;
            }
            for(i=0;i<m-1;i++)
            {
                for(j=i+1;j<m;j++)
                {
                    if(num[i]>num[j])
                    {
                        for(k=0;k<n;k++)
                        {
                            b=a[i][k];
                            a[i][k]=a[j][k];
                            a[j][k]=b;
                        }
                        t=num[i];
                        num[i]=num[j];
                        num[j]=t;
                    }
                }
            }
            for(i=0;i<m;i++)
            {
                for(j=0;j<n;j++)
                    printf("%c",a[i][j]);
                printf("\n");
            }
            return 0;
}
程序如上,在vs2010下运行正常
提交一直WA,实在看不出来错误
特此求助。

[ 本帖最后由 交相辉映 于 2010-12-17 00:23 编辑 ]
搜索更多相关主题的帖子: 北大 poj 
2010-12-17 00:14
交相辉映
Rank: 2
等 级:论坛游民
帖 子:13
专家分:17
注 册:2010-11-28
收藏
得分:0 
题目要求:
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

CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
2010-12-17 00:15
交相辉映
Rank: 2
等 级:论坛游民
帖 子:13
专家分:17
注 册:2010-11-28
收藏
得分:0 
题目大意: DNA 由 A,C,G,T四个字母组成,给你一些排列,让从最有序到最无序排列,也就是逆序数最小到逆序数最大排列
什么是逆序数呢,在一个排列中,如果前面的数比后面的大就称为逆序.一个排列中的逆序总数称为逆序数,
逆序数为偶数的排列为偶排列,逆序数为奇数的排列为奇排列,给出32145求出它的逆序数,
从它的第二个数开始,和它前面的数比较大小,如果是从小到大的顺数,
则逆序数为0,如果前面有几个比它大的逆序数就是几。
2010-12-17 00:43
交相辉映
Rank: 2
等 级:论坛游民
帖 子:13
专家分:17
注 册:2010-11-28
收藏
得分:0 
没有人帮忙吗?
2010-12-17 11:51
交相辉映
Rank: 2
等 级:论坛游民
帖 子:13
专家分:17
注 册:2010-11-28
收藏
得分:0 
#include<stdio.h>
int count(char name[]);
void sort(int k);
struct list
{
    char name[51];
    int count_t;
}a[100];
int main(void)
{
    int m,n;
    scanf("%d %d",&m,&n);
    for(int i=0;i<m;i++)
        {
            scanf("%s",a[i].name);
            a[i].count_t=count(a[i].name);
        }
    sort(m);
    for(int i=0;i<m;i++)
        {
            printf("%s",a[i].name);
            printf("\n");
    }
    getchar();
    return 0;


}
int count(char name[])
{
    int sum=0;
    for(int i=0;name[i];i++)
        for(int j=i+1;name[j];j++)
            if(name[i]>name[j])
                sum++;
    return sum;
}
void sort(int k)
{
    struct list temp;
    for(int i=0;i<k-1;i++)
        for(int j=i+1;j<k;j++)
            if(a[i].count_t>a[j].count_t)
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
}
换了个办法就AC了
第一种办法最直观的反而搞不定
后来再仔细研究吧。
结贴吧。
2010-12-17 17:53
快速回复:北大的poj 1007题目怎么一直WA
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036735 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved