본문 바로가기

코딩테스트/프로그래머스22

[Level 1] 자연수 뒤집어 배열로 만들기 class Solution { public int[] solution(long n) { String s =""+n; //String에 n 추가 int[] answer = new int[s.length()];//입력받은 숫자의 길이만큼 int cnt=0; while(n>0) { answer[cnt]=(int)(n%10);//12345 -> 나머지 5 -> 4 -> 3 -> 2 ->1 n/=10; // n=1234 -> 123 -> -> 12 -> 1 cnt++; } return answer; } } 2022. 8. 11.
[Level 1] 시저 암호 class Solution { public String solution(String s, int n) { String answer = ""; for(int i=0; i E if((6496 && ne122) ? (char)(ne+n-122+96) : (char)(ne+n); } } return answer; } } /* 1. 문자열에서 하나씩 검사 split("") 2. 문자의 개수만큼 반복문을 돌림 3. 문자의 아스키코드값으로 변환하여 n만큼 이동 4. 문자를 합친다. */ /* 문자를 ASCII 코드로 바꾸기 char형을 (int) 강제 형 변환 아스키 코드에서 대문자번호와 소문자번호만 구별할 수 있어야함 A = 65 Z = 90 a = 97 z = 122 */ 2022. 8. 11.
[Level 1] 로또의 최고 순위와 최저 순위 import java.util.*; class Solution { public int solution(String dartResult) { int answer = 0; double[] result = new double[3]; //다트 기회는 3번 String[] c = dartResult.split(""); //각 문자별 구별 int num=0; for(int i=0; i1&&c[i-2].equals("1")&&c[i-1].equals("0")) result[num-1] = 10; //숫자 10 구별 break; case "D": result[num++]=Math.pow(Integer.parseInt(c[i-1]), 2); if(i>1&&c[i-2].equals("1")&&c[i-1].equals("0.. 2022. 8. 11.
[Level 1] 로또의 최고 순위와 최저 순위 class Solution { public int[] solution(int[] lottos, int[] win_nums) { int[] answer = new int[2]; // 0인 경우 다 맞거나, 다틀리거나 int count=0; for(int z=0; z 2022. 8. 11.