취뽀했어용
그래도 열심히 매일매일 알고리즘 풀기를 도전해 볼 것입니다:) 아직 안하고 있는게 함정.. 지치지 말고 파이팅하기!!
2022.04.06
[C언어] 두 디렉토리 비교
두 디렉토리를 비교하는 프로그램 입니다. 오류가 많은 코드이니 참고만 하시길.. 수정해야 할 코드는 주석처리를 했습니다. 나중에 시간날 때 다시 도전.. /** * 두 디렉토리 비교 * Test와 Real 디렉토리 비교하여 파일 유무 및 내용 확인하기 */ #include #include #include #include #define _CRT_NONSTDC_NO_WARNINGS typedef struct _finddata_t FILE_SEARCH; char* getFileList(char* path); void compare_file_name(char** arr1, char** arr2, int size1, int size2); int compare_text(char** comp1, char** comp..
2022.03.28
[C언어] 삼각형 경로 최대 합 찾기
문제를 나중에 첨부하도록 하겠습니다.. 삼각형 모양의 정수 배열을 받아 아래로 내려가는 경로에서 가장 큰 합을 찾는 문제입니다. /** * 정수 삼각형 * 삼각형 꼭대기에서 바닥까지 이어지는 경로에서 합이 가장 큰 경우 찾기 */ #include int solution(int(*arr)[5], int col, int row); int get_max(int* arr); int main() { int result = 0; result = solution((int[][5]) { {7}, { 3, 8 }, { 8, 1, 0 }, { 2, 7, 4, 4 }, { 4, 5, 2, 6, 5 } }, 5, 5); printf("%d\n", result); return 0; } int solution(int (*arr)..
2022.03.28
[C언어] 소수 찾기 문제
문자열 숫자를 입력받아 해당 숫자로 만들 수 있는 소수를 찾는 문제 입니다. (아마도 프로그래머스 2 레벨 문제..maybe) /** * 소수 찾기 문제 * 문자열 numbers가 주어졌을 때, 만들 수 있는 소수 개수 찾기 */ #include #include #include #include "math.h" #define _NO_CRT_STDIO_INLINE int biggest_number(int* arr, int length); int get_Prime(int* arr, int num, int size); int main() { char str[7]; int num[7] = {0,}; int copy[7] = { 0, }; int len = 0; int total_prime; //문자열 입력받기 p..
2022.03.28
코테 연습하기
1. 프로그래머스 1~3 Level 풀기 https://programmers.co.kr/learn/challenges?tab=all_challenges 코딩테스트 연습 기초부터 차근차근, 직접 코드를 작성해 보세요. programmers.co.kr 2. 프로그래머스 코딩테스트 고득점 Kit 풀이 https://programmers.co.kr/learn/challenges?tab=algorithm_practice_kit 코딩테스트 연습 기초부터 차근차근, 직접 코드를 작성해 보세요. programmers.co.kr 3. 프로그래머스 SQL 고득점 Kit 풀이 (일단 나중에) https://programmers.co.kr/learn/challenges?tab=sql_practice_kit 코딩테스트 연습 기..
2022.03.17

취뽀했어용

얘리밍
|2022. 4. 6. 21:38
320x100
728x90

그래도 열심히

매일매일

알고리즘 풀기를 도전해 볼 

것입니다:)

 

아직 안하고 있는게 함정..

 

지치지 말고 파이팅하기!!

 

728x90
반응형

'하루 일기' 카테고리의 다른 글

새로운 시작👏  (3) 2023.01.25
이것 저것..  (0) 2022.12.06
코테 연습하기  (3) 2022.03.17
320x100
728x90

두 디렉토리를 비교하는

프로그램 입니다.

 

오류가 많은 코드이니

참고만 하시길..

수정해야 할 코드는 주석처리를 했습니다.

 

나중에 시간날 때 다시 도전..

/**
* 두 디렉토리 비교
* Test와 Real 디렉토리 비교하여 파일 유무 및 내용 확인하기
*/
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <stdlib.h>
#define _CRT_NONSTDC_NO_WARNINGS
typedef struct _finddata_t FILE_SEARCH;

char* getFileList(char* path);
void compare_file_name(char** arr1, char** arr2, int size1, int size2);
int compare_text(char** comp1, char** comp2);

