Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[week4] 백준 10804번 문제 #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.

11 changes: 11 additions & 0 deletions .idea/ObjectJava.iml

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.

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.

Binary file added out/production/ObjectJava/CardDeck.class
Binary file not shown.
Binary file added out/production/ObjectJava/Main.class
Binary file not shown.
50 changes: 50 additions & 0 deletions week4/지선의/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.util.Scanner;

//백준 10804번
class CardDeck { //카드 상태 관리하는 클래스
private int[] cards; // 카드 상태 저장 배열

public CardDeck() {
cards = new int[20];
for (int i = 0; i < 20; i++) {
cards[i] = i + 1;
}
}

public void reverseRange(int start, int end) { //주어진 범위(start부터 end까지)의 카드를 뒤집음
// start와 end는 1-based 인덱스이므로, 0-based로 변환
start--;
end--;

while (start < end) {
int temp = cards[start];
cards[start] = cards[end];
cards[end] = temp;
start++;
end--;
}
}

public void printDeck() {
for (int card : cards) {
System.out.print(card + " ");
}
System.out.println();
}
}

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
CardDeck deck = new CardDeck();

for (int i = 0; i < 10; i++) {
int start = sc.nextInt();
int end = sc.nextInt();
deck.reverseRange(start, end);
}

deck.printDeck();
sc.close();
}
}