简单题要注意过程的优化,代码要写得简洁、调理。 

     判断一个人编程的水平高不高,只需要写一行代码就知道了。

     一定要多多注意思维的全面性,多审题,最后提炼出最简洁的代码方案。加油啊,你要做的很多绝不是三下五除二就能完成的。 

     这道题在C++中可以编译通过,用C出现编译错误。

 

 
  
  1. #include <iostream> 
  2. #include <cmath> 
  3. using namespace std; 
  4.  
  5. int main() 
  6.     int n, m; 
  7.     while(scanf("%d %d", &n, &m) != EOF) 
  8.     { 
  9.         int cnt = 0, tot = 0; 
  10.         for(int i = 0, num = 2; i < n; ++i, num += 2) 
  11.         { 
  12.             tot += num; 
  13.             cnt++; 
  14.             if(cnt == m && i != n-1) 
  15.             { 
  16.                 printf("%d ", tot/cnt); 
  17.                 cnt = 0; 
  18.                 tot = 0; 
  19.             } 
  20.             else if(i == n-1) 
  21.             { 
  22.                 printf("%d", tot/cnt); 
  23.                 cnt = 0; 
  24.                 tot = 0; 
  25.             } 
  26.         } 
  27.         printf("\n"); 
  28.     } 
  29.     return 0;