(C #) the second question of ACM

Source: Internet
Author: User
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;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.