Codeforces 131A CAPS LOCK (simulated water problem)

Source: Internet
Author: User
Tags lowercase time limit
A. Caps LOCK
Click to open the topic
Time limit per test 2 seconds memory limit per test megabytes input standard input output standard output

What does WE need CAPS LOCK for?

Caps Lock is a computer keyboard key. Pressing it sets an input mode in which typed letters is capital by default. If It is pressed by accident, it leads to accidents like the one we had in the first passage.

Let's consider that a word have been typed with the Caps lock key accidentally switched on, if:either it only contains UPP Ercase letters; or all letters except for the first one is uppercase.

In this case we should automatically, the case of all letters. For example, the case of the letters, which form words "HELLO", "HTTP", "Z" should be changed.

Write a program, that applies the rule mentioned above. If The rule cannot is applied, the program should leave the word unchanged. Input

The first line of 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. Sample Test (s) Input

CAPS
Output
Caps
Input
Lock
Output
Lock

╮(╯▽╰)╭ The topic was not understood at first, leading to WA several times. If it is all uppercase or if the first letter is lowercase and the other is uppercase, it is converted to the first letter uppercase, and the other lowercase, if not both of the cases are not processed.
╮(╯▽╰)╭ water problem is still wrong.

#include <iostream>
#include <string.h>
using namespace std;
int main ()
{
    char c[101];
    int i,k,ans,s;
    while (cin>>c)
    {
        K=strlen (c);
        ans=s=0;
        for (I=1; i<k; i++)
        {
            if (c[i]>= ' A ' &&c[i]<= ' Z ')
                s++;
            else if (c[i]>= ' a ' &&c[i]<= ' z ')
                ans++;
        }
        if ((ans==0&&s!=0) | | | K==1)
        {
            if (c[0]>= ' a ' &&c[0]<= ' z ')
                c[0]-=32;
            else if (c[0]>= ' A ' &&c[0]<= ' Z ')
                c[0]+=32;
            for (I=1; i<k; i++)
            {
                c[i]+=32;
            }
            cout<<c<<endl;
        }
        else
            cout<<c<<endl;
        memset (c, ' + ', sizeof (c));
    }
    return 0;
}


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.