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
  • 相关阅读:
    jUnit4初探(1)
    关于冒泡排序与选择排序
    我对直接插入排序的一点理解
    Java中的Scanner类
    String数组与字符串类
    Redis知识点详解
    MySQL操作命令详解
    java中常见面试题整理
    Redis的安装部署
    zookeeper的伪集群部署步骤
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771494.html
Copyright © 2011-2022 走看看