試題 算法訓練 P1101---藍橋杯

試題 算法訓練 P1101
題目描述:
資源限制
時間限制:1.0s 內存限制:256.0MB
  
  有一份提貨單,其數據項目有:商品名(MC)、單價(DJ)、數量(SL)。定義一個結構體prut,其成員是上面的三項數據。在主函數中定義一個prut類型的結構體數組,輸入每個元素的值,計算並輸出提貨單的總金額。
  輸入格式:第一行是數據項個數N(N<100),接下來每一行是一個數據項。商品名是長度不超過100的字符串,單價爲double類型,數量爲整型。
  輸出格式:double類型的總金額。
輸入:
  4
  book 12.5 3
  pen 2.5 10
  computer 3200 1
  flower 47 5

輸出:
  3497.500000
AC代碼:

#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
struct node
{
	char name[100];
	double dj;
	int num;
}a[100];
int main()
{
	int n,i;
	cin>>n;
	double sum=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i].name>>a[i].dj>>a[i].num;
		sum+=a[i].dj*a[i].num;
	}
	printf("%.6lf\n",sum);
    return 0;
}
發佈了159 篇原創文章 · 獲贊 87 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章