작성일 :

문제 링크

13528번 - Grass Seed Inc.

설명

잔디 씨앗 단가와 각 잔디밭의 너비, 길이가 주어질 때 총 비용을 계산하는 문제입니다.


접근법

각 잔디밭의 넓이를 구해 단가를 곱한 뒤 모두 합산합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;

class Program {
  static void Main() {
    var c = double.Parse(Console.ReadLine()!);
    var n = int.Parse(Console.ReadLine()!);
    var total = 0.0;
    for (var i = 0; i < n; i++) {
      var parts = Console.ReadLine()!.Split();
      var w = double.Parse(parts[0]);
      var l = double.Parse(parts[1]);
      total += c * w * l;
    }
    Console.WriteLine($"{total:F7}");
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  double c; int n; cin >> c >> n;
  double total = 0.0;
  for (int i = 0; i < n; i++) {
    double w, l; cin >> w >> l;
    total += c * w * l;
  }
  cout << fixed << setprecision(7) << total << "\n";

  return 0;
}