aboutsummaryrefslogtreecommitdiff
path: root/semestre 2/informatique/tme
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-03-10 10:31:33 +0100
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-03-10 10:31:33 +0100
commit4a3afaf44aa29e66a6c879c60322015a2920a5ab (patch)
tree64d3e7748078b4215341aeead3b30eaaf28070ad /semestre 2/informatique/tme
parent77bfb2ccd3152c1f41d43dc192ba86ca8fd0f72f (diff)
Ajout de la semaine des cours du 3 au 7 mars
Diffstat (limited to 'semestre 2/informatique/tme')
-rw-r--r--semestre 2/informatique/tme/semaine5/27_comptage_mots.c19
-rw-r--r--semestre 2/informatique/tme/semaine5/28_participation_frais.c52
-rw-r--r--semestre 2/informatique/tme/semaine5/29_filtre.c25
-rw-r--r--semestre 2/informatique/tme/semaine5/30_compression.c64
-rw-r--r--semestre 2/informatique/tme/semaine5/31_image_mystere.c29
5 files changed, 189 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine5/27_comptage_mots.c b/semestre 2/informatique/tme/semaine5/27_comptage_mots.c
new file mode 100644
index 0000000..7ea19e7
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine5/27_comptage_mots.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+int compte_mots(char *s){
+ int i = 0;
+ int cnt = 0;
+ int counted = 0;
+ while (s[i] != '\0'){
+ if (s[i] != ' ' && !counted) {
+ cnt++;
+ counted = 1;
+ } else if (s[i] == ' ') counted = 0;
+ i++;
+ }
+ return cnt;
+}
+
+int main() {
+ printf("%d", compte_mots(" bonjour je suis un mot "));
+}
diff --git a/semestre 2/informatique/tme/semaine5/28_participation_frais.c b/semestre 2/informatique/tme/semaine5/28_participation_frais.c
new file mode 100644
index 0000000..e5aff0d
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine5/28_participation_frais.c
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#define NB_AMIS 4
+#define NB_JOURS 7
+
+void init_tab(float tab[NB_AMIS][NB_JOURS]){
+ for (int i = 0; i < NB_AMIS; i++) {
+ for (int j = 0; j < NB_JOURS; j++) tab[i][j] = 0;
+ }
+}
+
+void random_tab(float tab[NB_AMIS][NB_JOURS], int j) {
+ int a = rand()%NB_AMIS;
+ int v = rand()%21+30;
+ tab[a][j] = v;
+ for (int i = 0; i < NB_AMIS; i++) {
+ if (i != a) tab[i][j] = (float) v/(-NB_AMIS+1);
+ }
+}
+
+void show_tab(float tab[NB_AMIS][NB_JOURS]){
+ printf("Jour/Ami||\t");
+ for (int i = 0; i < NB_AMIS; i++) printf("%d\t|\t", i+1);
+ printf("\n");
+ for (int i = 0; i < NB_AMIS*18; i++) printf("-");
+ printf("\n");
+ for (int j = 0; j < NB_JOURS;j++){
+ for (int i = 0; i < NB_AMIS; i++) {
+ if (i == 0) printf("%d\t||\t", j+1);
+ printf("%.2f\t|\t", tab[i][j]);
+ if (i == NB_AMIS-1) printf("\n");
+ }
+ }
+}
+
+void show_solde(float tab[NB_AMIS][NB_JOURS], int a){
+ float s = 0;
+ for (int j = 0; j < NB_JOURS; j++) s += tab[a][j];
+ printf("Ami %d a pour solde %.02f\n", a, s);
+}
+
+int main() {
+ float tab[NB_AMIS][NB_JOURS] = {};
+ srand(time(NULL));
+ init_tab(tab);
+ for (int d = 0; d < NB_JOURS; d++) random_tab(tab, d);
+ show_tab(tab);
+ for (int i = 0; i < NB_AMIS; i++) show_solde(tab, i);
+ return 0;
+}
+
diff --git a/semestre 2/informatique/tme/semaine5/29_filtre.c b/semestre 2/informatique/tme/semaine5/29_filtre.c
new file mode 100644
index 0000000..37a5625
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine5/29_filtre.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+void show_filtre(char *s){
+ for (int i = 0; s[i] != '\0'; i++) {
+ if (s[i] >= 'A' && s[i] <= 'z') printf("%c", s[i]);
+ }
+}
+
+char *filtre(char *s) {
+ char *ns = malloc(sizeof(char) * strlen(s));
+ int j = 0;
+ for (int i = 0; s[i] != '\0'; i++){
+ if (s[i] >= 'A' && s[i] <= 'z') ns[j++] = s[i];
+ }
+ return ns;
+}
+
+int main() {
+ char *s = "Hello World! What's up guys?";
+ show_filtre(s);
+ printf("\n%s\n", filtre(s));
+ return 0;
+}
diff --git a/semestre 2/informatique/tme/semaine5/30_compression.c b/semestre 2/informatique/tme/semaine5/30_compression.c
new file mode 100644
index 0000000..161cd00
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine5/30_compression.c
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#define MIN 2
+#define MAX 15
+
+int init_tab(int tab[MAX+1]) {
+ int size = rand()%(MAX-MIN+1)+MIN;
+ for (int i = 0; i < size; i++) {
+ tab[i] = rand()%2;
+ }
+ tab[size] = -1;
+ return size;
+}
+
+void compress_tab(int tab_brut[], int tab_compress[]){
+ int j = 0;
+ int last = -1;
+ int cnt = 0;
+ for (int i = 0; tab_brut[i] != -1; i++) {
+ if (last == -1 || tab_brut[i] != last) {
+ if (last != -1) {
+ int id = j++;
+ tab_compress[id*2] = cnt;
+ tab_compress[id*2+1] = last;
+ }
+ last = tab_brut[i];
+ cnt = 0;
+ }
+ cnt++;
+ }
+ if (last != -1) {
+ int id = j++;
+ tab_compress[id*2] = cnt;
+ tab_compress[id*2+1] = last;
+ }
+ tab_compress[j*2] = -1;
+}
+
+int compare(int tab_brut[], int tab_compress[]){
+ int j = 0;
+ for (int i = 0; tab_compress[i] != -1; i += 2) {
+ int n = tab_compress[i];
+ int v = tab_compress[i+1];
+ for (int cnt = 0; cnt < n; cnt++) {
+ if (tab_brut[j++] != v) return 0;
+ }
+ }
+ return 1;
+}
+
+int main(){
+ srand(time(NULL));
+ int tab[MAX+1] = {};
+ int tab_compress[MAX+1] = {};
+ init_tab(tab);
+ compress_tab(tab, tab_compress);
+ for (int i = 0; tab[i] != -1; i++) printf("%d, ", tab[i]);
+ printf("\n");
+ for (int i = 0; tab_compress[i] != -1; i += 2) printf("%d:%d, ", tab_compress[i], tab_compress[i+1]);
+ printf("\n");
+ printf("%s", compare(tab, tab_compress) ? "True" : "False");
+ return 0;
+}
diff --git a/semestre 2/informatique/tme/semaine5/31_image_mystere.c b/semestre 2/informatique/tme/semaine5/31_image_mystere.c
new file mode 100644
index 0000000..51ca321
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine5/31_image_mystere.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+void calcule_borne_sup(int *tab, int taille){
+ int dec = -1;
+ for (int i = 0; i < taille; i++) {
+ tab[i] += dec;
+ dec = tab[i];
+ }
+}
+
+int tire_non_equi(int *tab, int taille){
+ int tire = rand()%100;
+ int i;
+ for (i = taille -1; tab[i] > tire; i--);
+ printf("%d - %d <= %d\n", i, tab[i], tire);
+ return i;
+}
+
+int main() {
+ srand(time(NULL));
+ int tab[] = {17, 28, 50, 5};
+ calcule_borne_sup(tab, 4);
+ for (int i = 0; i < 4; i++) printf("%d, ", tab[i]);
+ printf("\n");
+ printf("%d", tire_non_equi(tab, 4));
+ return 0;
+}