This is a bit difficult. The second requirement is not met. For the BBC. There will be duplicates.
BBC
BCB
BCB
CBB
Although filtering is not repeated, it is certainly not the original intention of the question. You have time to redo it.
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. IO;
Namespace Acm2
{
Class Program
{
Static Void Main ( String [] ARGs)
{
Filestream FS = New Filestream (ARGs [ 0 ], Filemode. Open, fileaccess. Read );
Streamreader SR = New Streamreader (FS );
String S = Sr. Readline ();
Int N = Int . Parse (s );
For ( Int I = 0 ; I < N; I ++ )
{
S = Sr. Readline ();
Console. writeline ( " Case " + (I + 1 ));
Deal (s );
}
}
Static String Sort ( String Str)
{
Char [] CS = Str. tochararray (); Char Temp;
For ( Int I = 0 ; I < CS. length; I ++ )
For ( Int J = I; j < CS. length; j ++ )
If (CS [I] > CS [J])
{< br> temp = CS [I];
CS [I] = CS [J];
CS [J] = temp;
}
Return New String (CS );
}
Static Void Deal ( String Str)
{
String Mstr = Sort (STR );
String [] STRs = Dealf (mstr );
For ( Int I = 0 ; I < STRs. length; I ++ )
Console. writeline (STRs [I]);
}
Static String [] Dealf ( String Str)
{
If (Str. Length = 1 )
Return New String [] {STR} ;
If (Str. Length = 2 )
{
String [] Torets = New String [ 2 ];
Torets [ 0 ] = STR;
Torets [ 1 ] = Str. substring ( 1 ) + Str. substring ( 0 , 1 );
Return Torets;
}
String C = Str. substring ( 0 , 1 );
String [] RET = Dealf (Str. substring ( 1 ));
String [] Toret = New String [Ret. Length * 2 ];
For ( Int I = 0 ; I < Toret. length; I ++ )
{
If (I < Toret. Length / 2 )
Toret [I] = C + RET [I];
Else
Toret [I] = RET [I - Ret. Length] + C;
}
Return Toret;
}
}
}