[BOJ] IF문
2020. 7. 19. 23:56ㆍBOJ
아직 초반이라 아주 거뜬하다.
[BOJ 1330]
코딩 로봇이 된 느낌이다.
#include <stdio.h>
int main(){
int A, B;
scanf("%d%d",&A,&B);
if(A>B) putchar('>');
else if(A<B) putchar('<');
else /*if(A==B)*/ printf("==");
}
[BOJ 9498]
역시 함수로 짜주는 게 좋다. 일요일 저녁이라 위 문제도 채점이 밀려있다.
#include <stdio.h>
int convertscore(int score){
if(score>=90) return 'A';
else if(score>=80) return 'B';
else if(score>=70) return 'C';
else if(score>=60) return 'D';
else return 'F';
/* NEVER REACHED */
}
int main(){
int score;
scanf("%d",&score);
putchar(convertscore(score));
}
[BOJ 2753]
컴파일러를 믿어보자.
#include <stdio.h>
static inline bool is_multiple(int A, int B){
/* true if A is multiple of B */
return ((A%B) == 0);
}
int leap_year(int year){
if(is_multiple(year, 400)) return 1;
else if(is_multiple(year, 100)) return 0;
else if(is_multiple(year, 4)) return 1;
else return 0;
/* NEVER REACHED */
}
int main(){
int year;
scanf("%d",&year);
printf("%d",leap_year(year));
}
[BOJ 14681]
뭐 더 할 말이 있나.
#include <stdio.h>
int quadrant(int x, int y){
if(x>0){
if(y>0) return 1;
else /*if(y<0)*/ return 4;
} else{
if(y>0) return 2;
else /*if(y<0)*/ return 3;
}
}
int main(){
int x, y;
scanf("%d%d",&x,&y);
printf("%d",quadrant(x,y));
}
[BOJ 2884]
역시 마지막 문제는 뇌절이 제맛이다.
#include <stdio.h>
#include <utility>
typedef std::pair<int,int> time_t;
time_t alarm_time(time_t real_time){
int H = real_time.first;
int M = real_time.second;
if(M>=45) M -= 45;
else{
M += (60 - 45);
// decrease hour
H -= 1;
if(H<0) H += 24;
}
return {H,M};
}
int main(){
int H, M;
scanf("%d%d",&H,&M);
time_t alarm = alarm_time({H,M});
printf("%d %d", alarm.first, alarm.second);
}
다음 시간에 만나요~
'BOJ' 카테고리의 다른 글
[BOJ] 함수 (0) | 2020.07.23 |
---|---|
[BOJ] 1차원 배열 (0) | 2020.07.21 |
[BOJ] WHILE문 (0) | 2020.07.21 |
[BOJ] FOR문 (0) | 2020.07.20 |
[BOJ] 입출력과 사칙연산 (1) | 2020.07.20 |