Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package baekjoon.basic; | ||
|
||
import java.util.Scanner; | ||
|
||
public class 최대공약수와최소공배수 { | ||
|
||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
|
||
int a = sc.nextInt(); | ||
int b = sc.nextInt(); | ||
|
||
int gbc = gbc(a, b); | ||
int lcm = lcm(a, b); | ||
|
||
System.out.println(gbc); | ||
System.out.println(lcm); | ||
} | ||
|
||
private static int gbc(int a, int b) { | ||
if (a < b) { | ||
int temp = a; | ||
a = b; | ||
b = temp; | ||
} | ||
|
||
while(b != 0) { | ||
int r = a % b; | ||
a = b; | ||
b = r; | ||
} | ||
|
||
return a; | ||
} | ||
|
||
private static int lcm(int a, int b) { | ||
return a * b / gbc(a, b); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package baekjoon.datastructure; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
|
||
public class 카드2 { | ||
public static void main(String[] args) { | ||
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { | ||
int n = Integer.parseInt(br.readLine()); | ||
Queue<Integer> que = new LinkedList<>(); | ||
|
||
for (int i = 1; i <= n; i++) { | ||
que.offer(i); | ||
} | ||
|
||
while (que.size() != 1) { | ||
que.poll(); | ||
|
||
que.offer(que.poll()); | ||
} | ||
|
||
System.out.println(que.poll()); | ||
|
||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package baekjoon.implementation; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class 음계 { | ||
public static void main(String[] args) { | ||
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { | ||
String[] arr = br.readLine().split(" "); | ||
String result = arr[0].equals("1") ? "ascending" : "descending"; | ||
|
||
for (int i = 1; i < 8; i++) { | ||
int first = Integer.parseInt(arr[i - 1]); | ||
int second = Integer.parseInt(arr[i]); | ||
|
||
if (first + 1 == second) { | ||
result = "ascending"; | ||
} else if (second + 1 == first) { | ||
|
||
result = "descending"; | ||
} else { | ||
result = "mixed"; | ||
break; | ||
} | ||
} | ||
|
||
System.out.println(result); | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package baekjoon.implementation; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
|
||
public class 팰린드롬수 { | ||
|
||
public static void main(String[] args) { | ||
try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out))) { | ||
String k = br.readLine(); | ||
while (!k.equals("0")) { | ||
String[] arr = k.split(""); | ||
int i = 0; | ||
int j = arr.length - 1; | ||
|
||
while(i <= arr.length - 1 || j >= 0) { | ||
if (i >= j) { | ||
bw.write("yes\n"); | ||
break; | ||
} | ||
|
||
if (!arr[i].equals(arr[j])) { | ||
bw.write("no\n"); | ||
break; | ||
} | ||
|
||
i++; | ||
j--; | ||
} | ||
k = br.readLine(); | ||
} | ||
|
||
bw.flush(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package baekjoon.sort; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class 수찾기 { | ||
public static void main(String[] args) { | ||
try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { | ||
int n = Integer.parseInt(br.readLine()); | ||
Map<String, Integer> map = new HashMap<>(); | ||
|
||
String[] in = br.readLine().split(" "); | ||
|
||
for (String s : in) { | ||
map.put(s, 0); | ||
} | ||
|
||
int m = Integer.parseInt(br.readLine()); | ||
String[] inputMArray = br.readLine().split(" "); | ||
|
||
List<String> inputMList = new ArrayList<>(Arrays.asList(inputMArray)); | ||
|
||
for(String num : inputMList) { | ||
if (map.containsKey(num)) { | ||
System.out.println("1"); | ||
} else { | ||
System.out.println("0"); | ||
} | ||
} | ||
|
||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |