끄적끄적 코딩
article thumbnail
Published 2023. 1. 11. 22:51
[C++] SWEA - 간단한 369게임 알고리즘

숫자를 차례대로 출력합니다. 3 6 9 게임의 규칙에 따라 박수는 '-'로 대체해서 출력합니다.

#include<iostream>
#include<string>
using namespace std;
int main(int argc, char** argv)
{
    int n;
    int count;
    string s;
     
    cin >> n;
     
    for(int i=1; i<=n; ++i){
        count = 0;
        s = to_string(i);
        for(int j=0; j<s.size(); ++j){
            if(s[j] == '3' || s[j] == '6' || s[j] == '9'){
                ++count;
            }   
        }
        if(count > 0){
            for(int k=0; k<count; ++k){
                cout << "-";   
            }
        } else {
            cout << s;
        }
        cout << " ";
    }
    return 0;
}

검색 태그