50171. Split a string

難度:2.5/5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <limits.h>
#include "splitAndMap.h"

int get_size(char*** ptr){
int n = 0;
while(ptr[n] != NULL) n++;
return n;
}

void splitAndMap(char*** ptr, char* str){
int n = get_size(ptr);
int arr_idx[10] = {0};
int len[10] = {0};

char* token = strtok(str, "*");
while(token != NULL){
int min_idx = 0;
for(int i = 1; i < n; i++){
if(len[i] < len[min_idx]) min_idx = i;
}
ptr[min_idx][arr_idx[min_idx]++] = token;
len[min_idx] += strlen(token);
token = strtok(NULL, "*");
}
}


50171. Split a string
https://aaronlin1229.github.io/judgegirl_50171/
Author
Akizumi
Posted on
July 17, 2023
Licensed under