最好将变量定义为double型。
#include<bits/stdc++.h> using namespace std; double n,D,p,L,v; int main() { int maxn = 0; while(scanf("%lf%lf",&n,&D)!=EOF) { if(n==0&&D==0) return 0; double sum_L = 0,sum = 0.0; for(int i=0;i<n;i++){ scanf("%lf%lf%lf",&p,&L,&v); sum+=2.0*L/v; sum_L+=L; } sum+=D-sum_L; printf("Case %d: %.3lf\n\n",++maxn,sum); } return 0; }
原文地址:http://blog.csdn.net/weizhuwyzc000/article/details/44780919