A. CAPS LOCK time limit/test 0.5 second memory limit per test 256 megabytes input standard input output standard OUTPU T
WHAT do WE NEED CAPS LOCK for?
Caps Lock is a computer keyboard key. Pressing it sets an input mode into which typed letters are capital by default. If It is pressed by accident, it leads to accidents like the "one" and "we had in the" the "I Passage."
Let's consider that's a word has been typed with the Caps lock key accidentally in switched it only If:either Ercase letters; or all letters except for the one are uppercase.
In this case we should automatically change the case to all letters. For example, the case of the letters that form words "HELLO", "HTTP", "Z" should to be changed.
Write A program This applies the rule mentioned above. If The rule cannot is applied, the program should leave the word unchanged. Input
The ' the ' input data contains a word consisting of uppercase and lowercase Latin letters. The word ' s length is from 1 to characters, inclusive. Output
Print The result of the given word ' s processing. Examples input
CAPS
Output
Caps
Input
Lock
Output
Lock
The main idea: to consider only two cases (1) all uppercase letters (2) except the first character, others are uppercase letters. For the first case, change it to all lowercase output. For the second case, change it to only the first character capitalization, and all others to lowercase output. The idea of solving problems: the main effect of the topic has clearly indicated the two situations that need to be considered, is a water problem.
The following is a problem-solving code (Java implementation)
import Java.util.Scanner; public class Main {public static void main (string[] args) {//TODO auto-generated method stub Scanner Scanner = NE
W Scanner (system.in);
String str = scanner.nextline ();
char[] ch = str.tochararray ();
Boolean uppercase = FALSE;
Boolean flag = false;
if (ch[0] >= ' A ' && ch[0] <= ' z ') {flag = true;
for (int i = 1; i < ch.length;i++) {if (Ch[i] >= ' A ' && ch[i] <= ' Z ') {flag = true;
Continue
}else{flag = false;
Break
}}else{uppercase = true;
for (int i = 1;i < ch.length;i++) {if (Ch[i] >= ' A ' && ch[i] <= ' Z ') {uppercase = true;
Continue
}else{uppercase = false;
Break
}} if (flag) {System.out.println (str.substring (0, 1). toUpperCase () + str.substring (1). toLowerCase ());
}else if (uppercase) {System.out.println (Str.tolowercase ());
}else {System.out.println (str); }
}
}