C language: Two applets with time complexity of O (1)
Both examples use the same programming philosophy: For character operations, the char type can contain a maximum of 256 characters, but can meet the needs of upper and lower case, number, and other basic characters. Use the ascii code value of the character as the subscript of the array with the size of 256, and fill the content/condition to be searched in the array. In this way, you can view the content of the corresponding underlying object to perform corresponding operations. This is the programming idea that the time complexity is O (1). It is also based on a hash table. You can view the hash table on your own. The first example is as follows: when lowercase letter a is input, uppercase letter Z is output, and lowercase letter B is input, uppercase letter Y is output ,... when the lowercase letter z is input, the uppercase letter A is output.
1 # include <stdio. h> 2 # include <string. h> 3 4 void change (char arr [], int ch) {5 int I = 0; 6 int j = 90; 7 for (I = 97; I <123; I ++) {// Add Z-A 8 arr [I] = j -- one by one in the subscript of a-z in arr [256 --; 9} 10 printf ("% c \ n", arr [ch]); 11} 12 13 int main () {14 char arr [256] = {0 }; 15 int ch = 0; 16 ch = getchar (); 17 change (arr, ch); 18 return 0; 19}