[C++] 프로그래머스 전화번호 목록 해시
·
Algorithm/Programmers
효율성 3, 4실패 코드 더보기 #include #include #include using namespace std; bool solution(vector phone_book) { bool answer = true; for(int i = 0; i < phone_book.size(); i++) //지정된 전화번호 { int counts = 0; for(int j = 0; j < phone_book.size(); j++) //비교할 전화번호 { if(i == j) continue; //비교할 것이 같으면 패스 for(int k = 0; k < phone_book[i].size(); k++) //지정된 전화번호길이만큼 비교 { if(phone_book[i][k] != phone_book[j][k]) //비교하..
[C++] 프로그래머스 완주하지 못한 선수 해시
·
Algorithm/Programmers
#include #include #include using namespace std; string solution(vector participant, vector completion) { string answer = ""; map partNames; map compNames; for(int i = 0; i < participant.size(); i++) partNames[participant[i]]++; for(int i = 0; i < completion.size(); i++) compNames[completion[i]]++; for(auto iter : compNames) { partNames[iter.first] -= iter.second; } for(auto iter : partNames) { i..
[C++] 프로그래머스 카펫 완전탐색
·
Algorithm/Programmers
#include #include using namespace std; vector solution(int brown, int yellow) { vector answer; for(int i = 6; i = 1이고 2 * 1이 yellow와 같기 때문에 답이므로 answer에 x길이 (i / 2)와 y의 길이 (j / 2 + 2)를 넣어주면 정답이 나온다.
[C++] 프로그래머스 소수찾기 완전탐색
·
Algorithm/Programmers
#include #include #include using namespace std; int solution(string numbers) { int answer = 0; sort(numbers.rbegin(), numbers.rend()); int num = stoi(numbers); vector visited(num + 1, false); for(int i = 2; i
[C++] 프로그래머스 모의고사 완전탐색
·
Algorithm/Programmers
#include #include #include using namespace std; vector solution(vector answers) { vector answer; int counts[3]{0}; int tester1[5] = {1,2,3,4,5}; int tester2[8] = {2,1,2,3,2,4,2,5}; int tester3[10] = {3,3,1,1,2,2,4,4,5,5}; for(int j = 0; j < answers.size(); j++) { if(tester1[j % 5] == answers[j]) counts[0]++; if(tester2[j % 8] == answers[j]) counts[1]++; if(tester3[j % 10] == answers[j]) counts[2..
루프의 순서도
·
C++/Basic
#include #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int j = 5; for(j; j