import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); if(3
어려운 알고리즘 문제 풀다가 심심풀이로 풀어보았습니다... ', '를 입력받기 때문에 split을 이용하면 되겠다 싶었고, String을 int형으로 변환하기 위해서는 Integer.parseInt(String)을 이용하면 되겠다 싶어 아래와 같이 코드를 짜보았습니다. import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); String[] sarr; int tot; for(int i=0; i
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int i = 0; i < T; i++) { int k = sc.nextInt(); int n = sc.nextInt(); System.out.println(howManyPeople(k, n)); } } public static int howManyPeople(int k, int n) { // 제한은 1
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int i=0; i
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); // 낮에 올라갈 수 있는 거리 int b = sc.nextInt(); // 밤에 내려가는 거리 int v = sc.nextInt(); // 나무막대의 높이 int tot = a-b; // 하루에 이동하는 거리 // 정상에 올라간 후에는 미끄러지지 않는다고 했기 때문에 // v에서 a 거리를 먼저 빼주고 계산 v = v - a; // 위에서 마지막 하루 이동하는 거리를 빼고 계산했기 때문에 결과에 하루를 더해줌. // 딱 나누어 떨어질 경우에는 +1 if(v ..
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x= sc.nextInt(); int tmp=0, cross_line=0; // 대각선 줄로 보면 줄하나가 생길때마다 원소가 1개씩 늘어나는 걸 볼 수 있음 // 대각선 줄 구하는 방법 for(int i=1; i= x) { cross_line=i; break; } } // 대각선 줄이 홀수/짝수 개수일 때 해당하는 원소 값 구하는 방법 if(cross_line % 2 == 1) System.out.println((1+tmp-x) + "/" + (cross_line-(tmp-x))); else..
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int count = 1; // 칸수 세는 count int range = 1; // 범위는 1부터 시작 int increase = 1; // 6의 배수만큼 범위를 올리기위해서 사용 // // 범위 // // 1 -> 1 1 1 // // 2~7 -> 2 1 6 // // 8~19 -> 3 6 12 // // 20~37 -> 4 12 18 // // 38~61 -> 5 18 24 while (range < n) { increase = (count++) * 6;..
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // overflow 가 나서 int -> long으로 변환 long a = sc.nextInt(); // 고정 long b = sc.nextInt(); // 재료 long c = sc.nextInt(); // 수입 long count = 0; // c * count = a + b * count 일 때 // 방정식으로 바꾸게되면 c * count - b * count = a // (c - b) * count = a // count = a / (c - b) // 수입이 재료보다 적으면 -1 출력 if..
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 단어의 개수를 입력받기 int n = sc.nextInt(); int count = 0; for (int i = 0; i < n; i++) { String s = sc.next(); // checker(s)가 true 인 경우에만 count if (checker(s)) { count++; } } System.out.println(count); } public static boolean checker(String s) { // 이전 문자를 나타내는 previous int previous = 0;..
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int count = 0; char[] c = new char[s.length()]; for (int i = 0; i < s.length(); i++) { c[i] = s.charAt(i); } // 크로아티아 문자 하나 = 알파벳 2글자이지만 1글자로 센다는 가정하에 // i가 n씩 증가한만큼 건너뛰기 때문에 count를 할 수 있음 for (int i = 0; i < s.length(); i++) { if (c[i] == 'c') { // IndexOuto..