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
101 changes: 66 additions & 35 deletions Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,69 @@ public class no_1249 {



public static void main(String[] args) throws Exception {


BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T;
T=Integer.parseInt(br.readLine());

for(int test_case = 1; test_case <= T; test_case++){

int n = Integer.parseInt(br.readLine());

int [][]map = new int[n+2][2];
boolean[] check = new boolean[n+2];
int[]result = new int[n+2];

int min = Integer.MAX_VALUE;
map[0][0] = Integer.parseInt(br.readLine());
map[0][1] = Integer.parseInt(br.readLine());
map[n+1][0] = Integer.parseInt(br.readLine());
map[n+1][1] = Integer.parseInt(br.readLine());

for(int i=0;i<=n;i++) {
map[i][0] = Integer.parseInt(br.readLine());
map[i][1] = Integer.parseInt(br.readLine());

}




}

}

}
public static void main(String args[]) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T;
T=Integer.parseInt(br.readLine());

for(int test_case = 1; test_case <= T; test_case++){

int size =Integer.parseInt(br.readLine());

int[][]map = new int[size][size];

int answer = Integer.MAX_VALUE;


for(int i=0;i<size;i++) {
String s = br.readLine();
for(int j=0;j<size;j++) {
map[i][j] = Integer.parseInt(""+s.charAt(j));
}
}

Queue<int[]> q = new LinkedList<>();

int[][]mov = {{1,0},{0,1},{-1,0},{0,-1}};
int[][]temp = new int[size][size];
boolean[][]visited = new boolean[size][size];
q.add(new int[] {0,0});

while(!q.isEmpty()) {

int []c = q.poll();
int i = c[0];
int j = c[1];

if(i==size-1 && j==size-1) {
answer = Math.min(answer, temp[i][j]);
continue;
}
if(answer<=temp[i][j]) continue;

for(int d=0;d<4;d++) {
int ni = i + mov[d][0];
int nj = j + mov[d][1];

if(ni<0 || nj<0|| size-1 <ni|| size-1 < nj) continue;

if(!visited[ni][nj] || temp[ni][nj] > temp[i][j] + map[ni][nj]) {
visited[ni][nj] = true;
temp[ni][nj] = temp[i][j] + map[ni][nj];
q.add(new int[] {ni,nj});
}

}

}

System.out.println("#"+test_case+" "+answer);



}

}

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

import java.util.Scanner;

public class no_1244 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int size = sc.nextInt();

int[]arr = new int[size];

for(int i=0;i<size;i++) arr[i] = sc.nextInt();

int test = sc.nextInt();

for(int t=0;t<test;t++) {

int sex = sc.nextInt();
int idx = sc.nextInt();

if(sex==1) {
for(int i=idx;i<size;i += idx) {
if(arr[i]==1) arr[i] = 0;
else arr[i] = 1;
}
}else {

int plus = 1;

while(true) {

if(arr[idx+plus]==arr[idx-plus]) {
if(arr[idx+plus]==1) {
arr[idx+plus] = 0;
arr[idx-plus] = 0;
}else {
arr[idx+plus] = 1;
arr[idx-plus] = 1;
}

plus++;

}else break;



}




}


}





for(int i : arr)System.out.println(i);

}

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

import java.util.Scanner;

public class no_1289 {


public static void main(String args[]) throws Exception
{
/*
아래의 메소드 호출은 앞으로 표준 입력(키보드) 대신 input.txt 파일로부터 읽어오겠다는 의미의 코드입니다.
여러분이 작성한 코드를 테스트 할 때, 편의를 위해서 input.txt에 입력을 저장한 후,
이 코드를 프로그램의 처음 부분에 추가하면 이후 입력을 수행할 때 표준 입력 대신 파일로부터 입력을 받아올 수 있습니다.
따라서 테스트를 수행할 때에는 아래 주석을 지우고 이 메소드를 사용하셔도 좋습니다.
단, 채점을 위해 코드를 제출하실 때에는 반드시 이 메소드를 지우거나 주석 처리 하셔야 합니다.
*/
//System.setIn(new FileInputStream("res/input.txt"));

/*
표준입력 System.in 으로부터 스캐너를 만들어 데이터를 읽어옵니다.
*/
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
/*
여러 개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
*/

for(int test_case = 1; test_case <= T; test_case++)
{

StringBuilder sb = new StringBuilder();

sb.append("#").append(test_case).append(" ");

String str = sc.next();
int[] a = new int[str.length()];
for(int i = 0; i < str.length(); i++) {
a[i] = str.charAt(i) - '0';
}
int num = a[0];

for(int i = 1; i < a.length; i++) {
if(a[i] != a[i-1]) num++;
}

sb.append(num);

System.out.println(sb.toString());

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

import java.util.ArrayList;
import java.util.HashMap;

public class no_13 {


public static void main(String[] args) {

String [] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"};

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

for(String str : record) {

String temp[] = str.split(" ");
String action = temp[0];
String id = temp[1];

if(action.equals("Leave")) continue;

String nick = temp[2];

map.put(id, nick);

}

for(String str : record) {

String temp[] = str.split(" ");
String action = temp[0];
String id = temp[1];

if(action.equals("Change")) continue;

String nick = map.get(id);
String ans = nick + "님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다.");

answerList.add(ans);

}


String[]answer = new String[answerList.size()];

for(int i = 0 ; i< answerList.size();i++) answer[i] = answerList.get(i);

for(String str : answer)System.out.println(str);


}
}