码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 131A cAPS lOCK

时间:2015-08-30 20:52:48      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

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

 

CodeForces 131A cAPS lOCK

标签:

原文地址:http://www.cnblogs.com/cyd308/p/4771494.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!