浙江工业大学ACM1042,哪错了?

来源:百度知道 编辑:UC知道 时间:2024/05/25 03:25:53
#include <stdio.h>
int main()
{
int first;
int last;
int between;
int sum;
int item;
scanf( "%d%d%d", &first, &last, &between );
while (first !=0 && last != 0 && between != 0){
item = (last - first)/between + 1;
sum = (first + last)*item/2;
printf( "%d\n", sum );
scanf( "%d%d%d", &first, &last, &between );
}
return 0;
}

题目是这个:
求等差数列的和
Time Limit:1000MS Memory Limit:32768K

Description:
有一些整数组,每三个整数为一组,分别表示等差数列的起始位置、终止位置和公差,求每组数列的和。如果三个整数都为0,表示输入结束。

Sample Input:
5 100 5
1 5 1
1 10 1
0 0 0
Sample Output:
1050
15
55

程序照这个输入的话没错
Sample Input:
5 100 5
1 5 1
1 10 1
0 0 0
Sample Output:
1050
15
55
但是不够严谨,
item = (last - first)/between + 1;
若是 last=5,first=2,between=2,此时数据本身就是错的,算出来的东西不就更错了