✧‧₊˚ 아바타
✧‧₊˚

Hi!

HOME CATEGORIES TAGS ARCHIVES ABOUT
#7C82F0

코드 패턴

📅2025-07-31 📁Study›코드 조각 ⏱ 1 min
코드 패턴
코드 패턴

정수 뒤집기

예: num = 1234 라면, reverse = 4321이 되도록 만드는 게 목표

1
2
3
4
5
int reverse = 0;
while (num > 0) {
    reverse = reverse * 10 + (num % 10);
    num /= 10;
}

% 10 → 맨 마지막 자릿수 가져오기
reverse * 10 + (마지막 자릿수) → 숫자를 왼쪽으로 밀고 자릿수 추가
/= 10 → 맨 마지막 자릿수 제거



Study, 코드 조각
c c++ 코드 조각 코드 패턴
This post is licensed under CC BY 4.0 by the author.
Share

Further Reading

Aug 21, 2025

알고리즘 템플릿(코테용)

0) 백준 입출력 개선 1 2 3 4 5 6 7 8 9 10 11 #include <iostream> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); return 0; } 1) 정렬 + 커스텀 비교 ...

Apr 6, 2025

문자열 뒤집기 (char*)

#include <iostream> void reverse(char* str) { if (str == nullptr) return; // 문자열의 끝을 찾음 (널 종료 문자 전까지 이동) char* end = str; while (*end != '\0') { ++end; } --e...

Nov 7, 2024

단순 연결 리스트의 노드 순서를 뒤집는 함수

// 단순 연결 리스트의 노드 순서 뒤집기 함수 void reverseList(Node*& head) { Node* prev = nullptr; Node* current = head; Node* next = nullptr; while (current != nullptr) { next = current...

갤러리 뷰

home화면에서 특정 태그 포스트 숨기기

Contents

© 2026 Yoo-Jeong. Some rights reserved.

Using the Chirpy theme for Jekyll.

Trending Tags

c++ c tech interview pic cs music html 그래픽스 css STL

A new version of content is available.