알고리즘
[자연수 뒤집기] 자연수 뒤집는 알고리즘
parkit
2018. 9. 28. 15:56
728x90
반응형
자연수를 뒤집는 알고리즘이다.
예) 283 → 382
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 31 32 33 34 35 | #include <iostream> #include <queue> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> using namespace std; int Reverse(int n) { int Before = n; int New = 0; while (Before) { New = (New * 10) + (Before % 10); Before = Before / 10; } return New; } int main(void) { int N = 0; scanf("%d", &N); printf("%d\n", Reverse(N)); return 0; } | cs |
728x90
반응형