코딩 테스트 준비/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인지를 확인한다!