12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- // 1003.cpp: 定义控制台应用程序的入口点。
- //
- #include "stdafx.h"
- #include<iostream>
- using namespace std;
- struct Node{
- int sum;
- int start, end;
- };
- Node* Combine(int *digs,int N, int length) {
- Node *nodes = new Node[length];
- bool gteZero, next = true;
- int index = 0;
- for (int i = 0; i < N; i++) {
- if (i == 0) {
- nodes[index].sum = 0;
- nodes[index].start = 0;
- nodes[index].end = -1;
- }
- else if (digs[i] >= 0 != gteZero) {
- nodes[index].end = i - 1;
- index++;
- nodes[index].sum = 0;
- nodes[index].start = i;
- nodes[index].end = -1;
- }
- nodes[index].sum += digs[i];
- gteZero = digs[i] >= 0;
- }
- if (nodes[index].end == -1)
- {
- nodes[index].end = N - 1;
- }
- return nodes;
- }
- int getResult() {
- }
- int main()
- {
- int T, N;
- while (cin >> T) {
- for (int index = 0; index < T; index++) {
- cin >> N;
- int *digs = new int[N];
- Node *nodes;
- bool gteZero = false;
- int count = 0;
- for (int i = 0; i < N; i++) {
- cin >> digs[i];
- if (i == 0) {
- count++;
- }
- else if (digs[i] >= 0 != gteZero) {
- count++;
- }
- gteZero = digs[i] >= 0;
- }
- nodes = Combine(digs, N, count);
- free(digs);
- }
- }
- return 0;
- }
|