본문 바로가기

알고리즘

1169 : 주사위 던지기1 import java.util.Scanner; public class Main { static int n, m; static int arr[] = new int [101]; public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); n = scan.nextInt(); m = scan.nextInt(); if (m == 1) { dice1(1); } else if (m == 2) { dice2(1, 1); } else if (m == 3) { dice3(1); } } private static void dice1(int level) { int i; if (lev.. 더보기
1309 : 팩토리얼 import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int n; int i, j; n = scan.nextInt(); long res = f(n); System.out.println(res); } private static long f(int a) { if (a 더보기
1158 : 삽입정렬 import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int n, i, j; int arr[] = new int[101]; n = scan.nextInt(); for (i = 0; i 0; j--) { if (arr[j] < arr[j - 1]) { int c = arr[j]; arr[j]=arr[j-1]; arr[j-1]=c; }.. 더보기
1697 : 큐(queue) import java.util.Scanner; public class Main { static int queue[] = new int [101]; static int f; static int r; public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int i, j, n = 0; String arr; int number[] = new int [101]; n = scan.nextInt(); for (i = 0; i < n; i++) { arr = scan.next(); if (arr.charAt(0) == 'i') { int num = scan.nextIn.. 더보기
3427 : 볼 모으기(balls) import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int n; String arr; int i, j; n = scan.nextInt(); arr= scan.next(); int red = 0, blue = 0; int rs = 0, bs = 0; int re=0,be=0; for (i = 0; i < n; i++) { if (arr.charAt(i) == 'R') { red++; } else { blue++; } } for (i = 0;.. 더보기
1761 : 숫자 야구 import java.util.Scanner; public class Main { public static class Baseball{ int num; int strick; int ball; public Baseball() {} public Baseball(int num,int strick,int ball) { this.num = num; this.strick=strick; this.ball =ball; } } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int n; Scanner sc = new Scanner(System.in); n = sc.nextInt(); Baseball[.. 더보기
1031 : 빙고 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Main { public static int saheja[][] = new int [6][6]; public static int bingopan[][] = new int [6][6]; public static int bingocnt = 0; public static void main(String[] args) throws IOException.. 더보기
1733 : 오목 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Main { static int badukpan[][] = new int [30][30]; static int type; public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader in = new Buffe.. 더보기