Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Javascript
- WarGame
- c++
- 웹페이지 만들기
- 머신러닝
- hackctf
- XSS Game
- BOJ
- hackerrank
- 기계학습
- siss
- 드림핵
- Python
- 숙명여자대학교 정보보안동아리
- 백준
- HTML
- The Loard of BOF
- C언어
- 생활코딩
- CSS
- c
- 자료구조 복습
- Sookmyung Information Security Study
- 파이썬
- SWEA
- lob
- 숙명여자대학교 정보보안 동아리
- BOJ Python
- PHP 웹페이지 만들기
- 풀이
Archives
- Today
- Total
혜랑's STORY
[HackerRank] Left Rotation 본문
# 문제
# 풀이
int* rotateLeft(int d, int arr_count, int* arr, int* result_count) {
*result_count = arr_count;
int *result = malloc(sizeof(int)*(*result_count));
int temp;
for(int i=0; i<d; i++){
temp = arr[0];
for(int j=1; j<arr_count; j++){
arr[j-1] = arr[j];
}
arr[arr_count-1] = temp;
}
for(int i=0; i<arr_count; i++)
result[i] = arr[i];
return result;
}
- 배열의 값을 왼쪽으로 미루는 방법으로 temp에 0번째 원소를 넣고 배열의 값을 하나씩 당겼다. 이후 맨 마지막 자리에 temp에 저장된 0번째 값을 넣는 것으로 배열의 값을 이동시켜 주었다.
- 문제에서 주어진 d번 왼쪽으로 밀도록 for문을 사용하였고 이후 result 배열에 복사해 주었다.
# 결과
'2021 SISS 21기 활동 > 여름방학 C언어' 카테고리의 다른 글
[HackerRank] Counting Sort 2 (0) | 2021.08.05 |
---|---|
[HackerRank] Counting Sort 1 (0) | 2021.08.05 |
[HackerRank] CamelCase (0) | 2021.07.31 |
[HackerRank] Pangrams (0) | 2021.07.24 |
[HackerRank] Caesar Cipher (0) | 2021.07.24 |