문제: 6603번: 로또
basic-algo-lecture/workbook/0x0C.md at master · encrypted-def/basic-algo-lecture
basic-algo-lecture/workbook/0x0C.md at master · encrypted-def/basic-algo-lecture
바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.
github.com
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip> // setprecision을 사용하기 위한 헤더
#include <climits>
#include <list>
#include <sstream>
using namespace std;
int k;
int S[12]; // max 가 12 임
int curNums[6]; // 로또는 6개 골라야함
int visit[50]; // 방문 처리
void Funct(int n, int prev) {
if (n == 6) {
for (int i = 0; i < 6; i++)
cout << curNums[i] << " ";
cout << "\n";
return;
}
for (int i = 0; i < k; i++) {
// 만약 이미 방문했거나, 이전 값보다 작다면 패스!
if (visit[S[i]] == 1 || prev > S[i]) continue;
// 방문한 곳이 아니라면
visit[S[i]] = 1; // 방문 표시
curNums[n] = S[i];
Funct(n + 1, S[i]);
visit[S[i]] = 0; // 방문 표시 없애기
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
while (true) {
// 입력 처리
string input;
getline(cin, input); // 한 줄 입력 받기
if (input == "0") break;
istringstream iss(input);
iss >> k;
for (int i = 0; i < k; i++) {
iss >> S[i];
}
sort(S, S + k); // 배열 정렬
// 이제 백트래킹..;
Funct(0, 0);
cout << "\n";
}
return 0;
}
참고자료:
문자열 파싱 함수 - istringstream, ostringstream, stringstream — My IT Study
문자열 파싱 함수 - istringstream, ostringstream, stringstream
오늘은 2021 카카오 블라인드 문제를 풀며 사용했던 문자열 파싱 함수 세 가지에 대해서 포스팅하려고 한다. 세 함수는 모두 sstream 헤더에 포함되어 있다. 1. istringstream string을 입력받아 다른 형식
myprivatestudy.tistory.com
아니 istringstream 쓰니까 문자열 처리가 너무 쉽다. 계속 기억해놓고 이 문제처럼 입력 주어지면 쓰자!!!