백준 온라인 저지 / 6763번 Speed fines are not fine!
https://www.acmicpc.net/problem/6763
- 사용언어 : C (C99)
- 알고리즘 : 수학, 사칙연산
C 코드
1. 문제 정리
두 개의 정수를 입력 한 후 계산 하는 문제이다.
첫번 째 입력은 속도 제한이고 두번 째 입력은 기록된 차의 속도이다.
주차 딱지 문제 같은 느낌이 아닐까? ㅋㅋㅋㅋㅋㅋ 테이블로 정리해보자.
제한된 속도 초과 (KM/H) | 금액 |
1 ~ 20 | $100 |
21 ~ 30 | $270 |
31 ~ 보다 많은 수 | $500 |
초과 하지 않았으면 Congratulations, you are within the speed limit!
초과된 속도에 따라 금액을 넣어서 You are speeding and your fine is $???..
예외 처리 하면 문제 해결
2. 완성 코드
#include <stdio.h>
int main() {
int A, B;
scanf_s("%d %d", &A, &B);
int speed = B - A;
if (speed <= 0) {
printf("Congratulations, you are within the speed limit!");
}
else {
if (1 < speed && speed <= 20) {
printf("You are speeding and your fine is $100.");
}
else if (21 < speed && speed <= 30) {
printf("You are speeding and your fine is $270.");
}
else {
printf("You are speeding and your fine is $500.");
}
}
}
'백준 알고리즘 > Lang-C | C++' 카테고리의 다른 글
[백준/C] 10797번 10부제 (0) | 2021.08.26 |
---|---|
[백준/C] 10768번 특별한 날 (1) | 2021.08.25 |
[백준/C] 10156번 과자 (0) | 2021.08.23 |
[백준/C] 10101번 삼각형 외우기 (0) | 2021.08.22 |
[백준/C] 5928번 Contest Timing (0) | 2021.08.21 |