[백준 5565] 영수증 (C#, C++) - soo:bak
작성일 :
문제 링크
설명
책 10권의 총 가격 합계과 10권 중 9권의 책 가격이 주어졌을 때,
마지막 1
개의 책 가격을 찾아 출력하는 간단한 산술 문제입니다.
접근법
- 입력 첫 줄에서 총 금액 을 입력받습니다.
- 이후
9
개의 정수를 입력받아, 총 금액에서 하나씩 차감해 나갑니다. - 위 과정이 끝난 후 남은 값이 남은 책의 가격입니다.
Code
[ C# ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
namespace Solution {
class Program {
static void Main(string[] args) {
int total = int.Parse(Console.ReadLine()!);
for (int i = 0; i < 9; i++) {
int cost = int.Parse(Console.ReadLine()!);
total -= cost;
}
Console.WriteLine(total);
}
}
}
[ 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);
int total; cin >> total;
for (int i = 0; i < 9; i++) {
int cost; cin >> cost;
total -= cost;
}
cout << total << "\n";
return 0;
}