Skip to content
Snippets Groups Projects
Commit 305b9e06 authored by Nicolas Ledesma's avatar Nicolas Ledesma
Browse files

clean up folder

parent 60d7e3bc
No related branches found
No related tags found
No related merge requests found
Showing
with 1254 additions and 0 deletions
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>README</title>
<style>
html {
color: #1a1a1a;
background-color: #fdfdfd;
}
body {
margin: 0 auto;
max-width: 36em;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 50px;
hyphens: auto;
overflow-wrap: break-word;
text-rendering: optimizeLegibility;
font-kerning: normal;
}
@media (max-width: 600px) {
body {
font-size: 0.9em;
padding: 12px;
}
h1 {
font-size: 1.8em;
}
}
@media print {
html {
background-color: white;
}
body {
background-color: transparent;
color: black;
font-size: 12pt;
}
p, h2, h3 {
orphans: 3;
widows: 3;
}
h2, h3, h4 {
page-break-after: avoid;
}
}
p {
margin: 1em 0;
}
a {
color: #1a1a1a;
}
a:visited {
color: #1a1a1a;
}
img {
max-width: 100%;
}
svg {
height: auto;
max-width: 100%;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 1.4em;
}
h5, h6 {
font-size: 1em;
font-style: italic;
}
h6 {
font-weight: normal;
}
ol, ul {
padding-left: 1.7em;
margin-top: 1em;
}
li > ol, li > ul {
margin-top: 0;
}
blockquote {
margin: 1em 0 1em 1.7em;
padding-left: 1em;
border-left: 2px solid #e6e6e6;
color: #606060;
}
code {
font-family: Menlo, Monaco, Consolas, 'Lucida Console', monospace;
font-size: 85%;
margin: 0;
hyphens: manual;
}
pre {
margin: 1em 0;
overflow: auto;
}
pre code {
padding: 0;
overflow: visible;
overflow-wrap: normal;
}
.sourceCode {
background-color: transparent;
overflow: visible;
}
hr {
background-color: #1a1a1a;
border: none;
height: 1px;
margin: 1em 0;
}
table {
margin: 1em 0;
border-collapse: collapse;
width: 100%;
overflow-x: auto;
display: block;
font-variant-numeric: lining-nums tabular-nums;
}
table caption {
margin-bottom: 0.75em;
}
tbody {
margin-top: 0.5em;
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
}
th {
border-top: 1px solid #1a1a1a;
padding: 0.25em 0.5em 0.25em 0.5em;
}
td {
padding: 0.125em 0.5em 0.25em 0.5em;
}
header {
margin-bottom: 4em;
text-align: center;
}
#TOC li {
list-style: none;
}
#TOC ul {
padding-left: 1.3em;
}
#TOC > ul {
padding-left: 0;
}
#TOC a:not(:hover) {
text-decoration: none;
}
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
/* The extra [class] is a hack that increases specificity enough to
override a similar rule in reveal.js */
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
</head>
<body>
<h1 id="test-de-programmation-séquentielle">Test de programmation
séquentielle</h1>
<p>Lisez ce texte attentivement et <strong>JUSQU’À LA FIN</strong> !</p>
<h2 id="énoncés">Énoncés</h2>
<p>Les énoncés ainsi qu’un exécutable d’exemple des trois exercices de
ce test se trouvent dans le répertoire <code>enonces</code> et ont la
structure suivante :</p>
<pre><code>├── enonces
│ ├── ex1
│ │ ├── README.html
│ │ ├── ex1
│ ├── ex2
│ │ ├── README.html
│ │ ├── ex2
│ ├── ex3
│ │ ├── README.html
│ │ ├── ex3</code></pre>
<h2 id="templates">Templates</h2>
<p>Votre projet est à effectuer dans le répertoire
<code>templates</code>. Votre projet a la structure suivante (il y a un
template dans le répertoire <code>templates</code>) :</p>
<pre><code>├── templates
│ ├── ex1
│ │ ├── Makefile
│ │ ├── ex1.c
│ ├── ex2
│ │ ├── Makefile
│ │ ├── ex2.c
│ ├── ex3
│ │ ├── Makefile
│ │ ├── ex3.c</code></pre>
<h2 id="examen">Examen</h2>
<p>Le test est composé de trois exercices. Vous n’avez droit qu’à une
feuille A4 recto-verso de notes, ainsi que les slides des cours de
programmation séquentielle et d’algorithmique se trouvant dans le
système de fichier.</p>
<p>Il y a <strong>trois</strong> exercices, et un seul fichier
<code>.c</code> par exercice avec son <code>Makefile</code>. La commande
<code>make</code> doit uniquement permettre de compiler le projet et
générer un exécutable nommé <code>ex1</code>, <code>ex2</code>,
<code>ex3</code>. Par soucis de simplicité, nous vous recommendons de
tout faire dans le fichier <code>.c</code> prévu à cet effet. Si vous
désirez séparer votre code dans divers fichiers, vous en assumerez
l’entière responsabilité. Il faudra absolument corriger le
<code>Makefile</code> pour que tout compile proprement et que nous
puissions évaluer votre travail.</p>
<p>Un code qui ne compile pas ne sera <strong>pas évalué</strong> !
Ainsi, il vaut mieux rendre quelque chose qui compile mais qui donne un
résultat faux (ou avec des erreurs à l’exécution), plutôt qu’un code qui
ne compile pas mais que vous pensez plus proche de la solution.</p>
<p>Le test dure de 18h30 à 21h30.</p>
<p>Si un exercice ne vous semble pas clair demandez-nous des
précisions.</p>
</body>
</html>
# Test de programmation séquentielle
Lisez ce texte attentivement et **JUSQU’À LA FIN** !
## Énoncés
Les énoncés ainsi qu’un exécutable d’exemple des trois exercices de ce test se trouvent dans le répertoire `enonces` et ont la structure suivante :
```
├── enonces
│ ├── ex1
│ │ ├── README.html
│ │ ├── ex1
│ ├── ex2
│ │ ├── README.html
│ │ ├── ex2
│ ├── ex3
│ │ ├── README.html
│ │ ├── ex3
```
## Templates
Votre projet est à effectuer dans le répertoire `templates`.
Votre projet a la structure suivante (il y a un template dans le répertoire `templates`) :
```
├── templates
│ ├── ex1
│ │ ├── Makefile
│ │ ├── ex1.c
│ ├── ex2
│ │ ├── Makefile
│ │ ├── ex2.c
│ ├── ex3
│ │ ├── Makefile
│ │ ├── ex3.c
```
## Examen
Le test est composé de trois exercices.
Vous n’avez droit qu’à une feuille A4 recto-verso de notes, ainsi que les slides des cours de programmation séquentielle et d’algorithmique se trouvant dans le système de fichier.
Il y a **trois** exercices, et un seul fichier `.c` par exercice avec son `Makefile`.
La commande `make` doit uniquement permettre de compiler le projet et générer un exécutable nommé `ex1`, `ex2`, `ex3`.
Par soucis de simplicité, nous vous recommendons de tout faire dans le fichier `.c` prévu à cet effet.
Si vous désirez séparer votre code dans divers fichiers, vous en assumerez l’entière responsabilité.
Il faudra absolument corriger le `Makefile` pour que tout compile proprement et que nous puissions évaluer votre travail.
Un code qui ne compile pas ne sera **pas évalué** !
Ainsi, il vaut mieux rendre quelque chose qui compile mais qui donne un résultat faux (ou avec des erreurs à l’exécution), plutôt qu’un code qui ne compile pas mais que vous pensez plus proche de la solution.
Le test dure de 18h30 à 21h30.
Si un exercice ne vous semble pas clair demandez-nous des précisions.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>README</title>
<style>
html {
color: #1a1a1a;
background-color: #fdfdfd;
}
body {
margin: 0 auto;
max-width: 36em;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 50px;
hyphens: auto;
overflow-wrap: break-word;
text-rendering: optimizeLegibility;
font-kerning: normal;
}
@media (max-width: 600px) {
body {
font-size: 0.9em;
padding: 12px;
}
h1 {
font-size: 1.8em;
}
}
@media print {
html {
background-color: white;
}
body {
background-color: transparent;
color: black;
font-size: 12pt;
}
p, h2, h3 {
orphans: 3;
widows: 3;
}
h2, h3, h4 {
page-break-after: avoid;
}
}
p {
margin: 1em 0;
}
a {
color: #1a1a1a;
}
a:visited {
color: #1a1a1a;
}
img {
max-width: 100%;
}
svg {
height: auto;
max-width: 100%;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 1.4em;
}
h5, h6 {
font-size: 1em;
font-style: italic;
}
h6 {
font-weight: normal;
}
ol, ul {
padding-left: 1.7em;
margin-top: 1em;
}
li > ol, li > ul {
margin-top: 0;
}
blockquote {
margin: 1em 0 1em 1.7em;
padding-left: 1em;
border-left: 2px solid #e6e6e6;
color: #606060;
}
code {
font-family: Menlo, Monaco, Consolas, 'Lucida Console', monospace;
font-size: 85%;
margin: 0;
hyphens: manual;
}
pre {
margin: 1em 0;
overflow: auto;
}
pre code {
padding: 0;
overflow: visible;
overflow-wrap: normal;
}
.sourceCode {
background-color: transparent;
overflow: visible;
}
hr {
background-color: #1a1a1a;
border: none;
height: 1px;
margin: 1em 0;
}
table {
margin: 1em 0;
border-collapse: collapse;
width: 100%;
overflow-x: auto;
display: block;
font-variant-numeric: lining-nums tabular-nums;
}
table caption {
margin-bottom: 0.75em;
}
tbody {
margin-top: 0.5em;
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
}
th {
border-top: 1px solid #1a1a1a;
padding: 0.25em 0.5em 0.25em 0.5em;
}
td {
padding: 0.125em 0.5em 0.25em 0.5em;
}
header {
margin-bottom: 4em;
text-align: center;
}
#TOC li {
list-style: none;
}
#TOC ul {
padding-left: 1.3em;
}
#TOC > ul {
padding-left: 0;
}
#TOC a:not(:hover) {
text-decoration: none;
}
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
/* The extra [class] is a hack that increases specificity enough to
override a similar rule in reveal.js */
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
</head>
<body>
<h1 id="exercice-1-lancer-de-dés">Exercice 1 : Lancer de dés</h1>
<p>Dans cet exercice, il faut simuler un lancer de dé à six faces,
compter le nombre d’occurrence de chaque résultat et stocker ces nombres
dans un tableau. À la fin de l’exécution, il faut afficher le nombre de
fois où chaque nombre est obtenu ainsi que son taux d’apparition. Le
nombre de lancer de dés est à lire sur la ligne de commande. Ainsi le
lancement de votre programme doit être</p>
<pre class="console"><code>./ex1 &lt;N&gt;</code></pre>
<p><code>N</code> est le nombre de fois où le dé est lancé.</p>
<p><strong>Attention:</strong> Vous devez initialiser votre générateur
de nombres aléatoire avec la graine <code>0</code>.</p>
<h2 id="exécutions">Exécutions</h2>
<p>L’exécution du programme suivant doit donner exactement cette
solution :</p>
<pre class="console"><code>./ex1 100
La face 1 est sortie 17 fois, soit 17.0%.
La face 2 est sortie 18 fois, soit 18.0%.
La face 3 est sortie 23 fois, soit 23.0%.
La face 4 est sortie 18 fois, soit 18.0%.
La face 5 est sortie 12 fois, soit 12.0%.
La face 6 est sortie 12 fois, soit 12.0%.</code></pre>
<pre class="console"><code>./ex1 1000
La face 1 est sortie 173 fois, soit 17.3%.
La face 2 est sortie 150 fois, soit 15.0%.
La face 3 est sortie 179 fois, soit 17.9%.
La face 4 est sortie 181 fois, soit 18.1%.
La face 5 est sortie 155 fois, soit 15.5%.
La face 6 est sortie 162 fois, soit 16.2%.</code></pre>
<pre class="console"><code>./ex1 10001
La face 1 est sortie 1651 fois, soit 16.5%.
La face 2 est sortie 1622 fois, soit 16.2%.
La face 3 est sortie 1743 fois, soit 17.4%.
La face 4 est sortie 1673 fois, soit 16.7%.
La face 5 est sortie 1693 fois, soit 16.9%.
La face 6 est sortie 1619 fois, soit 16.2%.</code></pre>
</body>
</html>
# Exercice 1 : Lancer de dés
Dans cet exercice, il faut simuler un lancer de dé à six faces, compter le nombre d'occurrence de chaque résultat et stocker ces nombres dans un tableau.
À la fin de l'exécution, il faut afficher le nombre de fois où chaque nombre est obtenu ainsi que son taux d’apparition.
Le nombre de lancer de dés est à lire sur la ligne de commande.
Ainsi le lancement de votre programme doit être
```console
./ex1 <N>
```
`N` est le nombre de fois où le dé est lancé.
**Attention:** Vous devez initialiser votre générateur de nombres aléatoire avec la graine `0`.
## Exécutions
L'exécution du programme suivant doit donner exactement cette solution :
```console
./ex1 100
La face 1 est sortie 17 fois, soit 17.0%.
La face 2 est sortie 18 fois, soit 18.0%.
La face 3 est sortie 23 fois, soit 23.0%.
La face 4 est sortie 18 fois, soit 18.0%.
La face 5 est sortie 12 fois, soit 12.0%.
La face 6 est sortie 12 fois, soit 12.0%.
```
```console
./ex1 1000
La face 1 est sortie 173 fois, soit 17.3%.
La face 2 est sortie 150 fois, soit 15.0%.
La face 3 est sortie 179 fois, soit 17.9%.
La face 4 est sortie 181 fois, soit 18.1%.
La face 5 est sortie 155 fois, soit 15.5%.
La face 6 est sortie 162 fois, soit 16.2%.
```
```console
./ex1 10001
La face 1 est sortie 1651 fois, soit 16.5%.
La face 2 est sortie 1622 fois, soit 16.2%.
La face 3 est sortie 1743 fois, soit 17.4%.
La face 4 est sortie 1673 fois, soit 16.7%.
La face 5 est sortie 1693 fois, soit 16.9%.
La face 6 est sortie 1619 fois, soit 16.2%.
```
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>README</title>
<style>
html {
color: #1a1a1a;
background-color: #fdfdfd;
}
body {
margin: 0 auto;
max-width: 36em;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 50px;
hyphens: auto;
overflow-wrap: break-word;
text-rendering: optimizeLegibility;
font-kerning: normal;
}
@media (max-width: 600px) {
body {
font-size: 0.9em;
padding: 12px;
}
h1 {
font-size: 1.8em;
}
}
@media print {
html {
background-color: white;
}
body {
background-color: transparent;
color: black;
font-size: 12pt;
}
p, h2, h3 {
orphans: 3;
widows: 3;
}
h2, h3, h4 {
page-break-after: avoid;
}
}
p {
margin: 1em 0;
}
a {
color: #1a1a1a;
}
a:visited {
color: #1a1a1a;
}
img {
max-width: 100%;
}
svg {
height: auto;
max-width: 100%;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 1.4em;
}
h5, h6 {
font-size: 1em;
font-style: italic;
}
h6 {
font-weight: normal;
}
ol, ul {
padding-left: 1.7em;
margin-top: 1em;
}
li > ol, li > ul {
margin-top: 0;
}
blockquote {
margin: 1em 0 1em 1.7em;
padding-left: 1em;
border-left: 2px solid #e6e6e6;
color: #606060;
}
code {
font-family: Menlo, Monaco, Consolas, 'Lucida Console', monospace;
font-size: 85%;
margin: 0;
hyphens: manual;
}
pre {
margin: 1em 0;
overflow: auto;
}
pre code {
padding: 0;
overflow: visible;
overflow-wrap: normal;
}
.sourceCode {
background-color: transparent;
overflow: visible;
}
hr {
background-color: #1a1a1a;
border: none;
height: 1px;
margin: 1em 0;
}
table {
margin: 1em 0;
border-collapse: collapse;
width: 100%;
overflow-x: auto;
display: block;
font-variant-numeric: lining-nums tabular-nums;
}
table caption {
margin-bottom: 0.75em;
}
tbody {
margin-top: 0.5em;
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
}
th {
border-top: 1px solid #1a1a1a;
padding: 0.25em 0.5em 0.25em 0.5em;
}
td {
padding: 0.125em 0.5em 0.25em 0.5em;
}
header {
margin-bottom: 4em;
text-align: center;
}
#TOC li {
list-style: none;
}
#TOC ul {
padding-left: 1.3em;
}
#TOC > ul {
padding-left: 0;
}
#TOC a:not(:hover) {
text-decoration: none;
}
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
/* The extra [class] is a hack that increases specificity enough to
override a similar rule in reveal.js */
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
</head>
<body>
<h1 id="exercice-2-occurrences-dune-sous-chaine">Exercice 2 :
occurrences d’une sous-chaine</h1>
<p>On souhaite écrire un programme qui permet de compter le nombre
d’occurrences d’une sous-chaine de caractères dans une chaine de
caractères.</p>
<p>Votre détection ne doit pas être sensible à la casse (c’est à dire il
ne doit pas y avoir de différence entre les minuscules et les
majuscules).</p>
<p>Ainsi pour la chaine <code>Neeeeed</code> :</p>
<ul>
<li>et la sous-chaine <code>eee</code> le résultat est
<code>3</code> ;</li>
<li>et la sous-chaine <code>ne</code> le résultat est
<code>1</code> ;</li>
<li>et la sous-chaine <code>Pierre</code> le résultat est
<code>0</code>.</li>
</ul>
<h2 id="paramètres">Paramètres</h2>
<p>Les deux chaines doivent être passées au programme comme paramètres
de la fonction <code>main</code>. Le lancement de votre programme doit
être :</p>
<pre class="console"><code>./ex2 &lt;mot&gt; &lt;sous-chaine&gt;</code></pre>
<p><em>Pensez à contrôler ces paramètres.</em></p>
<h2 id="affichage">Affichage</h2>
<p>Votre programme doit afficher le résultat en fin d’exécution.</p>
<h2 id="indications">Indications</h2>
<p>La table des caractères <a
href="https://fr.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange">ASCII</a>
peut vous être utile.</p>
<pre><code> Dec Char Dec Char Dec Char Dec Char
---------- --------- --------- ----------
0 NUL 32 SPACE 64 @ 96 `
1 SOH 33 ! 65 A 97 a
2 STX 34 &quot; 66 B 98 b
3 ETX 35 # 67 C 99 c
4 EOT 36 $ 68 D 100 d
5 ENQ 37 % 69 E 101 e
6 ACK 38 &amp; 70 F 102 f
7 BEL 39 &#39; 71 G 103 g
8 BS 40 ( 72 H 104 h
9 TAB 41 ) 73 I 105 i
10 LF 42 * 74 J 106 j
11 VT 43 + 75 K 107 k
12 FF 44 , 76 L 108 l
13 CR 45 - 77 M 109 m
14 SO 46 . 78 N 110 n
15 SI 47 / 79 O 111 o
16 DLE 48 0 80 P 112 p
17 DC1 49 1 81 Q 113 q
18 DC2 50 2 82 R 114 r
19 DC3 51 3 83 S 115 s
20 DC4 52 4 84 T 116 t
21 NAK 53 5 85 U 117 u
22 SYN 54 6 86 V 118 v
23 ETB 55 7 87 W 119 w
24 CAN 56 8 88 X 120 x
25 EM 57 9 89 Y 121 y
26 SUB 58 : 90 Z 122 z
27 ESC 59 ; 91 [ 123 {
28 FS 60 &lt; 92 \ 124 |
29 GS 61 = 93 ] 125 }
30 RS 62 &gt; 94 ^ 126 ~
31 US 63 ? 95 _ 127 DEL</code></pre>
</body>
</html>
# Exercice 2 : occurrences d’une sous-chaine
On souhaite écrire un programme qui permet de compter le nombre d’occurrences d’une sous-chaine de caractères dans une chaine de caractères.
Votre détection ne doit pas être sensible à la casse (c’est à dire il ne doit pas y avoir de différence entre les minuscules et les majuscules).
Ainsi pour la chaine `Neeeeed` :
- et la sous-chaine `eee` le résultat est `3` ;
- et la sous-chaine `ne` le résultat est `1` ;
- et la sous-chaine `Pierre` le résultat est `0`.
## Paramètres
Les deux chaines doivent être passées au programme comme paramètres de la fonction `main`.
Le lancement de votre programme doit être :
```console
./ex2 <mot> <sous-chaine>
```
*Pensez à contrôler ces paramètres.*
## Affichage
Votre programme doit afficher le résultat en fin d’exécution.
## Indications
La table des caractères [ASCII](https://fr.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange) peut vous être utile.
```
Dec Char Dec Char Dec Char Dec Char
---------- --------- --------- ----------
0 NUL 32 SPACE 64 @ 96 `
1 SOH 33 ! 65 A 97 a
2 STX 34 " 66 B 98 b
3 ETX 35 # 67 C 99 c
4 EOT 36 $ 68 D 100 d
5 ENQ 37 % 69 E 101 e
6 ACK 38 & 70 F 102 f
7 BEL 39 ' 71 G 103 g
8 BS 40 ( 72 H 104 h
9 TAB 41 ) 73 I 105 i
10 LF 42 * 74 J 106 j
11 VT 43 + 75 K 107 k
12 FF 44 , 76 L 108 l
13 CR 45 - 77 M 109 m
14 SO 46 . 78 N 110 n
15 SI 47 / 79 O 111 o
16 DLE 48 0 80 P 112 p
17 DC1 49 1 81 Q 113 q
18 DC2 50 2 82 R 114 r
19 DC3 51 3 83 S 115 s
20 DC4 52 4 84 T 116 t
21 NAK 53 5 85 U 117 u
22 SYN 54 6 86 V 118 v
23 ETB 55 7 87 W 119 w
24 CAN 56 8 88 X 120 x
25 EM 57 9 89 Y 121 y
26 SUB 58 : 90 Z 122 z
27 ESC 59 ; 91 [ 123 {
28 FS 60 < 92 \ 124 |
29 GS 61 = 93 ] 125 }
30 RS 62 > 94 ^ 126 ~
31 US 63 ? 95 _ 127 DEL
```
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>README</title>
<style>
html {
color: #1a1a1a;
background-color: #fdfdfd;
}
body {
margin: 0 auto;
max-width: 36em;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 50px;
hyphens: auto;
overflow-wrap: break-word;
text-rendering: optimizeLegibility;
font-kerning: normal;
}
@media (max-width: 600px) {
body {
font-size: 0.9em;
padding: 12px;
}
h1 {
font-size: 1.8em;
}
}
@media print {
html {
background-color: white;
}
body {
background-color: transparent;
color: black;
font-size: 12pt;
}
p, h2, h3 {
orphans: 3;
widows: 3;
}
h2, h3, h4 {
page-break-after: avoid;
}
}
p {
margin: 1em 0;
}
a {
color: #1a1a1a;
}
a:visited {
color: #1a1a1a;
}
img {
max-width: 100%;
}
svg {
height: auto;
max-width: 100%;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 1.4em;
}
h5, h6 {
font-size: 1em;
font-style: italic;
}
h6 {
font-weight: normal;
}
ol, ul {
padding-left: 1.7em;
margin-top: 1em;
}
li > ol, li > ul {
margin-top: 0;
}
blockquote {
margin: 1em 0 1em 1.7em;
padding-left: 1em;
border-left: 2px solid #e6e6e6;
color: #606060;
}
code {
font-family: Menlo, Monaco, Consolas, 'Lucida Console', monospace;
font-size: 85%;
margin: 0;
hyphens: manual;
}
pre {
margin: 1em 0;
overflow: auto;
}
pre code {
padding: 0;
overflow: visible;
overflow-wrap: normal;
}
.sourceCode {
background-color: transparent;
overflow: visible;
}
hr {
background-color: #1a1a1a;
border: none;
height: 1px;
margin: 1em 0;
}
table {
margin: 1em 0;
border-collapse: collapse;
width: 100%;
overflow-x: auto;
display: block;
font-variant-numeric: lining-nums tabular-nums;
}
table caption {
margin-bottom: 0.75em;
}
tbody {
margin-top: 0.5em;
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
}
th {
border-top: 1px solid #1a1a1a;
padding: 0.25em 0.5em 0.25em 0.5em;
}
td {
padding: 0.125em 0.5em 0.25em 0.5em;
}
header {
margin-bottom: 4em;
text-align: center;
}
#TOC li {
list-style: none;
}
#TOC ul {
padding-left: 1.3em;
}
#TOC > ul {
padding-left: 0;
}
#TOC a:not(:hover) {
text-decoration: none;
}
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
/* The extra [class] is a hack that increases specificity enough to
override a similar rule in reveal.js */
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
</head>
<body>
<h1 id="exercice-3-fusion-de-tableaux">Exercice 3 : fusion de
tableaux</h1>
<p>On désire implémenter une fonction <code>fusion</code> qui prend deux
chaînes de caractères en argument et renvoie une chaîne de caractères
dans laquelle les lettres sont prises alternativement de la première et
de la seconde chaîne. Lorsque toutes les lettres d’une des deux chaînes
ont été prises, on copie simplement toutes les lettres restantes dans la
chaîne finale.</p>
<p>Toutes les <strong>allocations de mémoire de tableaux</strong>
doivent être faites <strong>dynamiquement</strong>. Pensez donc à bien
libérer la mémoire.</p>
<p>Ainsi pour les exécutions suivantes, on aura comme résultat :</p>
<pre><code>./ex3 Mary Louise
Chaîne fusionnée: MLaoruyise</code></pre>
<pre><code>./ex3 Wollstonecraft Michel
Chaîne fusionnée: WMoilclhsetlonecraft</code></pre>
<h2 id="compilation">Compilation</h2>
<p>Vous noterez que le <em>Makefile</em> fourni contient les options de
compilation suivantes :</p>
<pre><code>-g -fsanitize=address -fsanitize=undefined -fsanitize=leak</code></pre>
</body>
</html>
# Exercice 3 : fusion de tableaux
On désire implémenter une fonction `fusion` qui prend deux chaînes de caractères en argument et renvoie une chaîne de caractères dans laquelle les lettres sont prises alternativement de la première et de la seconde chaîne.
Lorsque toutes les lettres d’une des deux chaînes ont été prises, on copie simplement toutes les lettres restantes dans la chaîne finale.
Toutes les **allocations de mémoire de tableaux** doivent être faites **dynamiquement**.
Pensez donc à bien libérer la mémoire.
Ainsi pour les exécutions suivantes, on aura comme résultat :
```
./ex3 Mary Louise
Chaîne fusionnée: MLaoruyise
```
```
./ex3 Wollstonecraft Michel
Chaîne fusionnée: WMoilclhsetlonecraft
```
## Compilation
Vous noterez que le *Makefile* fourni contient les options de compilation suivantes :
```
-g -fsanitize=address -fsanitize=undefined -fsanitize=leak
```
CC = gcc -std=c11 -g
CFLAGS = -Wall -Wextra -Wpedantic
main: main.c ex1.c ex1.h
$(CC) $(CFLAGS) -o $@ main.c ex1.c
run: main
./main 100
clean:
rm -f main
\ No newline at end of file
#include "ex1.h"
//Helper functions
int rand_gen(int max_faces){
return rand() % max_faces + 1;
}
void int_to_array(int *tab, int size){
for(int i = 0;i < size;i++){
tab[i] = rand_gen(MAX_FACES);
}
}
void count_occ(int *tab, int size){
int occ[MAX_FACES] = {0};
//count
for(int i = 0;i < size;i++){
if(tab[i] >= 1 && tab[i] < MAX_FACES){
occ[tab[i]- 1]++;
}
}
//Print
for(int i = 1; i <= MAX_FACES;i++){
double percentage = (occ[i-1])/((double)size) * 100.0;
printf("Face %d: %d occurences, %.2f%%\n", i, occ[i -1], percentage);
}
}
#ifndef EX1_H
#define EX1_H
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX_FACES 6
int rand_gen(int max_faces);
void int_to_array(int *tab, int size);
void count_occ(int *tab, int size);
#endif
\ No newline at end of file
File added
#include "ex1.h"
int main(int argc, char *argv[]) {
if(argc != 2){
fprintf(stderr,"Usage:<%s><number of tries>", argv[0]);
return EXIT_FAILURE;
}
srand(time(NULL));
int num_tries = atoi(argv[1]);
if (num_tries <= 0) {
fprintf(stderr, "Number of tries must be positive\n");
return EXIT_FAILURE;
}
int *tab = (int *)malloc(num_tries * sizeof(int));
if (tab == NULL) {
fprintf(stderr, "Memory allocation failed\n");
return EXIT_FAILURE;
}
int_to_array(tab,num_tries);
count_occ(tab, num_tries);
free(tab);
return EXIT_SUCCESS;
}
CC = gcc -std=c11 -g
CFLAGS = -Wall -Wextra -Wpedantic
main: main.c ex2.c ex2.h
${CC} ${CFLAGS} -o $@ main.c ex2.c
run: main
./main Neeeeed eee
clean:
rm -f main
#include "ex2.h"
int sub_string_occ(char *s_str, char *str){
int count = 0;
char *tmp_str = str;
while((tmp_str = strstr(tmp_str,s_str)) != NULL){
count ++;
tmp_str ++;
}
return count;
}
#ifndef EX2_H
#define EX2_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
int sub_string_occ(char *s_str, char *str);
#endif
\ No newline at end of file
File added
#include "ex2.h"
int main(int argc, char *argv[]) {
if(argc != 3){
fprintf(stderr,"Usage:<%s><string><sub-string>\n",argv[0]);
return EXIT_FAILURE;
}
char *str = (char *)malloc((strlen(argv[1]) + 1) * sizeof(char));
if(str == NULL){
fprintf(stderr,"Memory allocation error\n");
}
char *s_str = (char *)malloc((strlen(argv[2]) + 1) * sizeof(char));
if(str == NULL){
fprintf(stderr,"Memory allocation error\n");
free(str);
}
str = argv[1];
s_str = argv[2];
int count_s_str = sub_string_occ(s_str,str);
printf("For sub-string (%s) there are (%d) occurences in string (%s) \n",argv[2], count_s_str, argv[1]);
//free(str);
//free(s_str);
return EXIT_SUCCESS;
}
CC = gcc -std=c11 -g
CFLAGS = -Wall -Wextra -Wpedantic
SANITIZER = -fsanitize=leak -fsanitize=undefined -fsanitize=address
main: main.c ex3.c ex3.h
${CC} ${CFLAGS} ${SANITIZER} -o $@ main.c ex3.c
run: main
./main Mary Louise
clean:
rm -f main
#include "ex3.h"
char *fusion(char *str1, char *str2, char *tmp_str){
int len_1 = strlen(str1);
int len_2 = strlen(str2);
int len = len_1 + len_2;
int i_1 = 0, i_2 = 0;
for(int i = 0;i < len;i++){
if(i % 2 == 0 && i_1 < len_1){
tmp_str[i] = str1[i_1++];
}else if(i_2 < len_2){
tmp_str[i] = str2[i_2++];
}
}
tmp_str[len] = '\0';
return tmp_str;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment