알고리즘

[알고리즘] 백준 28702 - FizzBuzz (C++)

blueberrysoda 2024. 10. 2. 23:59

[문제 링크] : https://www.acmicpc.net/problem/28702

#include <iostream>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string A, B, C;
    cin >> A >> B >> C;
    
    if(C[0] >= 48 && C[0] <= 57){
        int x = stoi(C) + 1;
        if(x % 3 == 0){
            if(x % 5 == 0){
                cout << "FizzBuzz";
            }
            else{
                cout << "Fizz";
            }
        }
        else if(x % 5 == 0){
            cout << "Buzz";
        }
        else{
            cout << x;
        }
    }
    else if(B[0] >= 48 && B[0] <= 57){
        int x = stoi(B) + 2;
        if(x % 3 == 0){
            if(x % 5 == 0){
                cout << "FizzBuzz";
            }
            else{
                cout << "Fizz";
            }
        }
        else if(x % 5 == 0){
            cout << "Buzz";
        }
        else{
            cout << x;
        }
    }
    else if(A[0] >= 48 && A[0] <= 57){
        int x = stoi(A) + 3;
        if(x % 3 == 0){
            if(x % 5 == 0){
                cout << "FizzBuzz";
            }
            else{
                cout << "Fizz";
            }
        }
        else if(x % 5 == 0){
            cout << "Buzz";
        }
        else{
            cout << x;
        }
    }
    cout << "\n";
    return 0;
}