CodeForces 131A cAPS lOCK

本文介绍了一个关于CAPSLOCK键误触导致输入错误的问题,并提供了一段C语言代码来自动修正这种错误。修正规则为:如果单词除了第一个字母外其余全部大写,则将所有字母转换为小写;若首字母大写则只转换首字母。
cAPS lOCK
Time Limit:500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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.

Sample Input

Input
cAPS
Output
Caps
Input
Lock
Output
Lock
 1 #include <stdio.h>
 2 #include <string.h>
 3 int main()
 4 {
 5     char a[105];
 6     int i,j,k;
 7     while(scanf("%s",a)!=EOF)
 8     {
 9         int flg=1;
10         int l=strlen(a);
11         for(i=1;i<l;i++)
12         {
13             if('A'<=a[i] && a[i]<='Z')
14                 k=1;
15             else
16             {
17                 flg=0;
18                 break;
19             }
20         }
21         //printf("%d\n",flg);
22         if(flg!=1)
23             printf("%s\n",a);
24         else
25         {
26             if('A'<=a[0] && a[0]<='Z')
27                 printf("%c",a[0]+32);
28             else
29                 printf("%c",a[0]-32);
30             for(i=1;i<l;i++)
31                 printf("%c",a[i]+32);
32         }
33         printf("\n");
34     }
35     return 0;
36 }
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4771494.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值