A c # basic question. How long can you develop it?

Source: Internet
Author: User
This is a Java interview question, which is implemented in C. The specific question is as follows: given 6 numbers 1, 2, 2, 3, 4, 5, we need to find the six digits that all the six digits are combined into and meet
(1) 3 and 5 cannot be connected
(2) 4 cannot be in the third place
Give your Algorithm .

I did this.

Using System;
Using System. IO;
Using System. collections;
Using System. Collections. Generic;
Using System. text;

Namespace Leleapplication1
{
Class Program
{
Static   Void Main ( String [] ARGs)
{
// Char [] A = {'1', '2', '2', '3', '4', '5 '};
Char [] = { ' 1 ' , ' 2 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' } ;
Int I =   0 ;
Ilist result = Program. pailie ();
Ilist result2 =   New Arraylist ();

// Streamwriter Tw = new streamwriter ("C :\\ out.txt ");
// Console. setout (TW );

Foreach ( String Str In Result)
{
If (Str. Contains ( " 35 " ) | Str. Contains ( " 53 " ) | Str. indexof ( ' 4 ' ) =   3 )
{
I++;
}
Else
Result2.add (STR );
// Console. writeline (STR );
}
Foreach ( String Str2 In Result2)
{
Console. writeline (str2 );
}

// Tw. writeline ("I =" + I );
// Tw. writeline ("Result: --" + result. Count );
// Tw. writeline ("Total: --" + result2.count );
Console. writeline ( " I = "   + I );
Console. writeline ( " Result :-- "   + Result. Count );
Console. writeline ( " Total :-- " + Result2.count );
}

Public   Static Ilist pailie ( Char [])
{
Ilist resultstr = New Arraylist ();
// Resultstr. Add (new string ());
Int N = A. length;
If (N =   2 )
{
Resultstr. Add ( New   String ());
Char Temp = A [ 0 ];
A [ 0 ] = A [ 1 ];
A [ 1 ] = Temp;
Resultstr. Add ( New   String ());
}

If (N >   2 )
{
For ( Int I =   0 ; I < N; I ++ )
{
String B =   New   String ();
B = B. Remove (I, 1 );
Char [] C = B. tochararray ();
Ilist tempstr = Pailie (C );
Foreach ( String S In Tempstr)
{
StringXx=A [I]. tostring ()+S;
Resultstr. Add (XX );
}
}
}

Return Resultstr;
}
}
}

Remove some comments and export them to files.

You can give better algorithms and give more valuable comments!

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.