Bonjour.
Je cherche à fabriquer un générateur de combinaisons Guématrique.
je suis arrivé grâce et avec l'aide de nombreuse personnes personnes présente sur ce Forum à un modèle physique prêt a être selon la courbe Merise "automatisé".
Cependant plusieurs points restent à valider
1:
J'utilise la Classe string, avec les objet string::iterator .
Les char*, associés à des boucles for classiques seraient ils plus rapide.
2:
j'ai besoin de connaitre chaque caractères, pour affecter la valeur d'une variable selon le schéma.
Si le caractere est un a, la variable vaut 1.
Si le caractère est un b, la variable vaut 2.
Si le caractère est un c, la variable vaut 3.
....
...
Si le caractère est un z la variable vaut 26.
Pour ce faire, et grâce à Steph_ng8
J'utilise cette "commande"
*it étant le caractère à tester.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 if ((*it0 >= 'a' /* 97 */) && (*it0 <= 'z' /* 122 */)) val = *it0 - 'a' +1 /* 96 */; else val = 0;
std::isalpha serait il plus rapide ?
Comment le mettre en place ?
Existe t'il un autre moyen plus rapide.
3:
La fonction reduit() calcule la réduction d'un nombre tel que:
183 = 1+8+3 = 12 =1+2 =3
Soitrenvoie 3
Code : Sélectionner tout - Visualiser dans une fenêtre à part reduit(183)
La fonction :Cette fonction appelle une autre fonction, pour transformer en string l'entier passé en paramètre.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 int reduit (int a) { string chain = to_string(a); int t; t = chain.length(); int ent; int res; res = 0; char car; int i; for(i=0; i<t; i++) { car = chain[i] ; ent = car - '0'; res = res + ent; } if(res<10) return res; else return reduit(res); }
Existe t-il un moyen plus rapide d'obtenir la réduction d'un entier selon le principe énoncé ci dessus.
Le code dans sa totalité :Ce code écrit les mots dans un fichier texte.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259 #include <cstdlib> #include <fstream> #include "stdlib.h" #include <stdio.h> #include <sstream> #include <cctype> // pour tolower et toupper #include <string> #include <iostream> #include <algorithm> // pour transform #include <cstring> ////////////////////////////////////////////////////// struct my_tolower { char operator()(char c) const { return std::tolower(static_cast<unsigned char>(c)); } }; using namespace std; template<typename T> string to_string( const T & Value ); int reduit (int a); int main(int argc, char *argv[]) { using namespace std; ofstream fichier("TextFile1.txt", ios::out | ios::trunc); int val,val1,val2,val3,val4,val5,val6,val7,val8,val9,val10,val11,valt,valr ; int taille; string str; string chaine; long z; z = 0; valt = 0; cout<<"Entrez caracteres (11 lettres en sortie)"<<endl; cin>> str; taille = str.length(); transform(str.begin(), str.end(), str.begin(), my_tolower()); for(int i1=0; i1 < taille; i1++) { for(int i2 = i1; i2 < taille; i2++) { if (stricmp(&str[i1], &str[i2]) > 0) { char tmp = str[i1]; str[i1] = str[i2]; str[i2] = tmp; } } } string::iterator it0; string::iterator it1; string::iterator it2; string::iterator it3; string::iterator it4; string::iterator it5; string::iterator it6; string::iterator it7; string::iterator it8; string::iterator it9; string::iterator it10; for ( it10=str.begin() ; it10 < str.end(); it10++ ) { for ( it9=str.begin() ; it9 < str.end(); it9++ ) { for ( it8=str.begin() ; it8 < str.end(); it8++ ) { for ( it7=str.begin() ; it7 < str.end(); it7++ ) { for ( it6=str.begin() ; it6 < str.end(); it6++ ) { for ( it5=str.begin() ; it5 < str.end(); it5++ ) { for ( it4=str.begin() ; it4 < str.end(); it4++ ) { for ( it3=str.begin() ; it3 < str.end(); it3++ ) { for ( it2=str.begin() ; it2 < str.end(); it2++ ) { for ( it1=str.begin() ; it1 < str.end(); it1++ ) { for ( it0=str.begin() ; it0 < str.end(); it0++ ) { if ((*it10 >= 'a' ) && (*it10 <= 'z' )) val10 = *it10 - 'a' +1 ; else val10 = 0; if ((*it9 >= 'a' ) && (*it9 <= 'z' )) val9 = *it9 - 'a' +1 ; else val9 = 0; if ((*it8 >= 'a' ) && (*it8 <= 'z' )) val8 = *it8 - 'a' +1 ; else val8 = 0; if ((*it7 >= 'a' ) && (*it7 <= 'z' )) val7 = *it7 - 'a' +1 ; else val7 = 0; if ((*it6 >= 'a' ) && (*it6 <= 'z' )) val6 = *it6 - 'a' +1 ; else val6 = 0; if ((*it5 >= 'a' ) && (*it5 <= 'z' )) val5 = *it5 - 'a' +1 ; else val5 = 0; if ((*it4 >= 'a' ) && (*it4 <= 'z' )) val4 = *it4 - 'a' +1 ; else val4 = 0; if ((*it3 >= 'a' ) && (*it3 <= 'z' )) val3 = *it3 - 'a' +1 ; else val3 = 0; if ((*it2 >= 'a' ) && (*it2 <= 'z' )) val2 = *it2 - 'a' +1 ; else val2 = 0; if ((*it1 >= 'a' ) && (*it1 <= 'z' )) val1 = *it1 - 'a' +1 ; else val1 = 0; if ((*it0 >= 'a' ) && (*it0 <= 'z' )) val = *it0 - 'a' +1 ; else val = 0; z = z +1; valt = valt += val += val1 += val2 += val3 += val4 += val5 += val6 += val7 += val8 += val9 += val10 ; valr = reduit(valt); cout<<*it10<<*it9<<*it8<<*it7<<*it6<<*it5<<*it4<<*it3<<*it2<<*it1<<*it0<<" "<<"Valeur"<<" "<<valt<<" "<<"Valeur réduite"<<" "<<valr<<" ""Nombre de combinaisons"<<" "<<z<<endl; fichier<<*it10<<*it9<<*it8<<*it7<<*it6<<*it5<<*it4<<*it3<<*it2<<*it1<<*it0<<" "<<"Valeur"<<" "<<valt<<" "<<"Valeur réduite"<<" "<<valr<<" ""Nombre de combinaisons"<<" "<<z<<endl; valt = 0; } } } } } } } } } } } system("PAUSE"); return EXIT_SUCCESS; } ///////////////////////////////////////// int reduit (int a) { string chain = to_string(a); int t; t = chain.length(); int ent; int res; res = 0; char car; int i; for(i=0; i<t; i++) { car = chain[i] ; ent = car - '0'; res = res + ent; } if(res<10) return res; else return reduit(res); } template<typename T> string to_string( const T & Value ) { // utiliser un flux de sortie pour créer la chaîne std::ostringstream oss; // écrire la valeur dans le flux oss << Value; // renvoyer une string return oss.str(); }
Pour contrôler la valeur des mot, il suffit de copier le mot, et de le coller dans ce logiciel :
http://mapage.noos.fr/pic-vert/numerus.html
Ce logiciel fait le travail inverse.
Merci
Partager