题目思路不难,关键注意考虑全面。下面是我的思路:
http://acm.sdibt.edu.cn:8080/judge/contest/view.action?cid=316#problem/G
#include <stdio.h>
#include <stdlib.h>
struct f
{
       int max1;
       int length;
       int *base,*top;
};
int main()
{
       struct f b;
       int max=0,max2=0;
       char a;
       b.base=(int*)malloc(sizeof(int)*100);
      *(b.base)=0;
      b.top=b.base+1;
      b.max1=100;
      b.length=0;
      scanf("%d",b.top);
     a=getchar();
 while(a==' ')
 {    
        b.top++;
        b.length++;
        scanf("%d",b.top);
        a=getchar();
 }
  while(b.top!=b.base)
 {
       if(*(b.top)<=0)
              b.top–;
       else
      {
              max+=*(b.top);
              b.top–;
             break;
       }
  }
   while(b.top!=b.base)
 {
  
     if(*(b.top)>0){
            max+=*(b.top);
            b.top–;
  }
  if(*(b.top)<0)
  {
          if(*(b.top+1)+*(b.top)>=0&&*(b.top-1)+*(b.top)>=0)
         {
                max+=*(b.top);
               b.top–;
               continue;
          }
        if(*(b.top+1)+*(b.top)<0||*(b.top-1)+*(b.top)<0)
       {      if(max>max2)
              max2=max;
              max=0;
              b.top-=1;
               while(b.top!=b.base)
               {
                       if(*(b.top)<=0)
                                   b.top–;
                        else
                        { 
                                  max+=*(b.top);
                                  b.top–;
                                  break;
                        }
                }
        }
  }
 }
 printf("%d",max2);
 return 0;
}
不足之处,欢迎指点…….

发表评论

电子邮件地址不会被公开。

Post Navigation