starting
This commit is contained in:
commit
2e899f840e
23
01/_.h
Normal file
23
01/_.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <wctype.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
|
||||||
|
|
||||||
|
char** str_split(char* a_str, const char a_delim);
|
||||||
|
|
||||||
|
int str_index(char *str, char c);
|
||||||
|
|
||||||
|
int number_of_element(char *str, char c);
|
||||||
|
|
||||||
|
long gmc(long a, long b);
|
||||||
|
long lmc(long a, long b);
|
||||||
|
long lmcs(int array[], int n);
|
1
01/build.sh
Executable file
1
01/build.sh
Executable file
|
@ -0,0 +1 @@
|
||||||
|
gcc -g -Wall -Wextra -include_.h *.c
|
16
01/main.c
Normal file
16
01/main.c
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "_.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
if (argc != 2)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
char *input = argv[1];
|
||||||
|
char **inputs = str_split(strdup(input), '\n');
|
||||||
|
|
||||||
|
for (int i = 0; inputs[i] != NULL; i++) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
0
01/main.txt
Normal file
0
01/main.txt
Normal file
84
01/mylib.c
Normal file
84
01/mylib.c
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
#include "_.h"
|
||||||
|
|
||||||
|
// NOT MY CODE
|
||||||
|
// https://stackoverflow.com/questions/9210528/split-string-with-delimiters-in-c
|
||||||
|
char** str_split(char* str, const char a_delim)
|
||||||
|
{
|
||||||
|
char *a_str = strdup(str);
|
||||||
|
char** result = 0;
|
||||||
|
size_t count = 0;
|
||||||
|
char* tmp = a_str;
|
||||||
|
char* last_comma = 0;
|
||||||
|
char delim[2];
|
||||||
|
delim[0] = a_delim;
|
||||||
|
delim[1] = 0;
|
||||||
|
|
||||||
|
while (*tmp)
|
||||||
|
{
|
||||||
|
if (a_delim == *tmp)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
last_comma = tmp;
|
||||||
|
}
|
||||||
|
tmp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
count += last_comma < (a_str + strlen(a_str) - 1);
|
||||||
|
|
||||||
|
count++;
|
||||||
|
|
||||||
|
result = malloc(sizeof(char*) * count);
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
size_t idx = 0;
|
||||||
|
char* token = strtok(a_str, delim);
|
||||||
|
|
||||||
|
while (token)
|
||||||
|
{
|
||||||
|
//assert(idx < count);
|
||||||
|
*(result + idx++) = strdup(token);
|
||||||
|
token = strtok(0, delim);
|
||||||
|
}
|
||||||
|
//assert(idx == count - 1);
|
||||||
|
*(result + idx) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(a_str);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_index(char *str, char c) {
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (str[i])
|
||||||
|
if (str[i++] == c)
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int number_of_element(char *str, char c) {
|
||||||
|
int nbr = 0;
|
||||||
|
for (int i = 0; str[i] != '\0'; i++)
|
||||||
|
if (str[i] == c)
|
||||||
|
nbr++;
|
||||||
|
return nbr;
|
||||||
|
}
|
||||||
|
|
||||||
|
long gmc(long a, long b) {
|
||||||
|
if (b == 0)
|
||||||
|
return a;
|
||||||
|
return gmc(b, a % b);
|
||||||
|
}
|
||||||
|
|
||||||
|
long lmc(long a, long b) {
|
||||||
|
return (a / gmc(a, b)) * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
long lmcs(int array[], int n) {
|
||||||
|
long result = array[0];
|
||||||
|
for (int i = 1; i < n; i++)
|
||||||
|
result = lmc(result, array[i]);
|
||||||
|
return result;
|
||||||
|
}
|
0
01/test.txt
Normal file
0
01/test.txt
Normal file
5
start.sh
Normal file
5
start.sh
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
test "$1" == "" && exit 1
|
||||||
|
cp -r template "$1" || exit 1
|
||||||
|
cd "$1" || exit 1
|
||||||
|
chmod +x *.sh || exit 1
|
23
template/_.h
Normal file
23
template/_.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <wctype.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
|
||||||
|
|
||||||
|
char** str_split(char* a_str, const char a_delim);
|
||||||
|
|
||||||
|
int str_index(char *str, char c);
|
||||||
|
|
||||||
|
int number_of_element(char *str, char c);
|
||||||
|
|
||||||
|
long gmc(long a, long b);
|
||||||
|
long lmc(long a, long b);
|
||||||
|
long lmcs(int array[], int n);
|
1
template/build.sh
Normal file
1
template/build.sh
Normal file
|
@ -0,0 +1 @@
|
||||||
|
gcc -g -Wall -Wextra -include_.h *.c
|
16
template/main.c
Normal file
16
template/main.c
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "_.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
if (argc != 2)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
char *input = argv[1];
|
||||||
|
char **inputs = str_split(strdup(input), '\n');
|
||||||
|
|
||||||
|
for (int i = 0; inputs[i] != NULL; i++) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
0
template/main.txt
Normal file
0
template/main.txt
Normal file
84
template/mylib.c
Normal file
84
template/mylib.c
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
#include "_.h"
|
||||||
|
|
||||||
|
// NOT MY CODE
|
||||||
|
// https://stackoverflow.com/questions/9210528/split-string-with-delimiters-in-c
|
||||||
|
char** str_split(char* str, const char a_delim)
|
||||||
|
{
|
||||||
|
char *a_str = strdup(str);
|
||||||
|
char** result = 0;
|
||||||
|
size_t count = 0;
|
||||||
|
char* tmp = a_str;
|
||||||
|
char* last_comma = 0;
|
||||||
|
char delim[2];
|
||||||
|
delim[0] = a_delim;
|
||||||
|
delim[1] = 0;
|
||||||
|
|
||||||
|
while (*tmp)
|
||||||
|
{
|
||||||
|
if (a_delim == *tmp)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
last_comma = tmp;
|
||||||
|
}
|
||||||
|
tmp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
count += last_comma < (a_str + strlen(a_str) - 1);
|
||||||
|
|
||||||
|
count++;
|
||||||
|
|
||||||
|
result = malloc(sizeof(char*) * count);
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
size_t idx = 0;
|
||||||
|
char* token = strtok(a_str, delim);
|
||||||
|
|
||||||
|
while (token)
|
||||||
|
{
|
||||||
|
//assert(idx < count);
|
||||||
|
*(result + idx++) = strdup(token);
|
||||||
|
token = strtok(0, delim);
|
||||||
|
}
|
||||||
|
//assert(idx == count - 1);
|
||||||
|
*(result + idx) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(a_str);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_index(char *str, char c) {
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (str[i])
|
||||||
|
if (str[i++] == c)
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int number_of_element(char *str, char c) {
|
||||||
|
int nbr = 0;
|
||||||
|
for (int i = 0; str[i] != '\0'; i++)
|
||||||
|
if (str[i] == c)
|
||||||
|
nbr++;
|
||||||
|
return nbr;
|
||||||
|
}
|
||||||
|
|
||||||
|
long gmc(long a, long b) {
|
||||||
|
if (b == 0)
|
||||||
|
return a;
|
||||||
|
return gmc(b, a % b);
|
||||||
|
}
|
||||||
|
|
||||||
|
long lmc(long a, long b) {
|
||||||
|
return (a / gmc(a, b)) * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
long lmcs(int array[], int n) {
|
||||||
|
long result = array[0];
|
||||||
|
for (int i = 1; i < n; i++)
|
||||||
|
result = lmc(result, array[i]);
|
||||||
|
return result;
|
||||||
|
}
|
0
template/test.txt
Normal file
0
template/test.txt
Normal file
Loading…
Reference in a new issue