목록Algorithm/구현 | ETC (50)
:: ADVANCE ::
dovelet 9 단계 재귀 특별한 4자리 정수 (sfn) http://59.23.113.171/30stair/sfn/sfn.php?pname=sfn 123456789101112131415161718192021222324252627282930#include int sumofDecimal(int n){ if (!n) return n; return n % 10 + sumofDecimal(n / 10);} int sumofDuodecimal(int n){ if (!n) return n; return n % 12 + sumofDuodecimal(n / 12);} int sumofHexadecimal(int n){ if (!n) return n; return n % 16 + sumofHexadecimal(n / ..
dovelet 9 단계 재귀 유클리드 호제법 (euclid) http://59.23.113.171/30stair/euclid/euclid.php?pname=euclid 12345678910111213141516171819202122#include int gcd(int n, int m) { if (m == 0) return n; else gcd(m, n % m);} int lcm(int n, int m) { int g = gcd(n, m); return n / g * m;} int main(void){ int n, m; scanf("%d %d", &n, &m); printf("%d %d\n", gcd(n, m), lcm(n, m)); return 0;}cs 당연한 얘기겠지만나머지 연산으로 만든 GCD가 마..
dovelet 9 단계 재귀 x의 y 거듭 제곱 (powerofx) http://59.23.113.171/30stair/powerofx/powerofx.php?pname=powerofx 1234567891011121314151617#include int square(int n, int m){ if (m == 1) return n; return n * square(n, m - 1);} int main(void){ int n, m; scanf("%d %d", &n, &m); printf("%d\n", square(n, m)); return 0;}cs 으아아아재귀야 오랜만이다오랜만이라 감을 잃었다...큰일이로다ㅠㅠ
dovelet 옥상 평균값 수열 (coci_prosjek) http://59.23.113.171/pool/coci_prosjek/coci_prosjek.php?pname=coci_prosjek 123456789101112131415161718192021#include int main(void){ int n; int in[2] = { 0, }; int output[110] = { 0, }; scanf("%d", &n); for (int i = 0; i
dovelet 7 단계 다차원 배열 3*3 블럭의 합 (block) http://59.23.113.171/30stair/block/block.php?pname=block 12345678910111213141516171819202122#include int main(void) { int i, j; int output[9] = { 0, }; for (i = 0; i
dovelet 옥상 색종이 (koi_Mpaper) http://59.23.113.171/pool/koi_Mpaper/koi_Mpaper.php?pname=koi_Mpaper 123456789101112131415161718192021222324252627282930313233343536#include int map[110][110];int cnt; int main(void){ int n, i, x, y, j; scanf("%d", &n); while (n--) { scanf("%d%d", &x, &y); for (i = 0; i
dovelet 9 단계 재귀 하노이 탑 (hanoi) http://59.23.113.171/30stair/hanoi/hanoi.php?pname=hanoi 1234567891011121314151617181920212223#include void hanoi(int n, int x, int y, int z){ if (n > 0){ hanoi(n - 1, x, z, y); printf("%d -> %d\n", x, z); hanoi(n - 1, y, x, z); }} int main(void){ int n; scanf("%d", &n); hanoi(n, 1, 2, 3); return 0;}cs 단순히 이동 횟수를 묻는 거라면 2*f(n-1)+1을 재귀로 돌리면 됨이동 경로를 나타내는 문제인데제공된 기본 소스..
dovelet 9단계 재귀 이진수로 바꾸기 (tobin) http://59.23.113.171/30stair/tobin/tobin.php?pname=tobin 1234567891011121314151617181920#include void tobin(int n){ if (n > 1) tobin(n / 2); printf("%d", n % 2);} int main(void){ int n; scanf("%d", &n); tobin(n); printf("\n"); return 0;}cs tobin 함수 안에 printf를 재귀 호출 위에 있으면 10일 때 0101 이 출력되고재귀 호출 다음에 있으면 10일 때 1010이 출력재귀가 끝나야 출력되니까 맨 처음 계산한 값이 맨 마지막에 출력된다이거를 잘 이해하고 ..
dovelet 9단계 재귀 계단 오르기 (upstair) http://59.23.113.171/30stair/upstair/upstair.php?pname=upstair 2015 5/16 123456789101112131415161718192021222324#include int cnt; void stair(int n) { if (n == 0) cnt++; else if (n > 0) { stair(n - 1); stair(n - 2); }} int main(void){ int n; scanf("%d", &n); stair(n); printf("%d\n", cnt); return 0;}cs 2015 1/15 123456789101112131415161718192021222324252627#include ..