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 liuwenxian at 2010-05-27 20:16:19 on Problem 1002
#include<iostream>
using namespace std;
int data[100000]={0};
void swap(int &a,int &b)
{
     int temp;
     temp=a;
     a=b;
     b=temp;
     }
int partion(int i,int j)
{
    int mark=i,x=data[i];
    for(int k=i+1;k<=j;k++)
    {
            if(data[k]<x)
            {
                         mark++;
                         if(mark!=k)swap(data[mark],data[k]);
                         }
                         }
    if(i!=mark)swap(data[i],data[mark]);
    return mark;
}
void quicksort(int i,int j)
{
     if(i<j)
     {
               int q=partion(i,j);
               quicksort(i,q-1);
               quicksort(q+1,j);
               }
}
void outputdigit(int x)
{
     int out[7];
     for(int i=6;i>=0;i--)
     {
             out[i]=x%10;
             x=x/10;
             }
     for(int i=0;i<7;i++)
     {
             printf("%d",out[i]);
             if(i==2)printf("-");
             }
}
             
void output(void)
{
     int num=1,i;
     bool flag=false;
     for(i=2;i<=data[0];i++)
     {
             if(data[i]==data[i-1])
             {
                              num++;
                              flag=true;
             }
             else 
             {
                  if(num>1)
                  {
                  outputdigit(data[i-1]);
                  printf(" %d\n",num);
                  }
                  num=1;
             }
     }
      if(num>1)
      {
               outputdigit(data[i-1]);
               printf(" %d\n",num);
      }
     if(!flag)
     printf("No duplicates.\n");
}
void input(void)
{
     int n,i=1;
     cin>>n;
     while(n>100000)
     {
                    cin>>n;
                    }
     data[0]=n;
     while(i<=n)
     {
                    int num=7,temp=0;
                    while(num)
                    {
                              char x;
                              cin>>x;
                              if(x!='-')
                              {
                                         if(x>='0'&&x<='9')
                                         temp=temp*10+x-'0';
                                         else if(x>='A'&&x<'Z')
                                         {
                                              if(x<'Q')
                                              temp=temp*10+(x-'A')/3+2;
                                              else temp=temp*10+(x-'Q')/3+7;
                                         }
                                         num--;
                              }
                    }
                    data[i]=temp;
                    i++;
     }
}
int main()
{
    input();
    quicksort(1,data[0]);
    //system("pause");
    output();
    //system("pause");
    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