초기 네이버 기록/알고리즘(C) 34

이코테 구현알고리즘 예제 1번 상하좌우 -방향벡터 (C언어)

#include int main() { int input; scanf("%d", &input); //int map[100][2];//0:x 1:y int x = 1; int y = 1; char order[2]; for (int i = 0; i 1) x--; else if (order[0] == 'R' && x 1) y--; else if (order[0] == 'D' && y < input) y++; } printf("%d %d", y, x); } 난 이렇게 풀었는데 방향 벡터를 이용해서 푸는 방법이 더 깔끔한 것 같다. dx[4] = {0, 0, 1, -1};(행) dy[4] = {1, -1, 0, 0};(열)이렇게 미..

백준 왕실의 나이트(C) 수학적 풀이, 완전 탐색적 풀

#include int main() { int count = 8; char input[3]; scanf("%s", input); int check = input[0] + input[1] - 'a' - '1'; if (check == 0 || check == 14) count -= 6; else if (check == 1 || check == 13) count -= 5; else if (check == 2 || check == 12) count -= 4; else if (check == 3 || check == 11) count -= 3; else if (check == 4 || check == 10) count -= 2; printf("%d", count); } 좀 이상하게 조건문에 꽂쳐서 수학적으로 풀..

백준 (C언어) (구현) 게임개발 -방향벡터 및 맵 탐색

#include #include int main() { int length, width;//세로, 가로 int x, y, direction;//방향은 0:북, 1:동, 2:남, 3:서 int** map;// 세로 가로, 0육지 1바다 scanf("%d %d", &length, &width); map = (int**)malloc(sizeof(int*) * (length)); //int move[4][2] = {{0,-1}, {1,0}, {0,1}, {-1,0}};//북, 동, 남 ,서 int move[4][2] = { {0,1}, {-1,0} ,{0,-1} ,{1,0} };//북,서,남,동 scanf("%d %d %d ", &x, &y, &direction); for (int i = 0; i < lengt..

백준 c++백준 1181번 단어정렬 (부제 :c++의 말도 안되는 편리함)

실패코드 #include #include using namespace std; int ft_strcmp(char *str1, char *str2) { if(strlen(str1) !=strlen(str2)) { if (strlen(str1) > strlen(str2)) return (1); else return (-1); } while (*str1 == *str2 && *str1 && *str2) { str1++; str2++; } return (*str1 - *str2); } int main() { int inputnum; cin >> inputnum; char **arr = new char*[inputnum + 1]; char *tmp; for (int i = 0; i < inputnum; i++) ..

백준 c++1654번 랜선 자르기 문제

실패코드 //시간 초과 코드 아무리 시간을 줄이려고 노력해도 이분탐색을 사용하지 않는다면 절대로 풀수 없는 범위가 나오는 문제이다. #include #include using namespace std; int main() { int k,n; cin >> k >> n; int count, result; int *input = new int[k]; for (int i =0; i > input[i]; } count = 0; sort(input ,input +k); int tk = k; for (int i = input[tk-1] ; tk >0; tk--) { count = 0; for (int j = 0; j < k; j++) { count +=input[j] / i; } if ..

백준 c++백준 7568 덩치 클래스 복습

​ 이 문제는 분명 클래스를 쓰지 않고도 더 짧게 풀 수 있었다. 하지만 굳이 클래스를 사용해 본건 생성자에 대해서 복습이 필요했고 더 보기 깔끔한 코드를 만들어보기 위해서였다. 확실히 가독성과 코드 짤 때 머리속에 정리가 잘 되는 느낌이다. calloc 함수를 사용해봤는데 malloc과 달리 인자를 넣는 방식이 살짝 달랐다. void *malloc(size_t size); void *calloc(size_t num, size_t size); 이렇게 돼있어서 처음에 멀록처럼 사용했다가 이렇게 바꾸었다. #include #include using namespace std; class human { private: int kg; int len; public : human(int kg, int len): kg..

728x90