반응형

알고리즘 11

가~위 바위~ 보!

코딩도장 - 가~위 바위~ 보! package may31; import java.util.Arrays; import java.util.Scanner; public class Test01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("몇판 하시겠습니까?");//게임 횟수 int input = sc.nextInt(); int[] result = new int[3];// 승무패 횟수 카운트 char[] result2 = new char[input];//승 무 패 결과값 저장 for(int i = 0; i < input; i++) { int input2; do { System.ou..

구글 입사 문제 중에서

코딩도장 - 구글 입사 문제 중에서 public class Main { public static void main(String[] args) { int[] N = new int[10000]; int count = 0; for (int i = 0; i < N.length; i++) { N[i] = i; // 값 대입용 if (N[i] % 10 == 8) { //System.out.println(i + " 1의 자리"); // 1의 자리 카운트 count++; } N[i] = N[i] / 10; if (N[i] % 10 == 8) { //System.out.println(i + " 10의 자리"); // 10의 자리 카운트 count++; } N[i] = N[i] / 10; if (N[i] % 10 == 8..

CamelCase를 Pothole_case로 바꾸기!

코딩 도장 CamelCase를 Pothole_case로 바꾸기 import java.util.Scanner; public class Camel2Pothole { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String word = sc.nextLine();//입력 for (int i = 0; i < word.length(); i++) { if(Character.isUpperCase(word.charAt(i))||Character.isDigit(word.charAt(i))){//대문자, 숫자 일시 System.out.print("_"+Character.toLowerCase(word.charAt(i)));// _삽..

타노스의 핑거 스냅

코딩도장 - 타노스의 핑거 스냅 import java.util.Arrays; public class Tanos { public static void main(String[] args) { int[] people = {2, 3, 1, 6, 5, 7, 8}; int ran = people.length/2; if(people.length%2==1) {//원소가 홀수라면 ran = (int) (Math.random()*2 + 1);// 1,2 절반 확률 if(ran%2==1) { ran = (people.length/2)+1;// 1일때 배열초기화 값 저장 System.out.println("1일때"); } else { ran = (people.length/2);// 2일때 배열초기화 값 저장 System.ou..

행렬의 덧셈

프로그래머스 - 행렬의 덧셈 class Solution { public int[][] solution(int[][] arr1, int[][] arr2) { int[][] answer = new int[arr1.length][arr1[0].length]; for (int i = 0; i < answer.length; i++) { for (int j = 0; j < answer[i].length; j++) { answer[i][j] = arr1[i][j] + arr2[i][j]; } } return answer; } } https://programmers.co.kr/learn/courses/30/lessons/12950 코딩테스트 연습 - 행렬의 덧셈 행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행..

x만큼 간격이 있는 n개의 숫자

프로그래머스 - x만큼 간격이 있는 n개의 숫자 class Solution { public long[] solution(int x, int n) { long[] answer = new long[n]; answer[0] = x; for(int i = 1; i < n; i++){ answer[i] +=answer[i-1]+x; } return answer; } } https://programmers.co.kr/learn/courses/30/lessons/12954 코딩테스트 연습 - x만큼 간격이 있는 n개의 숫자 함수 solution은 정수 x와 자연수 n을 입력 받아, x부터 시작해 x씩 증가하는 숫자를 n개 지니는 리스트를 리턴해야 합니다. 다음 제한 조건을 보고, 조건을 만족하는 함수, solutio..

반응형