본문 바로가기

반응형

알고리즘

(22)
문제 ID : CLOCKSYNC, 난이도: 중 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 package main; import java.util.ArrayList; import java.util.Scanner; public class MainClass { final static int INF = 9999; final static int SWITCHES = 10; final stat..
예제 : 여행하는 외판원 어떤 나라에 n(2
문제 ID : BOARDCOVER , 난이도: 하 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 package test; import java.util.Scanner; public class test{ public static void main(String[] args) { int board[][]; Scanner scanner = new Scanner(System.in); int test = scanner.nextInt(); for(int i = 0..
문제 ID : PICNIC, 난이도: 하 picnic 소풍 항상 친구인 학생들 끼리만 짝을 지어주는 프로그램 /* 테스트 케이스 : C 학생 수 : N 학생 짝의 수 : M 서로 친구인 학생 쌍이 주어진다. */ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include using namespace std; int dfs(int taken[11]); int dfs2(int taken[11]); int taken[11] = {0,}; int checkFriend[11][11] = {0,}; int C,N,M = 0; int main(){ cin >> C; for(int i = 0; i > N >> M; for(int j = 0; j > friend1 >> friend..
[백준-1764] 듣보잡 문자열을 입력받고 같은 문자열의 개수를 찾는 프로그램 n : 듣도 못한 사람의 수 m : 보도 못한 사람의 수 입력값 2 3 hduck Amgay dora2 ada hduck 출력값 1 hduck 문자열을 sort()를 이용해서 정렬을 한다. 정렬후 순차적으로 하나씩 비교하여 같은 문자열의 개수를 카운트한다. function(std::vector vec;) meaning vec.begin() iterator pointing to the first element.(첫번째 원소의 위치) vec.end() iterator pointing to next to last element.(마지막 원소 다음의 위치를 말한다) vec.push_back(value) 벡터의 가장 마지막 위치에 value를 추가 vec.po..
[백준 - 1924] 2007년 1/1 월요일이다 month월 day일은 무슨요일인지를 출력하라. 입력 1 1 출력 MON 요일은 7일마다 반복된다. ex) 1/1 월요일, 1/8 월요일 hint. 1/18일은 총 일수를 따지면 18일이고 18%7 = 4 1/8 월요일 8%7 = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include #include #include int findFirstDay(int M) { int days = 0; for (int month = 0; month > month >> day; int flag = (findFirstDay(month) + day) % 7 - 1; if (flag > day; int..
[백준 - 2798] 블랙잭 카드 3장을 뽑아서 더한 값이 M보다 작거나 같고 M과 가장 가까운 수를 찾는 게임이다. 입력값 => N : 카드의 갯수, M : 3개 카드를 더해서 넘지 말아야 할 수 카드의 원소 EX) 입력 5 21 5 6 7 8 9 출력 21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #include int blackJack1(int numOfinput, int maxNum){ int *a = new int [numOfinput]; int sum = -1; for(int i = 0; i > a[i]; } for(int i = 0; i
[LeetCode] Roman to Integer Roman numerals Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 위의 Sybol이 주어지면 Symbol과 숫자를 대응하여 계산한 값을 구하는 알고리즘이다. 계산 규직은 다음과 같다. 자신의 다음에 있는 Symbol의 Value가 자신의 Value보다 더 크다면 자기자신은 -연산을 하고 반대의 경우에는 +연산을 한다. EX) input : "III" output : "3" input : "IV" output : "4" input : "IX" output : "9" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 class Solution { public int romanToInt(String s) { int[] map..

반응형