Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

第二个程序为什么不能原序输出?

Posted by boringcpu at 2010-04-14 10:31:31 on Problem 1007
(两者除了count部分不同外,其余基本相同)
请大牛过目……
#include<stdio.h>
#include<string.h>
#define OK 1
struct list
{
    char c[51];
    int t;
}a[100];
int main()
{
    int count(char str[]);
    int sort(int m);
    int m,n,i;
    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%s",a[i].c);   
        a[i].t=count(a[i].c);   
    }
    sort(m);
    for(i=0;i<m;i++)
    {
        printf("%s\n",a[i].c);
    }
    return OK;
}
int count(char str[])
{
    int i,j,sum=0;
    for(i=0;str[i];i++)
    {
        for(j=i+1;str[j];j++)
        {
            if(str[i]>str[j])
            {
                sum++;
            }
        }   
    }
    return sum;
}
int sort(int m)
{
    int i,j,k;
    struct list temp;
    for(i=0;i<m-1;i++)
    {
        k=i;
        for(j=i+1;j<m;j++)
        {
            if(a[k].t>a[j].t)
            {
                k=j;
            }
        }
        if(k!=i)
        {
            temp=a[i];
            a[i]=a[k];
            a[k]=temp;
        }
    }
    return OK;
}

第二个
#include<stdio.h>
#include<string.h>
int count(char str[], int len)
{
        int i;  
        int sum = 0;
        int a[4] = {0};							
        for(i = len - 1; i >= 0; i--) {			
                switch (str[i]) {				
                        case 'A':				
                                a[0]++; 
                                a[1]++; 
                                a[2]++; 
                                break;			
                        case 'C':
                                a[1]++; 
                                a[2]++; 
                                sum += a[0];	
                                break;  
                        case 'G':
                                a[2]++; 
                                sum += a[1];
                                break;  
                        case 'T':
                                sum += a[2];	
                }
        }
        return sum;
}

struct list								
{
	char c[51];
	int t;
}a[101];

int sort(int m)
{
    int i,j,k;
    struct list temp;					
    for(i=0;i<m-1;i++)
    {
        k=i;
        for(j=i+1;j<m;j++)
        {
            if(a[k].t>a[j].t)			
            {
                k=j;
            }
        }
        if(k!=i)
        {
            temp=a[i];
            a[i]=a[k];
            a[k]=temp;
        }
    }
	return 0;
}

int main()
{
    int m,n,i;
    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%s",a[i].c);				
        a[i].t=count(a[i].c,m);   
    }
    sort(m);
    for(i=0;i<m;i++)
        printf("%s\n",a[i].c);
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator