Untitled
unknown
plain_text
a year ago
1.0 kB
2
Indexable
Never
#include <stdio.h> #include <time.h> #include <stdlib.h> int iscon(long long num) { long long prevdig = num % 10; num /= 10; while (num > 0) { long long curdig = num % 10; if (curdig + 1 != prevdig) return 0; num /= 10; prevdig = curdig; } return 1; } int main() { long long l, r; clock_t tic = clock(); scanf("%lld %lld", &l, &r); long long *consecutiveNumbers = malloc((l-r+1) * sizeof(long long)); int count = 0; for (long long num = l; num <= r; num++) { if (iscon(num)) { consecutiveNumbers[count] = num; count++; } } printf("["); for (int i = 0; i < count; i++) { printf("%lld", consecutiveNumbers[i]); if (i < count - 1) printf(","); } printf("]"); clock_t toc = clock(); printf("Elapsed: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC); return 0; }