标签:
在看pat上的题目思考许久,还是久久不能完全实现怎么去求子序列中的首位。先贴出个还有点bug的代码:
#include <stdio.h> int main() { int i, size = 0, maxEle = 0, currEle = 0; int currEleStart = 0, currEleEnd = 0; scanf("%d", &size); int arr[size]; for(i = 0; i < size; i++) { scanf("%d", &arr[i]); currEle += arr[i]; if (currEle >= 0 && maxEle == 0) { currEleStart = arr[i]; } if (currEle > maxEle) { maxEle = currEle; currEleEnd = arr[i]; } else if (currEle < 0) { currEle = 0; } } printf("%d %d %d", maxEle, currEleStart, currEleEnd); return 0; }
标签:
原文地址:http://www.cnblogs.com/hznge/p/5951268.html