본문 바로가기
728x90

전체 글140

[Python] 특정 문자의 위치 찾기 - find(), rfind(), index() 이번에는 특정 문자가 몇 번째 위치에 있는지 찾아볼게요. 위에서 사용했던 “Hello World.”를 다시 사용해볼게요. 이 문장에서 ‘W’는 몇 번째에 있을까요? 공백(띄어쓰기)과 특수문자를 포함해주세요. 세어봤나요? 몇 번째 인가요? 문장의 7번째 글자가 ‘W’네요. 그럼 파이썬을 이용해서 W를 찾아볼까요? 먼저 파이썬에서 제공하는 find() 함수를 이용해볼게요. hello_str = 'Hello World.' print(hello_str.find('W')) >> (출력) 6 잉? 분명 손으로 세어봤을 때는 7번째 글자인데 왜 6이 나올까요? 여러분들은 제일 첫 글자인 H를 1번으로 세었을 거에요. 하지만 컴퓨터는 0번째, 1번째… 이렇게 세기때문에 ‘W’가 6번째에 있다고 알려주는 거에요. 그럼 .. 2022. 6. 3.
[Python] 문자 개수 세기 - count() 아래 문자에는 영어 단어 ‘l’이 몇 개 있을까요? “Hello World.” 다들 손가락으로 몇 개인지 세어보셨나요? 3개가 있죠? 파이썬의 문자열은 count() 라는 함수는 검색할 문자를 찾아 몇 개인지 계산해주는데요. hello_str = 'Hello World.' print(hello_str.count('l')) >> (출력) 3 hello_str2 = 'Hello World. Hello~' print(hello_str2.count('Hello')) >> (출력) 2 count() 함수에 검색할 문자나 단어를 파라미터로 입력해주면 문장 안에 몇 번 등장하는지 계산해줘요. 쉽죠? 2022. 6. 3.
[Codility] Lesson 3 : PermMissingElem - JAVA 문제 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: class Solution { public int solution(int[] 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.. 2022. 6. 1.
[Codility] Lesson 3 : FrogJmp - JAVA 문제 A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D. Count the minimal number of jumps that the small frog must perform to reach its target. Write a function: class Solution { public int solution(int X, int Y, int D); } that, given three i.. 2022. 6. 1.
[Codility] Lesson 2 : OddOccurrencesInArray - JAVA 문제 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.. 2022. 5. 31.
[Codility] Lesson 2 : CyclicRotation - JAVA 문제 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.. 2022. 5. 30.
728x90