test done
This commit is contained in:
31
axis/task3.c
Normal file
31
axis/task3.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
char* solution(int N) {
|
||||
static const int size = (int)('z' - 'a');
|
||||
const int interval = (int)ceil((double)N / (double)size);
|
||||
|
||||
char* str = (char*)malloc((N + 1) * sizeof(char));
|
||||
str[N] = '\0';
|
||||
int count = 0;
|
||||
char offset = 0;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
str[i] = 'a' + offset;
|
||||
if (++count >= interval) {
|
||||
count = 0;
|
||||
++offset;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
int main() {
|
||||
{
|
||||
char* str = solution(3);
|
||||
printf("%s\n", str);
|
||||
free(str);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user