[백준 6763] Speed fines are not fine! (C#, C++) - soo:bak
작성일 :
문제 링크
6763번 - Speed fines are not fine!
설명
제한속도와 차량 속도가 주어질 때, 속도 위반 여부에 따라 과태료를 출력하는 문제입니다.
접근법
먼저 차량 속도에서 제한속도를 뺀 초과분을 계산합니다.
초과분이 0 이하면 축하 메시지를 출력합니다.
초과분이 1~20이면 $100, 21~30이면 $270, 31 이상이면 $500의 과태료를 출력합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
class Program {
static void Main() {
var limit = int.Parse(Console.ReadLine()!);
var speed = int.Parse(Console.ReadLine()!);
var delta = speed - limit;
if (delta <= 0)
Console.WriteLine("Congratulations, you are within the speed limit!");
else {
int fine = delta <= 20 ? 100 : (delta <= 30 ? 270 : 500);
Console.WriteLine($"You are speeding and your fine is ${fine}.");
}
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int limit, speed; cin >> limit >> speed;
int delta = speed - limit;
if (delta <= 0)
cout << "Congratulations, you are within the speed limit!\n";
else {
int fine = (delta <= 20) ? 100 : (delta <= 30 ? 270 : 500);
cout << "You are speeding and your fine is $" << fine << ".\n";
}
return 0;
}