/*
* POJ_2356.cpp
*
* Created on: 2013年10月8日
* Author: Administrator
*/
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 10005;
int a[maxn], s[maxn], mod[maxn];
void print(int s, int t) {
printf("%d\n", t - s + 1);
int i;
for (i = s; i <= t; ++i) {
printf("%d\n", a[i]);
}
}
int main() {
int n;
scanf("%d", &n);
memset(a, 0, sizeof(a));
memset(s, 0, sizeof(s));
memset(mod, 0, sizeof(mod));
int i;
for (i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
s[i] = s[i-1] + a[i];
if (s[i] % n == 0) {
print(1, i);
break;
} else if (!mod[s[i] % n]) {
mod[s[i] % n] = i;
} else {
print(mod[s[i] % n] + 1, i);
break;
}
}
}
本文提供了一段解决POJ_2356问题的C++代码实现,该问题涉及数组操作和模运算,通过记录前缀和及其模结果来查找满足条件的子数组。
993

被折叠的 条评论
为什么被折叠?



