1 |
Moin moin, |
2 |
|
3 |
>> maximale bzw. durchschnittliche Verschiebedistanz eines Buchstaben wär' |
4 |
>> vielleicht geeignet? |
5 |
nun gut, das kann es nicht, ... |
6 |
|
7 |
> Ja genau, so habe ich mir das in etwa vorgestellt. Könnte jemand das |
8 |
> noch kurz |
9 |
> in C++ schreiben? =) Es wäre ziemlich amüsant dass in kopete zu haben. Da |
10 |
... folgendes hab ich mal produziert: |
11 |
|
12 |
string MixWords::mix() |
13 |
{ |
14 |
srand((unsigned)time(0)); |
15 |
string message(*m_message); |
16 |
message.append(" "); |
17 |
while (message.length()>1) |
18 |
{ |
19 |
int space_pos = message.find(' ',0)+1; |
20 |
m_newmessage->append(mixWord(message.substr(0,space_pos))); |
21 |
message = message.erase(0,space_pos); |
22 |
} |
23 |
return *m_newmessage; |
24 |
}; |
25 |
|
26 |
string MixWords::mixWord(string old_word) |
27 |
{ |
28 |
if (old_word.length() < 4) |
29 |
return old_word; |
30 |
string new_word(""); |
31 |
new_word.append(old_word,0,1); |
32 |
old_word.erase(0,1); |
33 |
int last = old_word.length()-2; |
34 |
string last_char(""); |
35 |
last_char.append(old_word,last,2); |
36 |
old_word.erase(last,2); |
37 |
|
38 |
while (int range = old_word.length()) |
39 |
{ |
40 |
int rand_pos = rand() % range; |
41 |
new_word.append(old_word,rand_pos,1); |
42 |
old_word = old_word.erase(rand_pos,1); |
43 |
} |
44 |
new_word.append(last_char); |
45 |
return new_word; |
46 |
}; |
47 |
|
48 |
ist bei weitem nicht perfekt, aber vielleicht nen guter Anfang |
49 |
|
50 |
Gibt es auch komplett inklusive Testprogramm, Text und Inline-doku hier: |
51 |
|
52 |
http://stud.fh-wedel.de/~tinf8315/mixwords.tar.gz |
53 |
|
54 |
Sorry fuer die etwas merkwuerdige URL, bin Momentan noch im Urlaub. |
55 |
|
56 |
Gruss, |
57 |
Karsten |
58 |
|
59 |
-- |
60 |
In a world without walls and fences, |
61 |
why do we need Windows and Gates? |
62 |
-- |
63 |
gentoo-user-de@g.o mailing list |