poj 1247(简单题)

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n,data[31];
    while(scanf("%d",&n)==1&&n){
        for(int i=1;i<=n;i++){
            scanf("%d",&data[i]);
        }
        for(int s1=data[1],s2=data[n],i=1,j=n;;){
            if(s1==s2&&i==j-1){
                printf("Sam stops at position %d and Ella stops at position %d.\n",i,j);
                break;
            }
            else if(s1>s2){
                j--;
                s2 += data[j];
            }
            else if(s1<s2){
                i++;
                s1 += data[i];
            }
            else if(i>j-1){
                printf("No equal partitioning.\n");
                break;
            }
            else if(i<j-1){
                i++; 
                s1 += data[i];
                j--;
                s2 += data[j];
            }
        }
    }
    return 0;
}

 

上一篇:poj 1306(阶乘,大数运算)


下一篇:poj 2262(素数)