poj1247 bjfu1239水题

其实就是读题啦,读懂题很简单,就是问一个数组,存不存在一个点,按这个点切成两半,这两半的数字的和是一样的。不多说了,上代码

/*

 * Author    : ben

 */

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <ctime>

#include <iostream>

#include <algorithm>

#include <queue>

#include <set>

#include <map>

#include <stack>

#include <string>

#include <vector>

#include <deque>

#include <list>

#include <functional>

#include <numeric>

#include <cctype>

using namespace std;

const int MAXN = 40;

int data[MAXN];

int sum1[MAXN], sum2[MAXN];



int main() {

    int n, i;

    while (scanf("%d", &n) == 1 && n > 0) {

        sum1[0] = 0;

        for (i = 1; i <= n; i++) {

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

            sum1[i] = sum1[i - 1] + data[i];

        }

        sum2[n] = data[n];

        for (i = n - 1; i > 0; i--) {

            sum2[i] = sum2[i + 1] + data[i];

        }

        for (i = 1; i < n; i++) {

            if (sum1[i] == sum2[i + 1]) {

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

                break;

            }

        }

        if (i == n) {

            printf("No equal partitioning.\n");

        }

    }

    return 0;

}

 

你可能感兴趣的:(poj)