en annan lösning
Kod:
#include <iostream>
#include <numeric>
#include <cmath>
void edoceo_flashback_2009(int *a_start, int *a_end){
int max, week, tmp, *_p;
for(max=0,_p=a_start; _p<a_end; _p+=7){
if((tmp = std::accumulate(_p, std::min(_p+7,a_end), 0)) > max){
max = tmp;
week = int(std::ceil((_p-a_start)/7)+1);
}
}
std::cout << "week: " << week << " downfall: " << max << " mm." << std::endl;
return;
}
int main(int argc, char **argv){
int a[] = {
0,0,0,0,0,0,0, /* week 1 */
1,5,3,2,0,8,9, /* week 2 */
9,9,9,2,3,1,0, /* week 3 */
0,0,0,2,4,5,9, /* week 4 */
9,9,9 /* week 5 */
};
edoceo_flashback_2009(a, a+31);
return 0;
}