【ACM】杭电OJ 2090

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CSDN___CSDN/article/details/83821504

题目中给出的四舍五入的条件可以忽略不计了,因为提交的程序没有考虑四舍五入,照样AC了

printf("%.1lf\n",sum);

AC代码:

写的有点复杂了,其实不用定义结构体也可以。 

#include<iostream>
#include <cstdio>
using namespace std;
typedef struct Ve
{
	char name[100];
	double total;
	double price;
}vegetable;
int main()
{
	vegetable V;
	double sum=0;
	while(scanf("%s%lf%lf",V.name,&V.total,&V.price)==3)
        {
    	    sum+=(V.price*V.total);
	}	
	printf("%.1lf\n",sum);
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/CSDN___CSDN/article/details/83821504