#include "maklib.h"
#include <stdio.h>
int Max(int a, int b) {
return a < b ? b : a;
}
int main() {
int res, max, i, size;
res = max = 0;
size = Size();
for(i=1; i<=size; i++) {
res = Max(0, res+ElementAt(i));
max = Max(res, max);
}
if(MyNodeId() > 0) {
PutInt(0, max);
Send(0);
} else {
for(i=1; i<NumberOfNodes(); i++) {
Receive(i);
max = GetInt(i);
}
printf("%d\n", max);
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include "maklib.h" #include <stdio.h> int Max(int a, int b) { return a < b ? b : a; } int main() { int res, max, i, size; res = max = 0; size = Size(); for(i=1; i<=size; i++) { res = Max(0, res+ElementAt(i)); max = Max(res, max); } if(MyNodeId() > 0) { PutInt(0, max); Send(0); } else { for(i=1; i<NumberOfNodes(); i++) { Receive(i); max = GetInt(i); } printf("%d\n", max); } return 0; } |
English