简单题要注意过程的优化,代码要写得简洁、调理。
判断一个人编程的水平高不高,只需要写一行代码就知道了。
一定要多多注意思维的全面性,多审题,最后提炼出最简洁的代码方案。加油啊,你要做的很多绝不是三下五除二就能完成的。
这道题在C++中可以编译通过,用C出现编译错误。
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int n, m;
- while(scanf("%d %d", &n, &m) != EOF)
- {
- int cnt = 0, tot = 0;
- for(int i = 0, num = 2; i < n; ++i, num += 2)
- {
- tot += num;
- cnt++;
- if(cnt == m && i != n-1)
- {
- printf("%d ", tot/cnt);
- cnt = 0;
- tot = 0;
- }
- else if(i == n-1)
- {
- printf("%d", tot/cnt);
- cnt = 0;
- tot = 0;
- }
- }
- printf("\n");
- }
- return 0;
- }
转载于:https://blog.51cto.com/4487906/1181060