int main()
{
	int i = 0;
	char test_path[100] = "C:\\A_company\\test\\*.*";
	char real_path[100] = "C:\\A_company\\Real\\*.*";

	char** testFile = getFileList(test_path);
	char** realFile = getFileList(real_path);

	int size1 = 0, size2 = 0;

	while (testFile[size1] != NULL && realFile[size2] != NULL) {
		size1++, size2++; //test, real 파일의 길이
	}

	compare_file_name(testFile, realFile, size1, size2);



	system("pause");
	return 0;

}
/* directory 파일 리스트 확인 */
char* getFileList(char* path)
{
	int res = 1;
	int cnt;
	long handle;
	char search_path[100];
	static char* fileList[100];
	int i = 0;


	FILE_SEARCH file_search;

	//절대경로 파일명 만들기
	sprintf_s(search_path, "%s%s", path);

	//폴더 내 모든 파일 찾음
	handle = _findfirst(search_path, &file_search);

	if (handle == -1) { // 파일이 없을 때
		printf("Empty!");
	}
	else { //파일 목록 확인

		while (_findnext(handle, &file_search) == 0) {
			if (!strcmp(file_search.name, ".") || !strcmp(file_search.name, "..")) continue;
			else { //파일 리스트 배열에 저장
				fileList[i] = malloc(strlen(file_search.name) + 1);
				strcpy(fileList[i], file_search.name);
				i++;
			}
		}
		return fileList;
	}
	memset(fileList, '\0', sizeof(char) * i);
	_findclose(handle);
}
/* 파일 내용 비교*/
int compare_text(char** comp1, char** comp2)
{
	FILE* fp1;
	FILE* fp2;
	int res = 0;

	//파일 열기 오류
	if (((fp1 = fopen(comp1, "r")) == NULL) || (fp2 = fopen(comp2, "r")) == NULL) {
		fprintf(stderr, "file open error!");
		exit(1);
	}

	while (1) {
		//fgets(comp1, sizeof(comp1), fp1);
		//fgets(comp2, sizeof(comp2), fp2);

		if (strcmp(comp1, comp2) != 0) {
			res = -1;
			return res;
			break;
		}
		else {
			return res;
			break;
		}
	}
}
/* 파일 이름 비교*/
void compare_file_name(char** arr1, char** arr2, int size1, int size2)
{
	static char* A1[100];
	static char* B1[100];

	int k = 0;

	printf("%s\n", arr1[1]);
	printf("%s\n", arr2[1]);

	//동일한 파일 
	for (int i = 0; i < size1; i++) {
		for (int j = 0; j < size2; j++) {
			if (strcmp(arr1[i], arr2[j]) == 0) { //파일 이름이 같으면
				int val = compare_text(arr1[i], arr2[j]); //내용 비교 시작
				if (val == -1) { //내용 다르면
					printf("X: ", arr1[i]);
				}

			}
			else if (strcmp(arr1[i], arr2[j]) < 0) { // T에만 있는 파일
				printf("T: ", arr1[i]);
			}
			else { // R에만 있는 파일
				printf("R: ", arr2[j]);
			}
		}
	}


}
728x90
반응형
320x100
728x90

문제를 나중에

첨부하도록 하겠습니다..

 

삼각형 모양의 정수 배열을 받아

아래로 내려가는 경로에서 가장 큰 합을 찾는 문제입니다.

 

/**
* 정수 삼각형
* 삼각형 꼭대기에서 바닥까지 이어지는 경로에서 합이 가장 큰 경우 찾기
*/
#include <stdio.h>
int solution(int(*arr)[5], int col, int row);
int get_max(int* arr);
int main()
{
	int result = 0;
	
	result = solution((int[][5]) { {7}, { 3, 8 }, { 8, 1, 0 }, { 2, 7, 4, 4 }, { 4, 5, 2, 6, 5 } }, 5, 5);
	printf("%d\n", result);

	return 0;
	
}
int solution(int (*arr)[5], int col, int row)
{
	int i = 0, j = 0, k = 0, max = 0;
	int sumList[5] = {0,};
	
	arr[i][j] = arr[0][0];
	for (i = 1; i < row; i++) {
		for (j = 0; j < col; j++) {
			if (arr[i][j] == 0) continue; 
			if (j == 0) { 
				arr[i][j] += arr[i-1][j];
			}
			else if (j == i) {
				arr[i][j] += arr[i-1][j-1];
			}
			else {
				int com1 = arr[i - 1][j - 1];
				int com2 = arr[i - 1][j];
				int max_value = com1 > com2 ? com1 : com2;

				arr[i][j] = arr[i][j] + max_value;
			}			
			
		}
		memcpy(sumList, arr[i], sizeof(arr[i]));
	}

	/*더한 값들 중 최댓값 구하기*/
	max = sumList[0];
	for (int i = 0; i < sizeof(sumList) / sizeof(sumList[0]); i++) {
		if (max < sumList[i])
			max = sumList[i];
	}
	
	return max;
}

 

피드백, 댓글 환영

ㅎ.ㅎ

728x90
반응형
320x100
728x90

문자열 숫자를 입력받아

해당 숫자로 만들 수 있는 소수를 찾는 문제 입니다.

 

(아마도 프로그래머스 2 레벨 문제..maybe) 

/**  
* 소수 찾기 문제
* 문자열 numbers가 주어졌을 때, 만들 수 있는 소수 개수 찾기
*/
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "math.h"
#define _NO_CRT_STDIO_INLINE


