Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Collections;
Namespace ConsoleApplication2
{
Class StringSuan
{
// Whether the string contains the character in question A in question B
Public static void Contains ()
{
String str1 = "ggwahrah ";
String str2 = "gwha ";
// Open an auxiliary array and clear it
Int [] hash = new int [100];
// Num indicates the number of elements in the secondary array.
Int num = 0;
// Scan short strings
For (int j = 0; j <str2.Length; j ++)
{
// Convert the character to the index in the corresponding secondary Array
Int index = str2 [j]-'A ';
// If the index element in the secondary array is 0, set 1 and num ++;
If (hash [index] = 0)
{
Hash [index] = 1;
Num ++;
}
}
// Scan long strings
For (int k = 0; k <str1.Length; k ++)
{
Int index = str1 [k]-'A ';
// If the index element in the secondary array is 1, num --; if it is 0, no processing is performed (no statement is written ).
If (hash [index] = 1)
{
Hash [index] = 0;
Num --;
If (num = 0) // m = 0, that is, exit the loop.
Break;
}
}
// If num is 0, the long string contains all characters in the short string.
If (num = 0)
Console. WriteLine ("TRUE ");
Else
Console. WriteLine ("FALSE ");
}
////////
// Left rotation of the string
Public static void Reverse (StringBuilder sb, int index, int n)
{
For (int I = 0; I <n/2; I ++)
{
Char temp = sb [index + I];
Sb [index + I] = sb [index + n-I-1];
Sb [index + n-I-1] = temp;
}
}
Public static void LeftRotate (StringBuilder sb, int index)
{
If (index> sb. Length)
{
Console. WriteLine ("please insert smaller number ");
Return;
}
Reverse (sb, 0, index );
Reverse (sb, index, sb. Length-index );
Reverse (sb, 0, sb. Length );
Console. WriteLine (sb );
}
/////////
// Obtain the maximum continuous number in the string. get the longest number from a string
Public static void LongNumber (string n)
{
Char [] str = n. ToCharArray ();
Int max = 0, j = 0;
Int start = 0;
Bool set = false;
Int length = str. Length;
Int output = 0;
For (int I = 0; I <length; I ++)
{
If (char. IsNumber (str [I])
{
If (set = false)
Start = I;
J ++;
Set = true;
}
Else
{
If (j> max)
{
Output = start;
Max = j;
}
Set = false;
J = 0;
}
}
If (j> max)
{
Output = start;
Max = j;
}
For (int I = 0; I <max; I ++)
Console. Write (str [output + I]);
}
// Character Inversion
Static string Reverse1 (string original)
{
Char [] arr = original. ToCharArray ();
Array. Reverse (arr );
Return new string (arr );
}
Static void ver (char [] str)
{
Char temp;
Int len;
Len = str. Length;
For (int I = 0; I <len/2; I ++)
{
Temp = str [I];
Str [I] = str [len-I-1];
Str [len-I-1] = temp;
}
Console. WriteLine (str );
}
// The first character in the string that appears only once, "abcdabc" output: d
Public static char? Print (string str)
{
If (str. Length = 0 | str = null)
Return null;
Bool [] marks = new bool [str. Length];
For (int I = 0; I <str. Length; I ++)
{
If (marks [I]! = True)
{
Marks [I] = true;
Int count = 0;
For (int j = I; j <str. Length; j ++)
{
If (str [j] = str [I])
{
Count ++;
Marks [j] = true;
}
}
If (count = 1)
{
Return str [I];
}
}
}
Return null;
}
}
}