using System; using System.Threading; public class Worker { // This method will be called when the thread is started. public void DoWork() { while (!_shouldStop) { Console.WriteLine("worker thread: working..."); } Console.WriteLine("worker thread: terminating gracefully."); } public void RequestStop() { _shouldStop = true; } // Volatile is used as hint to the compiler that this data // member will be accessed by multiple threads. private volatile bool _shouldStop; } public class WorkerThreadExample { static void Main() { // Create the thread object. This does not start the thread. Worker workerObject = new Worker(); Thread workerThread = new Thread(workerObject.DoWork); // Start the worker thread. workerThread.Start(); Console.WriteLine("main thread: Starting worker thread..."); // Loop until worker thread activates. while (!workerThread.IsAlive); // Put the main thread to sleep for 1 millisecond to // allow the worker thread to do some work: Thread.Sleep(1); // Request that the worker thread stop itself: workerObject.RequestStop(); // Use the Join method to block the current thread // until the object's thread terminates. workerThread.Join(); Console.WriteLine("main thread: Worker thread has terminated."); } }
Labels
Programming
(16)
Algorithm
(15)
Java
(15)
ASP .NET
(4)
Enterprise Architecture
(4)
PHP and MySQL
(4)
Software Engineering
(2)
C#
(1)
Data Mining
(1)
Deep Learning
(1)
Java Script
(1)
Python
(1)
Sunday, September 20, 2015
C# Thread
Tuesday, September 15, 2015
Maze
문제 번호 G: [100점] 문제06
시간 제한: 1 Sec 메모리 제한: 128 MB제출: 764 해결 문제 수: 98
[제출][채점 상황 열람]
문제 설명
미로탈출 로봇 대회를 개최하였다. 대회에 사용되는 미로는 가로(X), 세로(Y) 100 이하의 크기이며, 로봇이 미로를 한 칸 이동하는 데는 1초가 걸린다.

로봇이 출발점에서 도착점까지 가장 빨리 이동할 경우 걸리는 시간을 구하는 프로그램을 작성하시오.
* 입출력 Template이필요한경우 C/C++ 제출은다음코드를복사하여코드를작성하시오
#include <stdio.h>
int maze[101][101];
int X, Y;
int sx, sy, ex, ey;
int main(void)
{
int i, j, k=0;
//입력받는부분
scanf("%d %d", &X, &Y);
scanf("%d %d %d %d", &sx, &sy, &ex, &ey);
for(i=0 ; i<Y ; i++)
{
for(j=0 ; j<X ; j++) scanf("%1d", &maze[i][j]);
}
//여기서부터작성
//출력하는부분
printf("%d\n", k);
return 0;
}
* 입출력 Template이필요한경우 JAVA 제출은다음코드를복사하여코드를작성하시오
import java.io.IOException;
import java.util.Scanner;
public class Main
{
public static void main(String [] arg) throws IOException
{
String [] maze ;
int X, Y;
int sx, sy, ex, ey;
int i, j, k=0;
Scanner sc = new Scanner(System.in);
//입력받는부분
X = sc.nextInt();
Y = sc.nextInt();
sx = sc.nextInt();
sy = sc.nextInt();
ex = sc.nextInt();
ey = sc.nextInt();
maze = new String [Y];
sc.nextLine();
for(i=0 ; i<Y ; i++) maze[i] = sc.nextLine();
//여기서부터작성
//출력하는부분
System.out.println(k);
sc.close();
}
}
[힌트]
|
입력예2
|
|
8 10
1 1 7 9
00000101
11001000
10000010
01101010
00000110
01010000
01110110
10000100
10011101
01000001
|
|
출력예2
|
|
16
|
|
입력예3
|
|
5 5
1 1 5 5
00000
01101
00100
01110
00000
|
|
출력예3
|
|
8
|
입력
첫줄에 미로의 크기 X, Y(1≤X, Y≤100)가 주어진다. 둘째 줄에 출발점 x, y 좌표와 도착점 x, y 좌표가 공백으로 구분하여 주어진다. 셋째 줄부터 미로의 정보가 길은 0, 벽은 1로 공백이 없이 들어온다. (주의) 좌표는 좌측상단이 가장 작은 위치이며 이 위치의 좌표는 (1,1)이다.
출력
첫줄에 출발점에서 도착점까지 가장 빠른 시간을 출력한다.
입력 예시
8 7
1 2 7 5
11111111
00000111
10110011
10111001
10111101
10000001
11111111
출력 예시
9도움말
Anything about the Problems, Please Contact Admin:admin
(c)2015 Edunix Corporation, A Family Company of Willtek Group
GPL2.0 2003-2015 HUSTOJ Project TEAM
참외밭 Wrong Answer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] arg) throws IOException { int[][] a = new int[6][2]; int K, sum = 0; Scanner sc = new Scanner(System.in); // 입력받는부분 K = sc.nextInt(); for (int i = 0; i < 6; i++) { a[i][0] = sc.nextInt(); a[i][1] = sc.nextInt(); } // 여기서부터작성 int[] eastWest = new int[3]; int[] southNorth = new int[3]; int eWIdx = 0; int sNIdx = 0; for (int i = 0; i < 6; i++) { if(a[i][0] == 1 || a[i][0] == 2){ eastWest[eWIdx++] = a[i][1]; } if(a[i][0] == 3 || a[i][0] == 4){ southNorth[sNIdx++] = a[i][1]; } } int ewBig = 0; int ewBigIdx = 0; int ewSmallIdx = 0; for(int i = 0;i < eastWest.length; i++){ if(ewBig < eastWest[i]){ ewBig = eastWest[i]; ewBigIdx = i; } } if(ewBigIdx == 0){ ewSmallIdx = 1; }else if(ewBigIdx == 1){ ewSmallIdx = 2; }else if(ewBigIdx == 2){ ewSmallIdx = 0; } int ewBigValue = eastWest[ewBigIdx]; int ewSmallValue = eastWest[ewSmallIdx]; ////////////////////////////////////////////////////////////// int snBig = 0; int snBigIdx = 0; int snSmallIdx = 0; for(int i = 0;i < southNorth.length; i++){ if(snBig < southNorth[i]){ snBig = southNorth[i]; snBigIdx = i; } } if(snBigIdx == 0){ snSmallIdx = 2; }else if(snBigIdx == 1){ snSmallIdx = 0; }else if(snBigIdx == 2){ snSmallIdx = 1; } int snBigValue = southNorth[snBigIdx]; int snSmallValue = southNorth[snSmallIdx]; // System.out.println(ewBigValue+" "+ewSmallValue); // System.out.println(snBigValue+" "+snSmallValue); sum = ((ewBigValue * snBigValue) - (ewSmallValue * snSmallValue)) * K; // 출력하는부분 System.out.println(sum); sc.close(); } } |
Rotating Array by a given angle(90, 180, 270, 360 degree)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] arg) throws IOException { int n; int[][] a; int r; Scanner sc = new Scanner(System.in); // 입력받는부분 n = sc.nextInt(); a = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) a[i][j] = sc.nextInt(); } for (;;) { r = sc.nextInt(); if (r == 0) break; // 여기서부터작성 int[][] tempA = new int[n][n]; int rowXDefault = 0; int rowYDefault = 0; int rowXIncrement = 0; int rowYIncrement = 0; int colXIncrement = 0; int colYIncrement = 0; if(r == 90){ rowXDefault = 0; rowYDefault = n -1; rowXIncrement = -1; rowYIncrement = -1; colXIncrement = +1; colYIncrement = -1; }else if(r == 180){ rowXDefault = n- 1; rowYDefault = n -1; rowXIncrement = -2; rowYIncrement = 0; colXIncrement = 0; colYIncrement = -2; }else if(r == 270){ rowXDefault = n - 1; rowYDefault = 0; rowXIncrement = -1; rowYIncrement = +1; colXIncrement = -1; colYIncrement = -1; }else if(r == 360){ //leave them } for (int i = 0; i < n; i++) { int indexX = rowXDefault; int indexY = rowYDefault; for (int j = 0; j < n; j++) { tempA[i + indexX][j + indexY] = a[i][j]; indexX += colXIncrement; indexY += colYIncrement; } rowXDefault += rowXIncrement; rowYDefault += rowYIncrement; } a = tempA; // 출력하는부분 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { System.out.print(a[i][j] + " "); } System.out.println(); } } sc.close(); } } |
N*N 배열에서 각 요소에 정수가 들어 있다. 이 배열에서 합이 가장 큰 행과 열의 번호를 각각 인쇄하라.
입력예시
5
3 -5 12 3 -21
-2 11 2 -7 -11
21 -21 -35 -93 -11
9 14 39 -98 -1
-2 -2 -2 -2 -2
출력예시
2 1
입력예시
5
3 -5 12 3 -21
-2 11 2 -7 -11
21 -21 -35 -93 -11
9 14 39 -98 -1
-2 -2 -2 -2 -2
출력예시
2 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] arg) throws IOException { int i, j, N; int[][] a; Scanner sc = new Scanner(System.in); // 입력 받는 부분 N = sc.nextInt(); a = new int[N][N]; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) a[i][j] = sc.nextInt(); } // 여기서부터 작성 int[] row_sum = new int[N]; int[] col_sum = new int[N]; for(i = 0; i < N; i++){ int row_sum_temp = 0; int col_sum_temp = 0; for (j = 0; j < N; j++){ row_sum_temp += a[i][j]; col_sum_temp += a[j][i]; } row_sum[i] = row_sum_temp; col_sum[i] = col_sum_temp; } int max_row_index = 1; int max_col_index = 1; int row_max = row_sum[0]; int col_max = col_sum[0]; for(i = 1; i < N; i++){ if(row_max < row_sum[i]){ max_row_index = i + 1; row_max = row_sum[i]; } } for(i = 1; i < N; i++){ if(col_max < col_sum[i]){ max_col_index = i + 1; col_max = col_sum[i]; // System.out.println("max_col_index : "+max_col_index); // System.out.println("col_max : "+col_max); } } // 출력 하는 부분 System.out.print(max_row_index + " " + max_col_index); sc.close(); } } |
Computing height as stacking bowl using parenthesis, JungOl Question 2604, (http://www.jungol.co.kr/problem.php?id=2604)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); String str = sc.nextLine(); char[] strArray = str.toCharArray(); int height = 0; for(int i = 0; i < strArray.length;i++){ if(i == 0){ height += 10; }else if(strArray[i] == '('){ if(strArray[i-1] == '('){ height += 5; }else{ height += 10; } }else if(strArray[i] == ')'){ if(strArray[i-1] == ')'){ height += 5; }else{ height += 10; } } } System.out.println(height); } } |
Monday, September 14, 2015
Computing the GCD(Greatest Common Divisor) and the LCM(Lowest Common Multiple) from multiple input numbers using Euclidean algorithm, JungOl Question 1002 (http://jungol.co.kr/problem.php?id=1002)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int N; N = sc.nextInt(); int[] input_arr = new int[N]; for(int i = 0;i < N; i++){ input_arr[i] = sc.nextInt(); } int current_gcd = input_arr[0]; for(int i = 0;i < N-1;i++){ if(current_gcd > input_arr[i+1]){ current_gcd = gcd(input_arr[i+1], current_gcd % input_arr[i+1]); }else{ current_gcd = gcd(current_gcd, input_arr[i+1] % current_gcd); } } int current_lcm = input_arr[0]; for(int i = 0;i < N-1;i++){ if(current_lcm > input_arr[i+1]){ current_lcm = lcm(current_lcm, input_arr[i+1], gcd(current_lcm, input_arr[i+1])); }else{ current_lcm = lcm(current_lcm, input_arr[i+1], gcd(input_arr[i+1], current_lcm)); } } System.out.println(current_gcd+" "+current_lcm); } static int gcd(int a, int b){ if(b == 0){ return a; } return gcd(b, a%b); } static int lcm(int a, int b, int gcd) { return a*b/gcd; } } |
Subscribe to:
Posts (Atom)