프로그래머스
[3] 네트워크
#include #include using namespace std; bool vis[1000]{false}; void dfs(vector computers, int start) { vis[start] = true; for (int i = 0; i < computers[start].size(); i++) { if (!vis[i] && computers[start][i]) dfs(computers, i); } } int solution(int n, vector computers) { int answer = 0; for (int i = 0; i < n; i++) { if(!vis[i]) { dfs(computers, i); answer++; } } return answer; }
[3] 입국 심사
#include #include #include using namespace std; long long solution(int n, vector times) { long long min = 1, max = (long long)n * (*max_element(times.begin(), times.end())); long long answer = 0; while(min
[2] 오픈 채팅방
vector OpenChat(vector record) { vector answer, state; map user; for (int i = 0; i > token) str[index++] = token; if (str[0] == "Enter") { state.push_back("님이 들어왔습니다."); answer.push_back(str[1]); user[str[1]] = str[2]; } else if (str[0] == "Leave") { state.push_back("님이 나갔습니다."); answer.pus..
[3] N으로 표현
int answer = 9; int goal = 0; void cal(int n, int cnt, int sum) { if (cnt > 8) return; if (sum == goal && answer > cnt) answer = cnt; int tmp = 0; for (int i = 1; i 8) ? -1 : answer; }