[Coding] Coding Test 정리

모든 코딩 테스트는 C++로 작성하였습니다. #

  1. 글자 뒤집기. 글자안에 특수문자 잇으면 그건 그대로 들고오기

     1bool Reverse::isSpecial(char c) {
     2	if ((c >= 'a') && (c <= 'z')) return false;
     3	if ((c >= 'A') && (c <= 'Z')) return false;
     4	return true;
     5}
     6
     7void Reverse::rev(char *array, int N) {
     8	int i = 0;  // i points to the first index of the array
     9	int j = N - 1; // j points to the last index of the array
    10
    11	while (i < j)
    12	{
    13		if (isSpecial(array[i]))
    14		{
    15			i++;
    16		}
    17		else if (isSpecial(array[j]))
    18		{
    19			j--;
    20		}
    21		else
    22		{
    23			char tmp = array[i];
    24			array[i] = array[j];
    25			array[j] = tmp;
    26			i++;
    27			j--;
    28		}
    29	}
    30}
    31
    32void Reverse::ReverseMain() {
    33	char str[] = "kr.yoon1101@gamil.com";
    34	int stringSize = sizeof(str);
    35	rev(str, stringSize);
    36	cout << str << endl;
    37}
  2. 링크드리스트 두개 합치기 그리고 정렬. 중복은 한개만

    1string test = "";
  3. 바이너리 서치(Binary Search, 이진 검색)를 이용해서 배열안에 원하는 숫자 찾기

     1//반복문을 이용한 이진 탐색
     2int BinarySearch::binarySearch(int array[], int _find, int size) {
     3	int s = 0;
     4	int e = size - 1;
     5	int m = 0;
     6
     7	while (s <= e) {
     8		m = (s + e) / 2;
     9		if (array[m] == _find) return m;
    10		else if (array[m] > _find) e = m - 1;
    11		else s = m + 1;
    12	}
    13	return -1;
    14}
    15
    16//재귀를 이용한 이진 탐색
    17int BinarySearch::binarySearch2(int array[], int _find, int size) {
    18	int s = 0;
    19	int e = size - 1;
    20	int m = 0;
    21
    22	if (s > e) return -1;
    23	m = (s + e) / 2;
    24	if (array[m] == _find) return m;
    25
    26	return -1;
    27}
    28
    29void BinarySearch::binaryRun() {
    30	int find = 0;
    31	cout << "찾고 싶은 값은 : " << endl;
    32	cin >> find;
    33	int data[] = { 1,3,6,8,11,23,111,114,213 };
    34	int dataSize = sizeof(data) / sizeof(int);
    35	int ans = binarySearch(data, find, dataSize);
    36	cout << ans;
    37}
    38
    39int BinarySearch::STLbinary_search() {
    40	int arr[100];
    41
    42	for (int i = 0; i < 100; i++) {
    43		arr[i] = i;
    44	}
    45	cout << "exist : " << binary_search(arr, arr + 100, 70) << endl;
    46
    47	return 0;
    48}
  4. 사전 검색 프로그램 (띄어쓰기)

  5. 회전수 구하기

  6. 비트 1의 갯수

  7. LRU

  8. 셀프 넘버 구하기

  9. 사다리 타기 프로그램

  10. 삼각별 만들기

  11. 스도쿠 만들기

  12. 지뢰게임

Advertisement