Giter Club home page Giter Club logo

cpp-basic-practice-history's Introduction

cpp-basic-practice-history's People

Contributors

wch18735 avatar

Watchers

 avatar  avatar

cpp-basic-practice-history's Issues

CPP TIL

#include<stdio.h>
#include<string.h>

const int LM = 210;
int wcnt;
char buf[LM], * words[LM];

void split() {
	char* token = strtok(buf, " ");
	while (token) {
		words[wcnt++] = token;
		token = strtok(NULL, " ");
	}
}

void insertionSort() {
	int i, j;
	for (i = 1; i < wcnt; ++i) {
		char* tp = words[i];

		for (j = i - 1; j >= 0; --j) {
			if (strcmp(words[j], tp) > 0) {
				words[j + 1] = words[j];
			}
			else break;
		}
		words[j + 1] = tp;
	}
}

void output() {
	int i, cnt = 1;

	for (i = 1; i < wcnt; ++i) {
		if (strcmp(words[i - 1], words[i]) == 0) cnt++;
		else {
			printf("%s : %d\n", words[i - 1], cnt);
			cnt = 1;
		}
	}
	printf("%s : %d\n", words[i - 1], cnt);
}

int main() {
	//freopen("input.txt", "r", stdin);

	while (scanf(" %[^\r\n]s", buf)) {
		if (strcmp(buf, "END") == 0) break;
		wcnt = 0;
		split();
		insertionSort();
		output();
	}

}

/*
* 배운 것
* 1. scanf()에 사용되는 정규표현식
* 2. insertionSort()
* 3. 창(W) 에서 새 창을 띄우면 한 쪽에 편집한 내용 옆에 동시 반영
* 4. strtok(NULL, delimeter) 는 이전에 찾았던 위치에서부터 다시 찾음
* 5. strcmp(str1, str2) 사용법
*/

string vector sorting alphabetically

알파벳 순서로 정렬 방법
=> 단순 string 비교 연산자 사용하면 자동으로 정렬된다

bool custom(string a, string b) {
    return a < b;
}

책 복사하기 문제

책복사하기 문제

  • 최적값 찾기
    check(): 최대 허용 가능 페이지가 mid일 때, 나눠지는 그룹 수 gCnt 가 주어지는 K 이하임을 만족하는가 에 대하여 가능/불가능 판단하는 함수
    check() 를 Binary Search 판단 조건으로 활용해 최대 허용 가능 페이지가 mid일 때,나눠진 그룹 수가 K개인가장 작은 값을 찾음

  • 출력
    배열을 역순으로 탐색하는 DFS 함수 작성
    후위 순회 진행 (탐색의 끝부터 출력을 진행하며 돌아옴)

void dfs(){
   // base condition
   // search
   // print()
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.