Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:

permutace s písmeny

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: permutace s písmeny

Autor: tcesky

11:37:05 03.01.2011

[code]
[color=#0000ff]using[/color][color=#000000] System;
[/color][color=#0000ff]using[/color][color=#000000] System.Collections.Generic;
[/color][color=#0000ff]using[/color][color=#000000] System.Linq;
[/color][color=#0000ff]using[/color][color=#000000] System.Text;

[/color][color=#0000ff]namespace[/color][color=#000000] Permutation
{
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Dobrý den.[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Chtěl bych se zeptat jestli někdo nevíte jak udělat permutaci s řetězci nejlépe v C#.[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Jde o to že bych např. zadal slovo kocka a program by udělal permutaci písmen bez [/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] opakování obsažených v tomto slově[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Děkuji za pomoc[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000]
[/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Program[/color][color=#000000]
{
[/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Main([/color][color=#0000ff]string[/color][color=#000000][[/color][color=#000000]] args)
{
[/color][color=#0000ff]var[/color][color=#000000] arr = MakeArr([/color][color=#a31515]"kocka"[/color][color=#000000]);
[/color][color=#2b91af]Console[/color][color=#000000].WriteLine(arr);
[/color][color=#0000ff]for[/color][color=#000000] (; nextLexiPermutation(arr); ) [/color][color=#2b91af]Console[/color][color=#000000].WriteLine(arr);

}
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#2b91af]StringBuilder[/color][color=#000000] MakeArr([/color][color=#0000ff]string[/color][color=#000000] txt)
{
[/color][color=#0000ff]var[/color][color=#000000] lst = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#0000ff]char[/color][color=#000000]>();
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] txt) [/color][color=#0000ff]if[/color][color=#000000] (lst.IndexOf(c) < 0) lst.Add(c);
lst.Sort();
[/color][color=#0000ff]var[/color][color=#000000] sb = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StringBuilder[/color][color=#000000]();
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] lst) sb.Append(c);
[/color][color=#0000ff]return[/color][color=#000000] sb;
}

[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] http://www.siafoo.net/snippet/319[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]Adapted to a stringbuilder[/color][color=#808080][/color][color=#000000]
[/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]bool[/color][color=#000000] nextLexiPermutation([/color][color=#2b91af]StringBuilder[/color][color=#000000] s)
{
[/color][color=#0000ff]int[/color][color=#000000] i = -1, j = 0;

[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] x = s.Length - 2; x >= 0; x--)
[/color][color=#0000ff]if[/color][color=#000000] (s[[/color][color=#000000]x] < s[[/color][color=#000000]x + 1])
{
i = x;
[/color][color=#0000ff]break[/color][color=#000000];
}

[/color][color=#0000ff]if[/color][color=#000000] (-1 == i)
[/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000];

[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] x = s.Length - 1; x > i; x--)
[/color][color=#0000ff]if[/color][color=#000000] (s[[/color][color=#000000]x] > s[[/color][color=#000000]i])
{
j = x;
[/color][color=#0000ff]break[/color][color=#000000];
}

[/color][color=#008000]// Swapping elements pointed by i and j;[/color][color=#000000]
[/color][color=#0000ff]char[/color][color=#000000] temp = s[[/color][color=#000000]i];
s[[/color][color=#000000]i] = s[[/color][color=#000000]j];
s[[/color][color=#000000]j] = temp;

[/color][color=#008000]// Reversing elements after i[/color][color=#000000]
[/color][color=#0000ff]for[/color][color=#000000] (i++, j = s.Length - 1; i < j; i++, j--)
{
temp = s[[/color][color=#000000]i];
s[[/color][color=#000000]i] = s[[/color][color=#000000]j];
s[[/color][color=#000000]j] = temp;
}
[/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]true[/color][color=#000000];
}
}
}

[/color][/code]
[size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size]
Zdravím

[color=#808080]
Nejezte žlutý sníh
________________________________________________
Dobře se pobavíte a od srdce zasmějete na stránkách
http://www.4itdevelopers.net/faq_at_builder.aspx

[/color]

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Dobrý den.[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Chtěl bych se zeptat jestli někdo nevíte jak udělat permutaci s řetězci nejlépe v C#.[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Jde o to že bych např. zadal slovo kocka a program by udělal permutaci písmen bez [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] opakování obsažených v tomto slově[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Děkuji za pomoc[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Program[/color][color=#000000] { [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Main([/color][color=#0000ff]string[/color][color=#000000][[/color][color=#000000]] args) { [/color][color=#0000ff]var[/color][color=#000000] arr = MakeArr([/color][color=#a31515]"kocka"[/color][color=#000000]); [/color][color=#2b91af]Console[/color][color=#000000].WriteLine(arr); [/color][color=#0000ff]for[/color][color=#000000] (; nextLexiPermutation(arr); ) [/color][color=#2b91af]Console[/color][color=#000000].WriteLine(arr); } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#2b91af]StringBuilder[/color][color=#000000] MakeArr([/color][color=#0000ff]string[/color][color=#000000] txt) { [/color][color=#0000ff]var[/color][color=#000000] lst = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#0000ff]char[/color][color=#000000]>(); [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] txt) [/color][color=#0000ff]if[/color][color=#000000] (lst.IndexOf(c) < 0) lst.Add(c); lst.Sort(); [/color][color=#0000ff]var[/color][color=#000000] sb = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StringBuilder[/color][color=#000000](); [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] lst) sb.Append(c); [/color][color=#0000ff]return[/color][color=#000000] sb; } [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] http://www.siafoo.net/snippet/319[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]Adapted to a stringbuilder[/color][color=#808080][/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]bool[/color][color=#000000] nextLexiPermutation([/color][color=#2b91af]StringBuilder[/color][color=#000000] s) { [/color][color=#0000ff]int[/color][color=#000000] i = -1, j = 0; [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] x = s.Length - 2; x >= 0; x--) [/color][color=#0000ff]if[/color][color=#000000] (s[[/color][color=#000000]x] < s[[/color][color=#000000]x + 1]) { i = x; [/color][color=#0000ff]break[/color][color=#000000]; } [/color][color=#0000ff]if[/color][color=#000000] (-1 == i) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] x = s.Length - 1; x > i; x--) [/color][color=#0000ff]if[/color][color=#000000] (s[[/color][color=#000000]x] > s[[/color][color=#000000]i]) { j = x; [/color][color=#0000ff]break[/color][color=#000000]; } [/color][color=#008000]// Swapping elements pointed by i and j;[/color][color=#000000] [/color][color=#0000ff]char[/color][color=#000000] temp = s[[/color][color=#000000]i]; s[[/color][color=#000000]i] = s[[/color][color=#000000]j]; s[[/color][color=#000000]j] = temp; [/color][color=#008000]// Reversing elements after i[/color][color=#000000] [/color][color=#0000ff]for[/color][color=#000000] (i++, j = s.Length - 1; i < j; i++, j--) { temp = s[[/color][color=#000000]i]; s[[/color][color=#000000]i] = s[[/color][color=#000000]j]; s[[/color][color=#000000]j] = temp; } [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]true[/color][color=#000000]; } } } [/color][/code] [size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size] Zdravím TČ [color=#808080] Nejezte žlutý sníh ________________________________________________ Dobře se pobavíte a od srdce zasmějete na stránkách http://www.4itdevelopers.net/faq_at_builder.aspx [/color]

Citovat příspěvek

 

Re: permutace s písmeny

Autor: grafnev

10:51:52 03.01.2011

Aaaaa pozde koukam, ze uz dal :).

Citovat příspěvek

 

Re: permutace s písmeny

Autor: grafnev

10:50:28 03.01.2011

Program s osklivou slozitosti O(n^n) je snad takovyto:

v poli vstup je umisteno 'kocka'

[code]
funkce permutuj(indexOd,soucasnaPermutace)
if indexOd=delka(vstup) then vypis(vstup)
else do
pismeno=vstup(indexOd);
for pocitadlo=1 to delka(vstup)
if prazdna(soucasnaPermutace[pocitadlo]) then do;
soucasnaPermutace[pocitadlo]=pismeno;
permutuj(indexOd+1,soucasnaPermutace);
end;
end
end
[/code]

Prasoprogram rozepsano (a overeno) bez rekurze pomoci for cyklu (frontu se mi vyrabet nechtelo) s hnusnym continue.
[code]
data _null_;
array permut {5} $1. ('' '' '' '' '');
array retez {5} $1. ('k' 'o' 'c' 'k' 'a');

cntr=0;
do c1=1 to 5;
if permut[c1] eq '' then permut[c1]=retez[1]; else continue;
do c2=1 to 5;
if permut[c2] eq '' then permut[c2]=retez[2]; else continue;
do c3=1 to 5;
if permut[c3] eq '' then permut[c3]=retez[3]; else continue;
do c4=1 to 5;
if permut[c4] eq '' then permut[c4]=retez[4]; else continue;
do c5=1 to 5;
if permut[c5] eq '' then do;
permut[c5]=retez[5];
put permut[1] +(-1) permut[2] +(-1) permut[3] +(-1) permut[4] +(-1) permut[5];
cntr+1;
end; else continue;
permut[c5]='';
end;
permut[c4]='';
end;
permut[c3]='';
end;
permut[c2]='';
end;
permut[c1]='';
end;
put cntr;
run;
[/code]

Lepsi program da asi tcesky :)

Citovat příspěvek

 

Re: permutace s písmeny

Autor: tcesky

10:46:02 03.01.2011

[code]
[color=#0000ff]using[/color][color=#000000] System;
[/color][color=#0000ff]using[/color][color=#000000] System.Collections.Generic;
[/color][color=#0000ff]using[/color][color=#000000] System.Linq;
[/color][color=#0000ff]using[/color][color=#000000] System.Text;

[/color][color=#0000ff]namespace[/color][color=#000000] Permutation
{
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Dobrý den.[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Chtěl bych se zeptat jestli někdo nevíte jak udělat permutaci s řetězci nejlépe v C#.[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Jde o to že bych např. zadal slovo kocka a program by udělal permutaci písmen bez [/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] opakování obsažených v tomto slově[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Děkuji za pomoc[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000]
[/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Program[/color][color=#000000]
{
[/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Main([/color][color=#0000ff]string[/color][color=#000000][[/color][color=#000000]] args)
{
[/color][color=#0000ff]var[/color][color=#000000] arr = MakeArr([/color][color=#a31515]"kocka"[/color][color=#000000]);
[/color][color=#0000ff]for[/color][color=#000000] (; arr!=[/color][color=#0000ff]null[/color][color=#000000]; arr = nextLexiPermutation(arr))
PrtArr(arr);
}
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]char[/color][color=#000000][[/color][color=#000000]] MakeArr([/color][color=#0000ff]string[/color][color=#000000] txt)
{
[/color][color=#0000ff]var[/color][color=#000000] lst = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#0000ff]char[/color][color=#000000]>();
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] txt) [/color][color=#0000ff]if[/color][color=#000000] (lst.IndexOf(c) < 0) lst.Add(c);
lst.Sort();
[/color][color=#0000ff]return[/color][color=#000000] lst.ToArray();
}

[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] PrtArr([/color][color=#0000ff]char[/color][color=#000000][[/color][color=#000000]] txt) { [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] txt)[/color][color=#2b91af]Console[/color][color=#000000].Write([/color][color=#a31515]"{0} "[/color][color=#000000], c); [/color][color=#2b91af]Console[/color][color=#000000].WriteLine(); }
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] http://www.siafoo.net/snippet/319[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000]
[/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]char[/color][color=#000000][[/color][color=#000000]] nextLexiPermutation([/color][color=#0000ff]char[/color][color=#000000][[/color][color=#000000]] s)
{
[/color][color=#0000ff]int[/color][color=#000000] i = -1, j = 0;

[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] x = s.Length - 2; x >= 0; x--)
[/color][color=#0000ff]if[/color][color=#000000] (s[[/color][color=#000000]x] < s[[/color][color=#000000]x + 1])
{
i = x;
[/color][color=#0000ff]break[/color][color=#000000];
}

[/color][color=#0000ff]if[/color][color=#000000] (-1 == i)
[/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]null[/color][color=#000000];

[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] x = s.Length - 1; x > i; x--)
[/color][color=#0000ff]if[/color][color=#000000] (s[[/color][color=#000000]x] > s[[/color][color=#000000]i])
{
j = x;
[/color][color=#0000ff]break[/color][color=#000000];
}

[/color][color=#008000]// Swapping elements pointed by i and j;[/color][color=#000000]
[/color][color=#0000ff]char[/color][color=#000000] temp = s[[/color][color=#000000]i];
s[[/color][color=#000000]i] = s[[/color][color=#000000]j];
s[[/color][color=#000000]j] = temp;

[/color][color=#008000]// Reversing elements after i[/color][color=#000000]
[/color][color=#2b91af]Array[/color][color=#000000].Reverse(s, i + 1, s.Length - (i + 1));
[/color][color=#0000ff]return[/color][color=#000000] s;
}
}
}

[/color][/code]
[size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size]
Zdravím

[color=#808080]
Nejezte žlutý sníh
________________________________________________
Dobře se pobavíte a od srdce zasmějete na stránkách
http://www.4itdevelopers.net/faq_at_builder.aspx

[/color]
[code]
a c k o
a c o k
a k c o
a k o c
a o c k
a o k c
c a k o
c a o k
c k a o
c k o a
c o a k
c o k a
k a c o
k a o c
k c a o
k c o a
k o a c
k o c a
o a c k
o a k c
o c a k
o c k a
o k a c
o k c a
Press any key to continue . . .
[/code]

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Dobrý den.[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Chtěl bych se zeptat jestli někdo nevíte jak udělat permutaci s řetězci nejlépe v C#.[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Jde o to že bych např. zadal slovo kocka a program by udělal permutaci písmen bez [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] opakování obsažených v tomto slově[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Děkuji za pomoc[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Program[/color][color=#000000] { [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Main([/color][color=#0000ff]string[/color][color=#000000][[/color][color=#000000]] args) { [/color][color=#0000ff]var[/color][color=#000000] arr = MakeArr([/color][color=#a31515]"kocka"[/color][color=#000000]); [/color][color=#0000ff]for[/color][color=#000000] (; arr!=[/color][color=#0000ff]null[/color][color=#000000]; arr = nextLexiPermutation(arr)) PrtArr(arr); } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]char[/color][color=#000000][[/color][color=#000000]] MakeArr([/color][color=#0000ff]string[/color][color=#000000] txt) { [/color][color=#0000ff]var[/color][color=#000000] lst = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#0000ff]char[/color][color=#000000]>(); [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] txt) [/color][color=#0000ff]if[/color][color=#000000] (lst.IndexOf(c) < 0) lst.Add(c); lst.Sort(); [/color][color=#0000ff]return[/color][color=#000000] lst.ToArray(); } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] PrtArr([/color][color=#0000ff]char[/color][color=#000000][[/color][color=#000000]] txt) { [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] txt)[/color][color=#2b91af]Console[/color][color=#000000].Write([/color][color=#a31515]"{0} "[/color][color=#000000], c); [/color][color=#2b91af]Console[/color][color=#000000].WriteLine(); } [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] http://www.siafoo.net/snippet/319[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]char[/color][color=#000000][[/color][color=#000000]] nextLexiPermutation([/color][color=#0000ff]char[/color][color=#000000][[/color][color=#000000]] s) { [/color][color=#0000ff]int[/color][color=#000000] i = -1, j = 0; [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] x = s.Length - 2; x >= 0; x--) [/color][color=#0000ff]if[/color][color=#000000] (s[[/color][color=#000000]x] < s[[/color][color=#000000]x + 1]) { i = x; [/color][color=#0000ff]break[/color][color=#000000]; } [/color][color=#0000ff]if[/color][color=#000000] (-1 == i) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]null[/color][color=#000000]; [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] x = s.Length - 1; x > i; x--) [/color][color=#0000ff]if[/color][color=#000000] (s[[/color][color=#000000]x] > s[[/color][color=#000000]i]) { j = x; [/color][color=#0000ff]break[/color][color=#000000]; } [/color][color=#008000]// Swapping elements pointed by i and j;[/color][color=#000000] [/color][color=#0000ff]char[/color][color=#000000] temp = s[[/color][color=#000000]i]; s[[/color][color=#000000]i] = s[[/color][color=#000000]j]; s[[/color][color=#000000]j] = temp; [/color][color=#008000]// Reversing elements after i[/color][color=#000000] [/color][color=#2b91af]Array[/color][color=#000000].Reverse(s, i + 1, s.Length - (i + 1)); [/color][color=#0000ff]return[/color][color=#000000] s; } } } [/color][/code] [size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size] Zdravím TČ [color=#808080] Nejezte žlutý sníh ________________________________________________ Dobře se pobavíte a od srdce zasmějete na stránkách http://www.4itdevelopers.net/faq_at_builder.aspx [/color] [code] a c k o a c o k a k c o a k o c a o c k a o k c c a k o c a o k c k a o c k o a c o a k c o k a k a c o k a o c k c a o k c o a k o a c k o c a o a c k o a k c o c a k o c k a o k a c o k c a Press any key to continue . . . [/code]

Citovat příspěvek

 

permutace s písmeny

Autor: Tomcosinevirady

17:54:45 02.01.2011

Dobrý den.
Chtěl bych se zeptat jestli někdo nevíte jak udělat permutaci s řetězci nejlépe v C#.
Jde o to že bych např. zadal slovo kocka a program by udělal permutaci písmen bez opakování obsažených v tomto slově

Děkuji za pomoc

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: