백준 알고리즘/Lang-C | C++

[백준/C] 6763번 Speed fines are not fine!

Jongung 2021. 8. 24. 00:44

 

백준 온라인 저지 / 6763번 Speed fines are not fine! 

https://www.acmicpc.net/problem/6763

 

6763번: Speed fines are not fine!

Many communities now have “radar” signs that tell drivers what their speed is, in the hope that they will slow down. You will output a message for a “radar” sign. The message will display information to a driver based on his/her speed according to

www.acmicpc.net

 

  • 사용언어 : 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.");
		}
	}

}