전체 글
![Codility - Perm Missing Elem // C++](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fb9EZDR%2FbtqBGZKH1p4%2F8KVQb0RnNuBLDwpCkkM7xk%2Fimg.png)
Codility - Perm Missing Elem // C++
문제 An array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing. Your goal is to find that missing element. Write a function: int solution(vector &A); that, given an array A, returns the value of the missing element. For example, given array A such that: A[0] = 2 A[1] = 3 A[2] = 1 A[3] = 5 the funct..
![Codility - Odd Occurrences In Array // C++](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FsLvC5%2FbtqBDcpMDkp%2Fl07K0hJt9lJLJ95whJcKi1%2Fimg.jpg)
Codility - Odd Occurrences In Array // C++
문제 A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired. For example, in array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9 the elements at indexes 0 and 2 have value 9, the elements a..
![Codility - Cyclic Rotation // C++](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fl4Zlz%2FbtqByE9RfO7%2F9E7la0k5dYXGKDrIli69G0%2Fimg.png)
Codility - Cyclic Rotation // C++
문제 An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place). The goal is to rotate array A K times; that is, each eleme..
![Codility - Binary Gap // C++](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbIOzsT%2FbtqBAVbFEiV%2F4XgEkiT05kbduDQYKnbJCk%2Fimg.jpg)
Codility - Binary Gap // C++
문제 A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binar..
![백준 1157번 단어 공부 // Python](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcD3oim%2FbtqBrmNSvU6%2FyNvKKkD8DWCXYfMhPbaw01%2Fimg.png)
백준 1157번 단어 공부 // Python
문제 알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다. 첫째 줄에 이 단어에서 가장 많이 사용된 알파벳을 대문자로 출력한다. 단, 가장 많이 사용된 알파벳이 여러 개 존재하는 경우에는 ?를 출력한다. 풀이 먼저, 입력받을 문자열은 대소문자 구분이 없고 정답은 대문자로 출력해야 하기 때문에 입력과 동시에 upper을 통하여 대문자로 바꿨다. 알파벳 별로 사용 횟수를 세기 위하여 count라는 list를 사용하여 횟수를 셌다. 마지막으로 count에서 max 값을 찾아줬는데, max 값이 같은 경우가 있는지 확인하여 check라는 변수를 이용했다. check가 false이고, max 값과 같은 경우..
![백준 2675번 문자열 반복 // Python](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fs7lGM%2FbtqBqPCH6UU%2Fhwct3RoXYHaBKBv24P9b51%2Fimg.png)
백준 2675번 문자열 반복 // Python
문제 문자열 S를 입력받은 후에, 각 문자를 R번 반복해 새 문자열 P를 만든 후 출력하는 프로그램을 작성하시오. 즉, 첫 번째 문자를 R번 반복하고, 두 번째 문자를 R번 반복하는 식으로 P를 만들면 된다. S에는 QR Code "alphanumeric" 문자만 들어있다. QR Code "alphanumeric" 문자는 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\$%*+-./: 이다. 첫째 줄에 테스트 케이스의 개수 T(1 ≤ T ≤ 1,000)가 주어진다. 각 테스트 케이스는 반복 횟수 R(1 ≤ R ≤ 8), 문자열 S가 공백으로 구분되어 주어진다. S의 길이는 적어도 1이며, 20글자를 넘지 않는다. 풀이 파이썬에서 공백을 기준으로 입력 받는것을 처리할줄 몰랐기에, 한 줄 ..
![백준 10809번 알파벳 찾기 // Python](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbNJU5v%2FbtqBp4Aw9Af%2FN0FN3qpzRP69ykB06JSZDk%2Fimg.jpg)
백준 10809번 알파벳 찾기 // Python
문제 알파벳 소문자로만 이루어진 단어 S가 주어진다. 각각의 알파벳에 대해서, 단어에 포함되어 있는 경우에는 처음 등장하는 위치를, 포함되어 있지 않은 경우에는 -1을 출력하는 프로그램을 작성하시오. 풀이 파이썬 내의 문자열에서 기본적으로 사용할 수 있는 find를 이용해서 문제를 풀었다. a-z까지 들어있는 문자열을 하나 선언해서 for문으로 하나씩 입력받은 문자열에서의 위치를 찾아냈다. 코드 더보기 s = input() alphabet = 'abcdefghijklmnopqrstuvwxyz' for i in alphabet: print(s.find(i))
![백준 11654번 아스키 코드 // Python](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FlEQAa%2FbtqBqiFjvXz%2FwaDAJKAheAHU1KAiTyJsOK%2Fimg.png)
백준 11654번 아스키 코드 // Python
문제 알파벳 소문자, 대문자, 숫자 0-9중 하나가 주어졌을 때, 주어진 글자의 아스키 코드값을 출력하는 프로그램을 작성하시오. 풀이 C언어에서는 char 변수를 printf("%d", ch)와 같이 사용하면 아스키 코드가 출력되지만, 파이썬에서는 다른 함수가 존재한다. ord 함수와 chr 함수인데, ord 함수는 문자를 아스키 코드로 chr 함수는 아스키 코드를 문자로 바꿔준다. (문자열이 아닌 문자만 변환 가능) 따라서 입력받은 문자를 ord 함수를 통하여 아스키 코드로 출력하면 된다. 코드 더보기 Python ch = input() print(ord(ch)) C++ scanf("%c", &ch); printf("%d", ch);