Codeforces 131-A problem solution

A. cAPS lOCK
time limit per test 0.5 second
memory limit per test 256 megabytes
input standard input
output standard output

wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are 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 has been typed with the Caps lock key accidentally switched on, if:
·         either it only contains uppercase letters;
·         or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be 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 100 characters, inclusive.
Output
Print the result of the given word's processing.

Examples
input
cAPS
output
Caps

input
Lock
output
Lock


Solution:

  • [tab]
    • C++
      • #include <bits/stdc++.h>
        using namespace std;
        
        int main()
        {
            int i,l=0;
            char s[100];
            cin>>s;
            for(i=1; i<strlen(s); i++)
            {
                if(s[i]>=65&&s[i]<=90)
                {
                    l++;
                }
            }
            if(l==strlen(s)-1)
            {
                for(i=0; i<strlen(s); i++)
                {
                    if(s[i]>=65&&s[i]<=90)
                    s[i]=97+s[i]-65;
                    else if(s[i]>=97&&s[i]<=122)
                    s[i]=65+s[i]-97;
                }
            }
            cout<<s;
            return 0;
        }
        
3/Technology/post-list
Name

Codeforces,53,Problem Solve,90,Programming Tricks,1,URI,37,
ltr
item
DorHubs: Codeforces 131-A problem solution
Codeforces 131-A problem solution
DorHubs
https://dorhubs.blogspot.com/2019/07/codeforces-131-problem-solution.html
https://dorhubs.blogspot.com/
https://dorhubs.blogspot.com/
https://dorhubs.blogspot.com/2019/07/codeforces-131-problem-solution.html
true
9087637800571592252
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy