숫자를 차례대로 출력합니다. 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;
}
'알고리즘' 카테고리의 다른 글
[Java] SWEA - 최장 증가 부분 수열 (0) | 2023.01.12 |
---|---|
[Java] SWEA - 햄버거 다이어트 (0) | 2023.01.12 |
[Java] SWEA - 스도쿠 검증 (0) | 2023.01.11 |
[Java] SWEA - 원재의 메모리 복구하기 (0) | 2023.01.11 |
[JavaScript] 프로그래머스 - 크레인 인형뽑기 게임 (0) | 2021.09.16 |