์ ์ฒด ๊ธ
-
[C++] ์ผ์ฑ 1767. [SW Test ์ํ๋ฌธ์ ] ํ๋ก์ธ์ ์ฐ๊ฒฐํ๊ธฐ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:05
#include #include #include using namespace std; int arr[12][12]; int T, N, res, pnum; bool dir_check(int x, int y, int dir) { if (dir == 1) { for (int i = y + 1; i < N; i++) { if (arr[x][i] != 0) return false; } } else if (dir == 2) { for (int i = x + 1; i < N; i++) { if (arr[i][y] != 0) return false; } } else if (dir == 3) { for (int i = 0; i < y; i++) { if (arr[x][i] != 0) return false; } } el..
-
[C++] ๋ฐฑ์ค 15686๋ฒ. ์นํจ๋ฐฐ๋ฌ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:04
#include #include #include using namespace std; int N, M; int city[50][50]; int chicken_dist = 100000; vector houses; vector chickens; vector answer((13,13)); int find_dist() { int dist; int mini_dist; int total = 0; for (int i = 0; i < houses.size(); i++) { mini_dist = 100000; for (int j = 0; j < M; j++) { dist = abs(houses[i].first - answer[j].first) + abs(houses[i].second - answer[j].second);..
-
[C++] ์ผ์ฑ 2112. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ๋ณดํธ ํ๋ฆ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:03
#include #include using namespace std; int D, W, K; int input_array[13][20]; int min_count = 20; void input_A(int row) { for (int i = 0; i < W; i++) input_array[row][i] = 0; } void input_B(int row) { for (int i = 0; i < W; i++) input_array[row][i] = 1; } bool test_column(int j) { int max_count = 0; int count = 1; for (int i = 1; i < D; i++) { if (input_array[i - 1][j] == input_array[i][j]) count..
-
[C++] ์ผ์ฑ 2105. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ๋์ ํธ ์นดํ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:02
#include #include using namespace std; int N; int input_array[20][20]; int dessert[101] = { 0, }; int dArr[][2] = { { -1,1 },{ 1,1 },{ 1,-1 },{ -1,-1 } }; int first_x, first_y; int max_count = -1; void recursive(int a, int b, int n, int direction) { int x = a + dArr[direction][0]; int y = b + dArr[direction][1]; if (x >= N || y >= N || x 3) // ๋ฐฐ์ด ๋ฒ์๋ฅผ ๋๊ฑฐ๋ 4๋ฐฉํฅ ํ์ ์ ๋์์ ๊ฒฝ..
-
์ฐ์ ์์ํ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ํ 2020. 9. 6. 04:48
#include #include using namespace std; struct Coord { int x; int y; Coord(int _x, int _y) { x = _x; y = _y; } }; struct Comp { // return ์ด ๋ฎ์ ์์ผ๋ก ๋ฝ๋๋ค(์ค๋ฆ์ฐจ์) bool operator()(struct Coord a, struct Coord b) { if (a.x == b.x) return a.y b.x; // x๋ ์ค๋ฆ์ฐจ์ } }; int main() { priority_queue pq_1; // ์ฐ์ ์์ํ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ด๋ฆผ์ฐจ์ pq_1.push(5); pq_1.push(2..
-
์์์ ์๋ฆฌ ์ถ๋ ฅ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ํ 2020. 8. 28. 19:54
.์ ๊ธฐ์ค์ผ๋ก ์ผ์ชฝ์ ์ ์ฒด ์๋ฆฟ์ ์ค๋ฅธ์ชฝ์ ์์์ ์๋ฆฟ์ float num = 1234.5678; printf("%9.1f", num); // 1234.5 printf("%9.2f", num); // 1234.56 printf("%9.3f", num); // 1234.567 printf("%9.4f", num); // 1234.5678 c++ ๋ฐฉ์์ ์์ธ๋ฏ?
-
๋ณ์ ํ์ ๋ณํ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ํ 2020. 8. 28. 19:51
string to char * : str_cstr(); string to char๋ฐฐ์ด char cstr[100]; string str = "hello"; strlen(cstr, str.c_str()); char ๋ฐฐ์ด to string char *cstr = "hello"; string str = cstr; char to int, float, long : atoi, atof, atol (ํค๋ cstdlib) string to int : string str = "100"; int num; num = atoi(str.c_str()); int to string : to_string() int num = 10; string str; str = to_string(num);