Programming Practice/SWEA
[SWEA] 1926. 간단한 369게임 - D2 (C++)
Cage
2022. 5. 26. 18:10
문제
* 해당 문제의 모든 저작권은 SWEA 측에 있으며 본 블로그는 학업 흔적을 남겨 학업 상향을 위한 블로그로 이익을 추구하지 않으며 SWEA 측의 약관을 위배하지 않음을 명시합니다.*
https://swexpertacademy.com/main/code/problem/problemList.do?
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
풀이
숫자를 문자열로, 문자열을 숫자로 바꾸는 방법을 알면 쉽게 풀 수 있다.
문자열에 3.6.9가 포함되었다면 그 숫자를 세어놓고 그만큼만 '-'를 출력하면 되는 문제이다
소스 코드
// Library
#include <iostream>
#include <string>
#include <stack>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <cctype>
#include <set>
#include <string.h>
#include <string>
// std::
using namespace std;
// Test_case
int T, test_case;
// Value
int N;
int arr[100][102];
// Matrix direction
//int dx[4] = { 0, 0, 1, -1 };
//int dy[4] = { 1, -1, 0, 0 };
// Sturct
//struct st {
//};
// Main function
int main() {
// cin, cout
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// SWEA 양식
T = 1;
// cin >> T;
for (test_case = 1; test_case <= T; test_case++) {
string str;
cin >> N;
for (int i = 1; i <= N; i++) {
string str;
int flag = 0;
str = to_string(i);
for (int i = 0; i < str.size(); i++) {
if (str[i] == '3' || str[i] == '6' || str[i] == '9')
flag++;
}
if (!flag)
cout << i << " ";
else {
for (int f = 0; f < flag; f++) {
cout << '-';
}
cout << " ";
}
}
//cout << "#" << test_case << " " << 1 << '\n';
}
return 0;
}