Programming/C

[백준] 단계별로 풀어보기 > if문 (C언어)

코딩뽀시래기 2021. 3. 21. 03:52
728x90

+) 풀이 코드

https://github.com/jung0115/CodingTestPractice.git

 

GitHub - jung0115/CodingTestPractice: Practice Coding Test with Beakjoon, programmers, etc.

Practice Coding Test with Beakjoon, programmers, etc. - GitHub - jung0115/CodingTestPractice: Practice Coding Test with Beakjoon, programmers, etc.

github.com

 

다시 알고리즘 문제 풀기에서 감을 찾아보자!

 

1330번

#include <stdio.h>
int main(void){
int num1, num2;
scanf("%d %d", &num1, &num2);
if(num1 > num2)
printf(">");
else if(num1<num2)
printf("<");
else
printf("==");
return 0;
}

 

9498번

#include <stdio.h>
int main(void){
int score;
scanf("%d", &score);
if(score<=100 && score>=90)
printf("A");
else if(score<=89 && score>=80)
printf("B");
else if(score<=79 && score>=70)
printf("C");
else if(score<=69 && score>=60)
printf("D");
else
printf("F");
return 0;
}

 

2753번

#include <stdio.h>
int main(void){
int year;
scanf("%d", &year);
if(((year%4) == 0 && (year%100) != 0) || (year%400) == 0)
printf("1");
else
printf("0");
return 0;
}

 

14681번

#include <stdio.h>
int main(void){
int x, y;
scanf("%d", &x);
scanf("%d", &y);
if(x > 0 && y > 0)
printf("1");
else if(x < 0 && y > 0)
printf("2");
else if(x < 0 && y < 0)
printf("3");
else
printf("4");
return 0;
}

 

2884번

#include <stdio.h>
int main(void){
int H, M;
scanf("%d %d", &H, &M);
if(M < 45){
int sample;
sample = 45 - M;
M = 60 - sample;
if(H == 0)
H = 23;
else
H--;
}
else if(M == 45)
M = 0;
else
M -= 45;
printf("%d %d", H, M);
return 0;
}
728x90