-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlireetdire.cpp
More file actions
71 lines (62 loc) · 1.51 KB
/
lireetdire.cpp
File metadata and controls
71 lines (62 loc) · 1.51 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
using namespace std;
int separer_chiffre_gauche(int& nombre)
{
int dix(1);
int temp(nombre);
while (temp >= 10) {
dix *= 10;
temp /= 10;
}
nombre %= dix;
return temp;
}
/*****************************************************
* Compléter le code à partir d'ici
*****************************************************/
void ajouter_chiffre_droit(int& nombre, int chiffre)
{
nombre *= 10;
nombre += chiffre;
}
void dire_chiffre(int& nombre, int repetitions_chiffre, int chiffre)
{
ajouter_chiffre_droit(nombre, repetitions_chiffre);
ajouter_chiffre_droit(nombre, chiffre);
}
int lire_et_dire(int& nombre)
{
int resultat = 0;
int counter = 1;
do {
int temp = separer_chiffre_gauche(nombre);
int nombre_temp = nombre;
int next_temp = separer_chiffre_gauche(nombre_temp);
if (temp == next_temp) {
counter +=1;
} else {
dire_chiffre(resultat,counter, temp);
counter = 1;
}
}while(nombre>0);
nombre = resultat;
return(nombre);
}
/*******************************************
* Ne rien modifier après cette ligne.
*******************************************/
void repeter_lire_et_dire(int& nombre, int fois)
{
while (fois-- > 0) {
nombre = lire_et_dire(nombre);
}
}
int main()
{
int nombre(1);
int fois(1);
cin >> nombre >> fois;
repeter_lire_et_dire(nombre, fois);
cout << nombre << endl;
return 0;
}