가장 큰 수 0 또는 양의 정수가 주어졌을 때, 정수를 이어 붙여 만들 수 있는 가장 큰 수를 알아내 주세요. 예를 들어, 주어진 정수가 [6, 10, 2]라면 [6102, 6210, 1062, 1026, 2610, 2106]를 만들 수 있고, 이중 가장 큰 수는 6210입니다. 0 또는 양의 정수가 담긴 배열 numbers가 매개변수로 주어질 때, 순서를 재배치하여 만들 수 있는 가장 큰 수를 문자열로 바꾸어 return 하도록 solution 함수를 작성해주세요. 제한 사항 numbers의 길이는 1 이상 100,000 이하입니다. numbers의 원소는 0 이상 1,000 이하입니다. 정답이 너무 클 수 있으니 문자열로 바꾸어 return 합니다. 입출력 예 numbersreturn [6, 10, ..

전체 글
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String str = sc.next(); System.out.println(solution(n, str)); sc.close(); } private static String solution(int n, String str) { String answer = ""; for(int i = 0; i
첫번째 어렵게 생각해서 푼 방법 public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); calc(str); sc.close(); } private static void calc(String str) { String str1 = ""; int k = 0; for(int i = 0; i0) { if(s.equals(str.charAt(i-1)+"")) { continue; } } k = 0; for(int j = i+1; j0) { str1 += (k+1)+""; } } System.out.println(str1); } 풀이 1. 문자열을 입력받고 2. 중복된 문자를 세는 k 변수,..
import java.util.Scanner; /* 한 개의 문자열 s와 문자 t가 주어지면 문자열 s의 각 문자가 문자 t와 떨어진 최소거리를 출력하는 프로그램을 작성하세요. */ public class Short2 { public static int [] solution(String s, char t) { int[]answer = new int[s.length()]; int p = 1000; for(int i = 0; i=0; i--) { if(s.charAt(i)==t) { p = 0; }else { p++; answer[i] = Math.min(answer[i], p); } } return answer; } public static void main(String[] args) { Scanner s..
import java.util.Scanner; public class Number { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); String num = "0123456789"; String answer = ""; sc.close(); for(int i = 0; i
public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); // 여러 개의 문자 한줄씩 읽어야 함. sc.close(); System.out.println(solution(str)); } public static String solution(String s) { String answer = "NO"; s = s.toUpperCase().replaceAll("[^A-Z]", ""); // 대문자 A~Z까지가 아니면 (^ -> 부정) ""로 replace 정규식 //System.out.println(s); String tmp = new StringBuilder(s).reverse..