feat: Initial commit

This commit is contained in:
2024-03-22 17:14:57 +01:00
parent dc83234df1
commit db9bafe755
45 changed files with 1996 additions and 0 deletions

43
TemiEsame/campionato.c Normal file
View File

@@ -0,0 +1,43 @@
#include <string.h>
#include <stdio.h>
#define MAXN 10
#define MAXM 10
int indMax(int ranking[MAXN], int n) {
int ind = 0, max = ranking[0];
for (int i = 1; i < n; i++) {
if (max < ranking[i]) {
ind = i;
max = ranking[i];
}
}
return ind;
}
void displRanking(int C[MAXN][MAXM], int n, int m) {
int ranking[MAXM];
puts("la squadra capolista in ognuna delle nelle 3 giornate è:");
for (int i = 0; i < n; i++) {
ranking[i] = 0;
}
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
ranking[i] += C[i][j];
}
printf(" %d", indMax(ranking, n));
}
putc('\n', stdout);
}
int main(){
int arr[MAXN][MAXM] = {{3,1,0},{0,1,1},{1,1,1},{1,1,3}};
displRanking(arr, 4, 3);
return 0;
}

2
TemiEsame/carte.txt Normal file
View File

@@ -0,0 +1,2 @@
1 2 4 4
3 3 5 8

38
TemiEsame/charErase.c Normal file
View File

@@ -0,0 +1,38 @@
#include <string.h>
#include <stdio.h>
int charErase (char str[], int pos[]) {
int l = strlen(str);
int * atp = pos;
int steps = 0;
// segno con -1 i caratteri da eliminare
while (*atp != -1) {
if (*atp < l)
str[*atp] = -1; // nessun carattere ascii ha codice -1, è una flag valida
atp++;
}
for (int i = 0; i < l; i++) {
while (str[i + steps] == -1) {
steps++;
if (i + steps >= l)
break;
}
str[i] = str[i + steps];
}
str[l-steps] = 0;
return steps;
}
int main(){
char sus[] = "ThisIsAString";
int arr[] = {7, 4, 2, 0, 11, -1};
printf("%d",charErase(sus, arr));
puts(sus);
return 0;
}

26
TemiEsame/conta.c Normal file
View File

@@ -0,0 +1,26 @@
#include <string.h>
#include <stdio.h>
int conta(char *parole[], int nparole, char *cerca) {
int s = 0;
int l = strlen(cerca);
for (int i = 0; i < nparole; i++) {
char * prt = parole[i];
do {
prt = strstr(prt, cerca);
if (prt != NULL) {
prt += l;
s++;
}
} while (prt != NULL);
}
return s;
}
int main(int argc, char ** argv) {
printf("%d", conta(argv, argc-1, argv[argc-1]));
return 0;
}

40
TemiEsame/countAndPrint.c Normal file
View File

@@ -0,0 +1,40 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int isVocal(char c) {
char * vowels = "aeiou";
c = tolower(c);
return strchr(vowels, c) != NULL;
}
void countAndPrint(char str[], int n) {
int l = strlen(str), v, s = 0;
for (int i = 0; i < l - n; i++) {
v = 0;
for (int j = i; j < i + n; j++) {
if (isVocal(str[j])) {
v++;
}
}
if (v == 2) {
s++;
for (int j = i; j < i + n; j++)
putchar(str[j]);
putchar('\n');
}
}
printf("%d", s);
}
int main() {
countAndPrint("forExample",4);
return 0;
}

View File

