昨天回到家啦~休息一下,今天刷一道题~靠,提交了5次,查不出来问题~先搁上来,有木有大神解答一下:
解决了:一个是最后多了一个空格;一个是没有对sum[]赋值 0;
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> #include <ctime> int main() { int n, m, i, k, j, l; int sum[100] = {}; int m_aver[100] = {}; int sum1, n_aver; while(scanf("%d%d", &n,&m)!=EOF && n<=100 && n>=m) { sum1 = 0; k = n/m; l = n%m;//repair for(j=0;j<k;++j){ for(i=0;i<m;++i){ sum[j] = sum[j] + 2*(i+1) +2*j*m; } m_aver[j] = sum[j]/m; if(l == 0 && j == (k-1)) //repair printf("%d", m_aver[j]); //the last and n=m is not " " else printf("%d ", m_aver[j]); sum[j] = 0; } if(n>k*m){ for(i=k*m;i<n;++i){ sum1 = sum1 + 2*(i+1); n_aver = sum1/(n-k*m);} printf("%d\n", n_aver); }else printf("\n"); } return 0; }