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

why is it wrong?

Posted by woaixiyuan at 2008-05-03 00:11:28 on Problem 3183
#include<stdio.h>
#define N 50001
int main()
{
       unsigned int i,n;
       int h[N];
       scanf("%d",&n);
       for(i=0;i<n;i++)
       {
           scanf("%d",&h[i]);
       }
       for(i=0;i<n-1;)
       {
          if(h[i]==h[i+1])
          {
               printf("%d\n",i+1);
               i++;
          }
          else if(h[i]>h[i+1])
          {
               printf("%d\n",i+1);
               i++;
               while(i<n-1&&h[i]>h[i+1])
               {        i++;           }
               i++;
          }
          else
          {
               i++;
               while(i<n-1&&h[i]<h[i+1])
               {     i++;      }
               printf("%d\n",i+1);
               if(h[i]==h[i+1])
               {    i++;     }
               else
               {
                  while(i<n-1&&h[i]>h[i+1])
                  {       i++;        }
                  i++;
               }
          }
       }
       if(h[n-2]==h[n-1])
              printf("%d\n",n);

       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