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

Hi guys, could you please view my code and tell me why I was wrong?

Posted by ducfilan at 2013-01-01 17:06:02 on Problem 1007
This is my code:

#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;

main()
{
    int n,m;
    while (scanf ("%d %d", &n, &m)!=EOF)
    {
        char DNA[m][n+1];
        int count[m],l=0;

        for(int i=m-1; i>=0; --i)
        {
            count[i]=0;
            fflush(stdin);
            cin.getline(DNA[i],n+1);
            int len=strlen(DNA[i]);
            for(int j=len-2; j>=0; --j)
                for(int k=len-1; k>=j+1; --k)
                    if(DNA[i][j]>DNA[i][k]) ++count[i];
        }
        //
        for(int k=m-1; k>=0; --k)
        {
            int imin=0;
            int min=count[0];
            //Ok
            for(int i=m-l-1; i>=0; --i)
                if(count[i]<min)
                {
                    min=count[i];
                    imin=i;
                }
            cout<<DNA[imin]<<endl;

            for(int i=0; i<m-l-1; i++)
                if(count[i]==count[m-1-l])
                {
                    char temp[n+1];
                    strcpy(temp,DNA[i]);
                    strcpy(DNA[i],DNA[m-1-l]);
                    strcpy(DNA[m-1-l],temp);
                    break;
                }

            count[imin]=count[m-1-l];
            strcpy(DNA[imin],DNA[m-1-l]);
            ++l;
        }
    }
    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