Codeforces the road of brush problem--131a CAPS LOCK

Source: Internet
Author: User
Tags lowercase
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); }
	}
}

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.