Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

개발 공부

369게임 본문

코딩 테스트 준비/c++

369게임

방구석개발입문 2022. 11. 12. 00:47
#include<iostream>
 
using namespace std;
 
int main()
{
    int x,count;
    cin >> x;
    
    for(int i=1; i<=x; i++)
    {
        string s= to_string(i);
        count=0;
        
        for(int j=0; j<s.size(); j++)               //자릿수마다 확인
        {
            if(s[j] == '3' || s[j] == '6'|| s[j] == '9')
                count++;
        }
        
        if (count == 0)
            cout << i;
        else 
            for(int j=0; j<count; j++)
                cout<<"-";
            
        cout <<" ";
    }
    
}

to_string을 이용해 int => string으로 변환해준다.

 

s.size()를 이용해 자릿수마다 369인지를 확인한다!