Skip to content
Merged
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
56 changes: 56 additions & 0 deletions Basic_Of_Algorithm/src/programmers_level_01/crain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package programmers_level_01;

import java.util.Stack;

public class crain {

public static void main(String[] args) {

int[][] board = {{0,0,0,0,0},{0,0,1,0,3},{0,2,5,0,1},{4,2,4,4,2},{3,5,1,3,1}};
int [] moves = {1,5,3,5,1,2,1,4};

int answer = 0;

Stack<Integer> stack = new Stack<>();


for(int mov : moves) {

mov--;

for(int i=0;i<board.length;i++) {

if(board[i][mov]!=0) {
if(stack.isEmpty()) {
stack.add(board[i][mov]);
board[i][mov] = 0;
break;
}
else {
if(stack.peek()==board[i][mov]) {
stack.pop();
answer++;
}else {
stack.add(board[i][mov]);
}
board[i][mov] = 0;
break;
}

}

}


}



System.out.println(answer*2);




}

}
38 changes: 38 additions & 0 deletions Basic_Of_Algorithm/src/programmers_level_2/change.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package programmers_level_2;

import java.util.*;

public class change {

public static void main(String[] args) {

String [][] clothes = {{"yellowhat", "headgear"}, {"bluesunglasses", "eyewear"}, {"green_turban", "headgear"}};
int answer = 1;

HashMap<String,ArrayList<String>> map = new HashMap<>();

for(int i=0;i<clothes.length;i++) {

String first = clothes[i][0];
String second = clothes[i][1];

if(!map.containsKey(second)) map.put(second, new ArrayList<>());

map.get(second).add(first);

}



for(String key : map.keySet()) {

answer *= map.get(key).size()+1;
}



System.out.println(answer-1);


}
}