반응형

import java.util.Scanner;

public class Main {

	static int[] a_cards = new int[10];
	static int[] b_cards = new int[10];
	static int answer_a = 0;
	static int answer_b = 0;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		
		for(int i=0;i<10;i++){
			a_cards[i] = sc.nextInt();
		}
		
		for(int i=0;i<10;i++) {
			b_cards[i] = sc.nextInt();
		}
		
		PlayGame();
		
		System.out.println(GetAnswer());
	}
	
	public static void PlayGame(){
		for(int i=0;i<10;i++) {
			if(a_cards[i] > b_cards[i]) {
				answer_a++;
			} else if(a_cards[i] < b_cards[i]) {
				answer_b++;
			}
		}
	}
	
	public static String GetAnswer() {
		if(answer_a > answer_b) return "A";
		else if(answer_b > answer_a) return "B";
		else return "D";
	}
}
반응형

'알고리즘 > Baekjoon' 카테고리의 다른 글

[Baekjoon] #9465 스티커  (0) 2024.04.08
[Baekjoon] #10250 ACM 호텔  (0) 2024.04.08
[Baekjoon] #10809 알파벳 찾기  (0) 2024.04.08
[Baekjoon] #11725 트리의 부모 찾기  (0) 2024.04.08
[Baekjoon] #6359 만취한 상범  (0) 2024.03.08
반응형

 

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String[] alpha = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
		
		for(int i=0;i<alpha.length;i++) {
			System.out.print(s.indexOf(alpha[i]) + " ");
		}
	}

}
반응형

'알고리즘 > Baekjoon' 카테고리의 다른 글

[Baekjoon] #10250 ACM 호텔  (0) 2024.04.08
[Baekjoon] #10801 카드게임  (0) 2024.04.08
[Baekjoon] #11725 트리의 부모 찾기  (0) 2024.04.08
[Baekjoon] #6359 만취한 상범  (0) 2024.03.08
[Baekjoon] #2573 빙산  (0) 2022.07.14
반응형

 

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int n;
	static int[] visit;
	static int[] parent;
	static ArrayList<Integer>[] ar;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		
		n = sc.nextInt();
		ar = new ArrayList[n+1];
		visit = new int[n+1];
		parent= new int[n+1];
		
		for(int i=1;i<=n;i++) {
			ar[i] = new ArrayList<Integer>();
		}
		
		for(int i=1;i<n;i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			ar[x].add(y);
			ar[y].add(x);
		}

		for(int i=1;i<=n;i++) {
			if(visit[i] == 0) {
				getDfs(i);
			}
		}
		
		for(int i=2;i<=n;i++) {
			System.out.println(parent[i]);
		}
	}
	
	public static void getDfs(int node) {
		if(visit[node] == 1) return;
		
		visit[node] = 1;
		
		for(int y : ar[node]) {	
			if(visit[y] == 0) {
				parent[y] = node;
				getDfs(y);
			}
		}
	}
}
반응형

'알고리즘 > Baekjoon' 카테고리의 다른 글

[Baekjoon] #10801 카드게임  (0) 2024.04.08
[Baekjoon] #10809 알파벳 찾기  (0) 2024.04.08
[Baekjoon] #6359 만취한 상범  (0) 2024.03.08
[Baekjoon] #2573 빙산  (0) 2022.07.14
[Baekjoon] #7562 나이트의 이동  (0) 2022.07.06
반응형

덧칠하기 : 연습문제 Lv.1

 

https://school.programmers.co.kr/learn/courses/30/lessons/161989

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

def solution(n, m, section):
    answer = 0
    
    while section:
        paint = section[0]
        
        while section and section[0] < paint+ m:
            section.pop(0)
        answer+=1
    
    return answer
반응형

'알고리즘 > 프로그래머스' 카테고리의 다른 글

완주하지 못한 선수  (0) 2024.04.06
둘만의 암호  (0) 2024.04.06
게임 맵 최단거리  (0) 2024.04.06
JadenCase 문자열 만들기  (0) 2024.04.06
최댓값과 최솟값  (0) 2024.03.27
반응형

완주하지 못한 선수: 해시 Lv.1

 

https://school.programmers.co.kr/learn/courses/30/lessons/42576

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

import java.util.HashMap;

class Solution {
    public String solution(String[] participant, String[] completion) {
        String answer = "";
        
       	HashMap<String, Integer> map = new HashMap<>();
		
		for(int i=0, l=participant.length;i<l;i++) {
			String key = participant[i];
			map.put(key, map.getOrDefault(key, 0)+1);
		}
		
		for(int i=0, l=completion.length;i<l;i++) {
			String key = completion[i];
			map.replace(key, map.get(key)-1);
		}
		
		return map.entrySet().stream().filter(e->e.getValue()==1).findFirst().get().getKey();
    }
}
반응형

'알고리즘 > 프로그래머스' 카테고리의 다른 글

덧칠하기  (0) 2024.04.06
둘만의 암호  (0) 2024.04.06
게임 맵 최단거리  (0) 2024.04.06
JadenCase 문자열 만들기  (0) 2024.04.06
최댓값과 최솟값  (0) 2024.03.27

+ Recent posts