5eb7fe63
Vincent Benoist
TP de C
|
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#include <stdio.h>
#include <string.h>
#define N 50
void setChaine (char *vect){
scanf("%s", vect);
}
void afficheCar (char car, char nb){
int nba;
nba = nb - '0';
int i ;
for(i=1; i <= nba; i++){
printf("%c", car);
}
}
void insererCar (char * ch, char car, int* ind, char nb){
int i ;
int nba;
nba = nb - '0';
for(i=(*ind); i < (*ind)+nba; i++){
ch[i] = car;
}
*ind = *ind + nba;
}
int chiffre(char ch){
if ((ch >= '0') && (ch <= '9')){
return 1;
}else{
return 0;
}
}
int minuscule(char ch){
if ((ch >= 'a') && (ch <= 'z')){
return 1;
}else{
return 0;
}
}
int majuscule(char ch){
if ((ch >= 'A') && (ch <= 'Z')){
return 1;
}else{
return 0;
}
}
void traiterChain ( char v[], char res[]){
int i;
i = 0;
int ind = 0;
while(v[i] != '\0'){
if(v[i+1]=='\0'){
afficheCar(v[i],'1');
insererCar(res,v[i],&ind,'1');
i +=1;
}else if(chiffre(v[i])){
afficheCar(v[i+1],((v[i])+1));
insererCar(res,v[i+1],&ind,((v[i])+1));
i += 2;
} else if(minuscule(v[i]) || majuscule(v[i])){
afficheCar(v[i],'1');
insererCar(res,v[i],&ind,'1');
i += 1;
}
}
res[ind] = '\0';
printf("---->%s",res);
}
/*void traiterChaine ( char v[]){
int i;
i = 0;
while(v[i] != '\0'){
if(v[i+1]=='\0'){
afficheCar(v[i],'1');
i +=1;
}else if(chiffre(v[i])){
afficheCar(v[i+1],((v[i])+1));
i += 2;
} else if(minuscule(v[i]) || majuscule(v[i])){
afficheCar(v[i],'1');
i += 1;
}
}
}*/
void EncodChain ( char v[], char encode[]){
int i;
i = 0;
char cCourant;
while(v[i] != '\0'){
if(v[i+1]=='\0'){
insererCar(encode,v[i+1],&i,1);
i +=1;
}
}
}
int main (){
char vect[N];
char decode[N];
setChaine(vect);
traiterChain(vect,decode);
return 1;
}
|