@@ -0,0 +1,46 @@
#include <string.h>
#include <stdio.h>
#define MAXR 10
#define MAXC 10
int buildMatrix(int V[], int N, int M[MAXR][MAXC], int nr, int nc) {
int p = 0, x, y;
if (N % 2 == 1) {
return 1;
}
for (int i = 0; i < N; i += 2) {
for (int j = 0; j < (V[i+1]); j++) {
x = p / nc;
y = p % nc;
if (x >= nr) {
return 1;
}
if (y == 0) {
putchar('\n');
}
M[x][y] = V[i];
printf("%d\t", V[i]);
p++;
}
}
putchar('\n');
p--;
if (p / nc != (nr - 1) || p % nc != (nc - 1)) {
return 1;
}
return 0;
}
int main(){
int arr[MAXR][MAXC];
int vec[] = {1, 2, 17, 2, 3, 1, 8, 4, 6, 1, 7, 3, 5, 2};
printf("%d", buildMatrix(vec, 14, arr, 3, 5));
return 0;
}

36
TemiEsame/maxOdd.c Normal file
View File

@@ -0,0 +1,36 @@
#include <string.h>
#include <stdio.h>
void maxOdd(int v[], int N) {
int max = 0, li = 0;
for (int i = 0; i <= N; i++) {
if (i == N || v[i] % 2 == 0) {
if (i - li > max) {
max = i - li;
}
li = i+1;
}
}
li = 0;
for (int i = 0; i <= N; i++) {
if (i == N || v[i] % 2 == 0) {
if (i - li == max) {
for (int j = li; j < i; j++){
printf("%i", v[j]);
}
puts("");
}
li = i+1;
}
}
}
int main(){
int arr[] = {1, 3, 7, 1, 0, 1, 9, 3, 1, 0};
maxOdd(arr, 10);
return 0;
}

46
TemiEsame/overslapping.c Normal file
View File

@@ -0,0 +1,46 @@
#include <string.h>
#include <stdio.h>
#define MAXN 10
int areaTot(FILE *fp) {
unsigned int carte[MAXN][MAXN];
unsigned int lx, ly, rx, ry, somma = 0;
for (int i = 0; i < MAXN; i++) {
for (int j = 0; j < MAXN; j++) {
carte[i][j] = 0;
}
}
while (!feof(fp)) {
if (fscanf(fp, "%u %u %u %u ", &lx, &ly, &rx, &ry) != 4) {
return -1;
}
if (lx >= MAXN || ly >= MAXN || rx >= MAXN || ry >= MAXN) {
return -1;
}
for (int i = lx; i < rx; i++) {
for (int j = ly; j < ry; j++) {
carte[i][j] = 1;
}
}
}
for (int i = 0; i < MAXN; i++) {
for (int j = 0; j < MAXN; j++) {
somma += carte[i][j];
}
}
return somma;
}
int main() {
FILE * fin;
fin = fopen("./carte.txt", "r");
printf("%d", areaTot(fin));
fclose(fin);
return 0;
}

26
TemiEsame/prodCartOrd.c Normal file
View File

@@ -0,0 +1,26 @@
#include <string.h>
#include <stdio.h>
void insertionSort(int *v1, int d1) {
int t = 0;
for (int i = 1; i < d1; i++) {
t = v1[i];
int j = i -1;
while (j >= 0 && v1[j]>t) {
v1[j+1] = v1[j];
j--;
}
v1[j+1] = t;
}
}
void prodCartOrd(int *v1, int d1, int *v2, int d2) {
insertionSort(v1, d1);
insertionSort(v2, d2);
}

19
TemiEsame/sommaCornici.c Normal file
View File

@@ -0,0 +1,19 @@
#include <string.h>
#include <stdio.h>
#define MAXN 10
int sommaCornici(int mat[MAXN][MAXN], int N, int vet[]) {
int c = N / 2;
for (int i = 0; i < c; i++) {
vet[i] = mat[i][i] + mat[N-i-1][i] + mat[N-i-1][N-i-1] + mat[N-i-1][N-i-1];
for (int j = i; j < N-i-1; j++) {
vet[i] += mat[i][j] + mat[j][i] + mat[N-i-1][j] + mat[j][N-i-1];
}
}
if (N % 2 == 1) {
vet[c+1] = mat[c][c];
}
}