목록전체 글 (103)
배움 저장소

9.2 함수의 프로토타입 // prototype void print_multiple_chars( ); void print_multiple_chars(char, int, bool); int main() { print_multiple_chars('*', WIDTH, true); } void print_multiplechars(char c, int width, bool DoesNewlineNeeded) { // sth.... } 함수의 프로토타입에서 매개변수를 지정하지 않고 비워놓아도 상관없다. 혹은 자료형만 표기할 수도 있다. 9.3 함수의 자료형과 반환값 정수형 반환 자료형은 생략 가능하다. 반환 자료형이 없다면 정수형으로 가정한다. 9.5 지역변수와 스택 int main() { // Main scope ..

8.1 입출력 버퍼 buffer를 사용하지 않는 입력 #include // Only Windows, _getch(), _getche() int main() { char c; while ( (c = _getche()) != '.') // 'e' for echo putchar(c); } Output hheelllloo wwoorrlldd buffer를 사용하지 않으면 위와 같이 출력된다. 위 코드는 아래 그림의 첫 번째 사례이다. while( getchar() != '/n' ); 일 때 입력값은 buffer에 저장된다. '/n'을 만나거나 buffer가 저장할 수 있는 용량을 넘어서면 이때까지 저장된 자료를 반환하고 다시 값을 입력받는다. 8.2 파일의 끝 char c; while(1) { c = getch..
7.1 분기문 IF if(Expression) Statement 이 때 Expression은 0일 때 false 아닐때 true로 간주한다. 7.2 표준 입출력 함수 // Case 1 int ch; do{ ch = getchar(); putchar(ch); } while (ch != '\n'); // Case 2 int ch; while( (ch=getchar()) != '\n') { putchar(ch); } 두 번째 예시에서 = 연산자는 우선순위가 낮으므로 ch=getchar()를 먼저 실행시켜주기 위하여 ( ) 를 사용해야 한다. Filtering: Convert Numbers to Asterisks // Case 1 int ch; while( (ch=getchar()) != '\n') { // F..
https://leetcode.com/problems/group-anagrams/ Group Anagrams - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 첫 시도 Set 사용방법을 기억할만해서 틀린풀이지만 기록해본다. Set 안에 Set을 하나 더 넣어서 시도했다. // input => vector& str; set bigSet; for(string &s:strs) { set smallSet; /* Set은 중복을 허용하지 않고, Set 값이 저장될 ..
Overloading 대신에 Template 사용하기 정수, 문자열을 출력하는 함수를 만들어보자. 같은 함수명이되 다른 자료형을 가지고 있는 함수를 Overloading해주면 된다. void PrintAny(int i) { cout

6.1 scanf( )의 반환값 사용하기 int num, sum = 0; int status; printf("Enter Next Integer (q to quit) : "); status = scanf("%d", &num); // (int) num에 문자를 넣으면 // status = 0이된다. while(status == 1) { sum = sum + num; printf("Enter Next Integer (q to quit) : "); status = scanf("%d", &num); } printf("Sum = %d \n", sum); scanf()함수를 while 조건문에 바로 넣을 수 있다. int num, sum = 0; printf("Enter Next Integer (q to quit) ..

https://leetcode.com/problems/rotate-image/ Rotate Image - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 풀이 1. transpose I,J에 있는 값과 J,I에 있는 값을 바꾸어버리면 (1,1),(2,2)...(x,x)를 기준으로 대칭된 matrix를 얻는다. 2. 정렬 이제 행의 위치만 반대로 정렬해주면 처음 matrix의 90도 회전된 matrix를 얻을 수 있다. 방법은 두 가지가 있다. 1) Swap ..

5.2. 대입 연산자 몇 가지 용어들 Operand & Operator 여기서 i와 1은 operand 피연산자이며 +는 operator 연산자이다. int i = i+1; L-value, R-value L-value : 메모리 공간을 차지하여 값을 할당받는다 값을 할당할 수도 있다. R-value : 값을 할당할 때 사용한다. 계산이 끝나면 사라진다. int i; // L-value i = 1024; // L-value에 R-value를 할당함 i = i+1; // L-value는 R-value처럼 쓸 수 있음 5.3~5.5 여러 연산자 int i, j, k; /* Triple Assignment */ i = j = k = 10; i = (j = (k = 10)); /* Binary Operator(이..