int biggest_number(int* arr, int length);
int get_Prime(int* arr, int num, int size);
int main()
{
	char str[7];
	int num[7] = {0,};
	int copy[7] = { 0, };
	int len = 0;
	int total_prime;
	//문자열 입력받기
	printf("input numbers : ");

	while (0 == scanf_s("%[^\n]", str, 7)) { // 길이가 0 혹은 7을 넘을 시 계속 입력받음 
		printf("숫자를 다시 입력하세요.\n");
		rewind(stdin);
		printf("input numbers : ");
	}

	len = strlen(str); //입력받은 숫자 길이
	
	// 한자리 숫자 씩 배열에 넣기
	for (int i = 0; str[i] != '\0'; i++) {
		num[i] = str[i] - '0';
	}

	memcpy(copy, num, sizeof(int)*len); 
	
	int bigNum = biggest_number(num, len);
	total_prime = get_Prime(copy, bigNum, len);
	printf("%d", total_prime);

	return 0;
}
//가장 큰수 - 내림차순 정렬
int biggest_number(int* arr,int length)
{
	int temp;
	int number = 0;
	for (int i = 0; i < length; i++) {
		for (int j = 0; j < (length - 1 - i); j++) {
			if (arr[j] < arr[j + 1]) {
				temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
			}
		}
	}
	//정수로 변환
	for (int i = 0 ; i <length; i++) {
		for (int j = 1; j < length - i; j++) {
			arr[i] *= 10;
		}
		number += arr[i];
	}
	
	return number;
}

//범위 내의 소수 판별
int get_Prime(int* arr, int num, int size)
{

	int cnt, comp;
	int check = 0, len = 0, total = 0;
	int temp[7] = {10,10,10,10,10,10,10};
	

	for (int i = 2; i <= num; i++) {
		cnt = 0;
		for (int j = 1; j <= i; j++) {
			if (i % j == 0) cnt++; //소수 아닌 수 
		}
		if (cnt == 2) { // 소수일 때
			int prime = i;
			char s1[7]; 
			int len = floor(log10(prime) + 1); //숫자 자리수 구하기
			
			sprintf_s(s1, 7, "%d", prime); //문자열 배열에 복사
			memcpy(temp, arr, sizeof(int)*size);
			
			/*해당 소수가 입력받은 숫자로 만들 수 있는 수인지 확인*/
			for (int k = 0; k < len; k++) { 
				for (int n = 0; n < size; n++) {
					comp = temp[n] + 48;
					if (s1[k] == comp) { //해당하는 문자가 있으면
						memmove(temp + n, temp + n + 1, (7-n-1)*sizeof(*temp)); //해당 문자 삭제(사용완료)
						check++; 
					}
				}
				if (check == len) total++;
			}
			check = 0;
			
			
		}
	}

	return total;
}

 

개선할 점이나 궁금한 점

댓글 환영 입니다:)

728x90
반응형

코테 연습하기

얘리밍
|2022. 3. 17. 01:56
320x100
728x90

1. 프로그래머스 1~3 Level 풀기

https://programmers.co.kr/learn/challenges?tab=all_challenges 

 

코딩테스트 연습

기초부터 차근차근, 직접 코드를 작성해 보세요.

programmers.co.kr

2. 프로그래머스 코딩테스트 고득점 Kit 풀이

https://programmers.co.kr/learn/challenges?tab=algorithm_practice_kit 

 

코딩테스트 연습

기초부터 차근차근, 직접 코드를 작성해 보세요.

programmers.co.kr

3. 프로그래머스 SQL 고득점 Kit 풀이 (일단 나중에)

https://programmers.co.kr/learn/challenges?tab=sql_practice_kit 

 

코딩테스트 연습

기초부터 차근차근, 직접 코드를 작성해 보세요.

programmers.co.kr

4. 백준 문제풀이

문제 추천 사이트 : https://covenant.tistory.com/224

 

코딩테스트 대비를 위한 백준 문제 추천

코딩테스트 대비를 위한 백준 문제 추천 끝 없는 훈련만이 실전에서 흐트럼없이 정답을 향해서 움직일 수 있습니다. (Photo by Specna Arms on Unsplash) 작년 한 해 수많은 코딩테스트를 직접 경험하고

covenant.tistory.com

5. LeetCode 75 문제 풀이

https://www.teamblind.com/post/New-Year-Gift---Curated-List-of-Top-75-LeetCode-Questions-to-Save-Your-Time-OaM1orEU

 

New Year Gift - Curated List of Top 75 LeetCode Questions to Save Your Time

New Year Gift to every fellow time-constrained engineer out there looking for a job, here's a list of the best LeetCode questions that teach you core concepts and techniques for each category/type of problems! Many other LeetCode questions are a mash...

www.teamblind.com

 

차근차근

공부해보자

파이팅!

728x90
반응형

'하루 일기' 카테고리의 다른 글

새로운 시작👏  (3) 2023.01.25
이것 저것..  (0) 2022.12.06
취뽀했어용  (2) 2022.04.06