簡單題要注意過程的優化,代碼要寫得簡潔、調理。
判斷一個人編程的水平高不高,只需要寫一行代碼就知道了。
一定要多多注意思維的全面性,多審題,最後提煉出最簡潔的代碼方案。加油啊,你要做的很多絕不是三下五除二就能完成的。
這道題在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;
- }