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

一个晚上,它WA得很HAPPY,我实在是太累了

Posted by Jackjiangsir at 2008-06-27 05:21:53 on Problem 1002
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int stack[1000100];
int p;
void downto(int i)
{
     int j=i*2;
     int temp=stack[i];
     while(j<=p)
     {
                if(j<p&&stack[j+1]>stack[j])
                    j++;
                if(stack[j]>temp)
                    stack[i]=stack[j];
                else break;
                i=j;
                j=i*2;
     }
     stack[i]=temp;
}
void makeorder()
{
     int i;
     long temp;
     for(i=p/2;i>=1;i--)
        downto(i);
     i=p;
     while(p>1)
     {
               temp=stack[p];
               stack[p]=stack[1];
               stack[1]=temp;
               p--;
               downto(1);
     }
     p=i;
}
void sov()
{
     int a[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
     int flag=1;
     int i,j;
     char c[20];
     int temp;
     scanf("%d",&p);
     for(i=1;i<=p;i++)
     {
          scanf("%s",c);
          stack[i]=0;
          for(j=0;c[j];j++)
             if(c[j]!='-')
                if(c[j]>='A'&&c[j]<'Z'&&c[j]!='Q')
                    stack[i]=stack[i]*10+a[c[j]-'A'];
                else if(c[j]>='0'&&c[j]<='9')
                       stack[i]=stack[i]*10+c[j]-'0';
                      else while(1);
     }
     makeorder();
     for(i=2;i<=p;i++)
        if(stack[i]<stack[i-1])
             while(1);
     j=1;
     temp=stack[1];
     for(i=2;i<=p;i++)
         if(stack[i]==stack[i-1])
              j++;
         else{
              if(j>1)
              {
                 printf("%03d-%04d %d\n",temp/10000,temp%10000,j);
                 flag=0;
              }
              temp=stack[i];
              j=1;
         }
     if(j>1)
     {
       printf("%03d-%04d %d\n",temp/10000,temp%10000,j);
       flag=0;
     }
     if(flag) printf("No duplicates.\n");
}
void main()
{
    
    sov();
}

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