poj1247

简单题

View Code
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cstring>

using namespace std;



#define maxn 40



int n;

int f[maxn];

int sum;



void input()

{

    for (int i = 0; i < n; i++)

        scanf("%d", &f[i]);

}



void work()

{

    sum = 0;

    for (int i = 0; i < n; i++)

        sum += f[i];

    if (sum & 1)

    {

        puts("No equal partitioning.");

        return;

    }

    int i = 0;

    int temp = 0;

    while (temp < sum / 2)

    {

        temp += f[i];

        i++;

    }

    //printf("%d %d\n", temp, sum / 2);

    if (temp == sum / 2)

        printf("Sam stops at position %d and Ella stops at position %d.\n", i, i + 1);

    else

        puts("No equal partitioning.");

}



int main()

{

    //freopen("t.txt", "r", stdin);

    while (scanf("%d", &n), n)

    {

        input();

        work();    

    }

    return 0;

}

 

你可能感兴趣的:(poj)