zoukankan      html  css  js  c++  java
  • CodeForces 131A cAPS lOCK

    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
    ",flg);
    22         if(flg!=1)
    23             printf("%s
    ",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("
    ");
    34     }
    35     return 0;
    36 }
    View Code
  • 相关阅读:
    生成器表达式
    列表生成式
    内置---排序(sorted)
    移动端摘要
    支付宝支付框js代码
    list-style-image不能设置位置
    vue-cli
    微信底部的菜单栏
    input在标签内设置禁止输入空格
    访问对象
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771494.html
Copyright © 2011-2022 走看看