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;
}