Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions 2024_2_Amicom_Algorithm.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/신채은/2주차" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/신채은/3주차" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/신채은/4주차" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
48 changes: 48 additions & 0 deletions 신채은/3주차/Baekjoon3/Stack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package Baekjoon3;

import java.util.List;
import java.util.ArrayList;

class Stack {

List<String> stack = new ArrayList<>();
String stackTop = "-1";

public void push(String item) {
stack.add(item);
stackTop = item;
}

public int pop() {

System.out.println(stackTop);

if(stackTop.equals("-1")) { //스텍에 들어있는게 없으므로 아래 과정 진행 X 리턴
return -1;
}
stack.remove(stack.size() - 1);
if (stack.size() == 0) {
stackTop = "-1"; //스텍 길이가 0이니까 top 초기화
} else {
stackTop = stack.get(stack.size() - 1);
}
return 0;
}

public void size() {
System.out.println(stack.size());
}

public void empty() {
if (stack.size() == 0) {
System.out.println(1);
} else {
System.out.println(0);
}
}

public void top() {
System.out.println(stackTop);
}

}
44 changes: 44 additions & 0 deletions 신채은/3주차/Baekjoon3/StackController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package Baekjoon3;

import java.util.Scanner;

public class StackController {
/*
정수를 저장하는 스택을 구현한 다음, 입력으로 주어지는 명령을 처리하는 프로그램을 작성하시오.
명령은 총 다섯 가지이다.

push X: 정수 X를 스택에 넣는 연산이다.
pop: 스택에서 가장 위에 있는 정수를 빼고, 그 수를 출력한다. 만약 스택에 들어있는 정수가 없는 경우에는 -1을 출력한다.
size: 스택에 들어있는 정수의 개수를 출력한다.
empty: 스택이 비어있으면 1, 아니면 0을 출력한다.
top: 스택의 가장 위에 있는 정수를 출력한다. 만약 스택에 들어있는 정수가 없는 경우에는 -1을 출력한다.*/

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
int commandCount = Integer.parseInt(sc.nextLine());

Stack stack = new Stack();

for (int i = 0; i < commandCount; i++) {
String command = sc.nextLine();
if (command.contains("push")) {
String item = command.split(" ")[1]; //공백을 기준으로 명령어와 입력값 구분
stack.push(item);
}else if (command.equals("pop")) {
stack.pop();
}else if(command.equals("size")) {
stack.size();
}
else if (command.equals("empty")) {
stack.empty();
}else if (command.equals("top")) {
stack.top();
}else{
System.out.println("스택에 해당 명령이 없습니다.");
System.exit(1);
}
}
}

}
57 changes: 57 additions & 0 deletions 신채은/3주차/Baekjoon4/Queue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package Baekjoon4;

import java.util.ArrayList;
import java.util.List;

class Queue {
List<String> queue = new ArrayList<>();
String queueFront = "-1";
String queueBack = "-1";

public void push(String item) {
queue.add(item);
if(queueFront.equals("-1")) { //큐에 아무것도 들어오지 않은 경우
queueFront = item;
}
queueBack = item;
}

public int pop() {

System.out.println(queueFront);

if(queueFront.equals("-1")) { //들어있는게 없으므로 아래 과정 진행 X 리턴
return -1;
}

queue.remove(0);

if (queue.size() == 0) {
queueFront = "-1"; //길이가 0이니까 초기화
queueBack = "-1";
} else {
queueFront = queue.get(0);
}
return 0;
}

public void size() {
System.out.println(queue.size());
}

public void empty() {
if (queue.size() == 0) {
System.out.println(1);
} else {
System.out.println(0);
}
}

public void front() {
System.out.println(queueFront);
}

public void back() {
System.out.println(queueBack);
}
}
48 changes: 48 additions & 0 deletions 신채은/3주차/Baekjoon4/QueueController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package Baekjoon4;

import Baekjoon4.Queue;
import java.util.Scanner;
/*
정수를 저장하는 큐를 구현한 다음, 입력으로 주어지는 명령을 처리하는 프로그램을 작성하시오.

명령은 총 여섯 가지이다.

push X: 정수 X를 큐에 넣는 연산이다.
pop: 큐에서 가장 앞에 있는 정수를 빼고, 그 수를 출력한다. 만약 큐에 들어있는 정수가 없는 경우에는 -1을 출력한다.
size: 큐에 들어있는 정수의 개수를 출력한다.
empty: 큐가 비어있으면 1, 아니면 0을 출력한다.
front: 큐의 가장 앞에 있는 정수를 출력한다. 만약 큐에 들어있는 정수가 없는 경우에는 -1을 출력한다.
back: 큐의 가장 뒤에 있는 정수를 출력한다. 만약 큐에 들어있는 정수가 없는 경우에는 -1을 출력한다.
*/

public class QueueController {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
int commandCount = Integer.parseInt(sc.nextLine());

Queue queue = new Queue();

for (int i = 0; i < commandCount; i++) {
String command = sc.nextLine();
if (command.contains("push")) {
String item = command.split(" ")[1]; //공백을 기준으로 명령어와 입력값 구분
queue.push(item);
} else if (command.equals("pop")) {
queue.pop();
} else if (command.equals("size")) {
queue.size();
} else if (command.equals("empty")) {
queue.empty();
} else if (command.equals("front")) {
queue.front();
} else if (command.equals("back")) {
queue.back();
} else {
System.out.println("스택에 해당 명령이 없습니다.");
System.exit(1);
}
}
}
}
Loading