Left Rotation - Hackerrank
Left Rotation - Hackerrank
Left Rotation - Hackerrank
h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* readline();
char** split_string(char*);
int main()
{
FILE* fptr = fopen(getenv("OUTPUT_PATH"), "w");
char** nd = split_string(readline());
char* n_endptr;
char* n_str = nd[0];
int n = strtol(n_str, &n_endptr, 10);
char* d_endptr;
char* d_str = nd[1];
int d = strtol(d_str, &d_endptr, 10);
*(a + i) = a_item;
}
int a_count = n;
int result_count;
int* result = rotLeft(a_count, a, d, &result_count);
if (i != result_count - 1) {
fprintf(fptr, " ");
}
}
fprintf(fptr, "\n");
fclose(fptr);
return 0;
}
char* readline() {
size_t alloc_length = 1024;
size_t data_length = 0;
char* data = malloc(alloc_length);
while (true) {
char* cursor = data + data_length;
char* line = fgets(cursor, alloc_length - data_length, stdin);
if (!line) {
break;
}
data_length += strlen(cursor);
alloc_length <<= 1;
if (data[data_length - 1] == '\n') {
data[data_length - 1] = '\0';
data[data_length] = '\0';
}
return data;
}
int spaces = 0;
while (token) {
splits = realloc(splits, sizeof(char*) * ++spaces);
if (!splits) {
return splits;
}
splits[spaces - 1] = token;
return splits;
}