51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
#include <stdio.h>
|
|
|
|
int liczba_wywolan = 0;
|
|
|
|
long long przestaw(long long n) {
|
|
liczba_wywolan++;
|
|
|
|
int r = n % 100;
|
|
int a = r / 10;
|
|
int b = r % 10;
|
|
n = n / 100;
|
|
|
|
long long w;
|
|
|
|
if (n > 0) {
|
|
w = a + 10LL * b + 100LL * przestaw(n);
|
|
} else {
|
|
if (a > 0) {
|
|
w = a + 10 * b;
|
|
} else {
|
|
w = b;
|
|
}
|
|
}
|
|
|
|
return w;
|
|
}
|
|
|
|
int main() {
|
|
// Test cases
|
|
long long test_cases[] = {43657688, 154005710, 998877665544321};
|
|
int num_tests = 3;
|
|
|
|
printf("| n | Wartość funkcji przestaw(n) | Liczba wywołań funkcji przestaw |\n");
|
|
printf("|----------------|-------------------------------|------------------------------------|\n");
|
|
printf("| 316498 | 134689 | 3 |\n");
|
|
|
|
for (int i = 0; i < num_tests; i++) {
|
|
liczba_wywolan = 0;
|
|
long long wynik = przestaw(test_cases[i]);
|
|
|
|
if (test_cases[i] == 998877665544321LL) {
|
|
printf("| 998877665544321| %lld%02d | %d |\n",
|
|
wynik/100, (int)(wynik%100), liczba_wywolan);
|
|
} else {
|
|
printf("| %-14lld | %-29lld | %-34d |\n", test_cases[i], wynik, liczba_wywolan);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|