Evaluate the combination of uppercase and lowercase letters of a script, for example, script, script...

Source: Internet
Author: User

Clszh. Java

 

/*
The form of different case combinations of scripts is as follows: -- Author: Wen min, CTO of Chenzhou
Script, script,
Script, script,
Script, script,
Script, script,
Script, script,
Script, script,
Script
*/
Import java. util. arraylist;
Import java. util. iterator;

 

Public class clszh {
// Get different combinations in an array-from min to Max
// Although this example is not used, it can still be used in other applications
Public arraylist getzhfromary (object [] ary, int Max, int min) throws exception {
Int Len = ary. length;
If (max> Len | min> = max ){
Throw new exception ("the maximum number of combinations must not exceed the length of the array and must be greater than the minimum number of combinations ");
}

Arraylist lst = new arraylist ();
Int size;
Object [] temp;
For (INT I = min; I <= max; I ++ ){
Int [] [] Results = getzh (Len, I );
Size = results. length;
For (Int J = 0; j <size; j ++ ){
Temp = new object [I];
For (int K = 0; k <I; k ++ ){
Temp [k] = ary [Results [J] [k];
}
Lst. Add (temp );
}
}

Return lst;
}
 
// Len: number of values in the sequence. The sequence starts from 0. For example, if Len is 8, it indicates that the sequence starts from 0 ~ 7. Obtain the eight numbers.
// Qty: the number of digits in a combination, for example, 4, which indicates that different 4-digit combinations are obtained from the preceding array.
// Return: all combinations
Public int [] [] getzh (INT Len, int qty) throws exception {
Int [] [] Results = NULL;

If (LEN <qty ){
Throw new exception ("cannot take" + qty + "number combination from" + Len +! ");
}

If (qty = 1 ){
Results = new int [Len] [1];
For (INT I = 0; I <Len; I ++ ){
Results [I] [0] = I;
}
Return results;
}
Else if (LEN = qty ){
Results = new int [1] [qty];
For (INT I = 0; I <qty; I ++ ){
Results [0] [I] = I;
}
Return results;
}

// Define the one-dimensional length of the returned array
Int Top = 1;
For (INT I = Len; I> = len-qty + 1; I --){
Top * = I;
}
Int Bottom = 1;
For (INT I = qty; I> = 2; I --){
Bottom * = I;
}
Int size = top/bottom;
Results = new int [size] [qty];

// Pre-initialization qty-1 fixed number Array
Int [] ary1 = new int [qty-1];
For (INT I = 0; I <qty-1; I ++ ){
Ary1 [I] = I;
}

// Call opezh to fill the returned array
Opezh (ary1, results, Len, qty, 0, size );

Return results;
}
 
// According to the previous qty-1 fixed number array, loop to determine the last number, add these arrays to the large array
// Then change the number of a fixed number array and its subsequent number
// Continuous recursive call
Private void opezh (INT [] ary1, int [] [] Results, int Len, int qty, int IX, int size ){
// System. Out. println ("opezh --" + ix );
For (INT I = ary1 [qty-2] + 1; I <Len; I ++ ){
Int [] ary2 = new int [qty];
For (Int J = 0; j <qty-1; j ++) {// The number of front qty-1 is the same as that of the fixed number Array
Ary2 [J] = ary1 [J];
}
Ary2 [qty-1] = I; // The qty number is the number of cycles
Results [ix] = ary2;
IX ++;
}

// Determine from the back to the front which number to increase. After this number increases, the subsequent number will change.
For (INT I = qty-2; I> = 0; I --){
If (ary1 [I] <I + len-qty ){
Ary1 [I] ++;
For (Int J = I + 1; j <qty-1; j ++ ){
Ary1 [J] = ary1 [J-1] + 1;
}
Break;
}
}

// If all the changes have not been completed, continue to call itself recursively
If (ary1 [0] <0 + len-qty ){
Opezh (ary1, results, Len, qty, IX, size );
}
Else {// last change
Int [] ary2 = new int [qty];
For (INT I = 0; I <qty; I ++ ){
Ary2 [I] = I + len-qty;
}
Results [ix] = ary2;
}
 
}
 
Public static void main (string [] ARGs) throws exception {
Clszh ZH = new clszh ();

/*
// Test the combination-the rule of the combination can be seen from the following:
Int Len = 7;
Int qty = 1;
Int [] [] Results = Zh. getzh (Len, qty );
Int size = results. length;
For (INT I = 0; I <size; I ++ ){
For (Int J = 0; j <qty; j ++ ){
System. Out. Print (results [I] [J] + "/t ");
}
System. Out. println ();
}
*/

/*
// Test N ~ in an array ~ M different combinations
String [] Ss = {"A", "B", "C", "1", "2", "3 "};
Arraylist L = Zh. getzhfromary (SS, 5, 3); // a combination of 3 to 5
Iterator it = L. iterator ();
Object [] temp;
Int Len;
While (it. hasnext ()){
Temp = (object []) it. Next ();
Len = temp. length;
For (INT I = 0; I <Len; I ++ ){
System. Out. Print (temp [I]);
}
System. Out. println ();
}
*/

// According to the initial form of the string, 1 ~ Converts n characters to uppercase and adds the converted strings to the set.
String STR = "script ";
Int Len = Str. Length ();
Int size;
String temp;
Char [] chars = NULL;
Arraylist lst = new arraylist ();
Lst. Add (STR );
For (INT I = 1; I <= Len; I ++) {// The number of characters to be converted ranges from 1 to Len.
Int [] [] Results = Zh. getzh (Len, I); // obtain the subscript of all characters to be converted
Size = results. length;
For (Int J = 0; j <size; j ++ ){
Chars = Str. tochararray ();
For (int K = 0; k <I; k ++ ){
Chars [Results [J] [k] = (char) (chars [Results [J] [k]-32 );
}
Temp = new string (chars );
Lst. Add (temp );
}
}

System. Out. println (LST );
}
}

 

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.