알고리즘/SWEA
[SWEA] 1926. 간단한 369게임
hyerann
2019. 4. 17. 14:47
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
www.swexpertacademy.com
정수를 문자열로 바꿔주는 to_string() 함수를 알고 있어야 풀 수 있는 문제이다.
* string to int, int to string 변환 함수
string to int | int to string |
atoi(char*) | to_string(int) |
string str = "123"; int num = atoi(str.c_str()); |
int num = 123; string str = to_string(num); |
#include <iostream>
#include <ios>
#include <string>
using namespace std;
int N;
void game369();
int main() {
cin.tie(0); ios::sync_with_stdio(0);
cin >> N;
game369();
return 0;
}
void game369() {
for (int i = 1; i <= N; i++) {
string number = to_string(i);
int clapCnt = 0;
for (int j = 0; j < number.length(); j++) {
if (number[j] == '3' || number[j] == '6' || number[j] == '9') clapCnt++;
}
if (clapCnt) {
number = "";
for (int clap = 0; clap < clapCnt; clap++) {
number += '-';
}
}
cout << number << ' ';
}
}