알고리즘 문제/BOJ_Cpp

[BOJ/Step2] if문 (C++)

NaNaRin🙃 2021. 9. 15. 15:44

https://www.acmicpc.net/problem/1330 : 두 수 비교하기

#include <iostream>
using namespace std;

int main(void){
    int a, b;
    cin >> a >> b;
    if(a > b){
        cout << ">" << endl;
    } else if (a < b){
        cout << "<" << endl;
    }else{
        cout << "==" << endl;
    }
    
}

 

https://www.acmicpc.net/problem/9498 : 시험 성적

#include <iostream>
using namespace std;

int main(void){
    int score;
    cin >> score;
    if(score >= 90) cout << "A" << endl;
    else if(score >= 80) cout << "B" << endl;
    else if(score >= 70) cout << "C" << endl;
    else if(score >= 60) cout << "D" << endl;
    else cout << "F" << endl;
}

 

https://www.acmicpc.net/problem/2753 : 윤년

#include <iostream>
using namespace std;

int main(void){
    int year;
    cin >> year;
    if((year%4==0 && year%100!=0) || year%400==0 ) cout << 1 << endl;
    else cout << 0 << endl;
}

 

https://www.acmicpc.net/problem/14681 : 사분면 고르기

#include <iostream>
using namespace std;

int main(void){
    int x, y;
    cin >> x >> y;
    if(x>0 && y >0) cout << 1 << endl;
    else if(x>0 && y<0) cout << 4 << endl;
    else if(x<0 && y>0) cout << 2 << endl;
    else if(x<0 && y<0) cout << 3 << endl;
}

 

https://www.acmicpc.net/problem/2884 : 알람 시계

#include <iostream>
using namespace std;

int main(void){
    int h, m;
    cin >> h >> m;
    m -= 45;
    if(m < 0) h -= 1, m += 60;
    if(h < 0) h =23;
    cout << h << " " << m << endl;
}