zoukankan      html  css  js  c++  java
  • HDU 2573 Typing

    Typing

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 869    Accepted Submission(s): 544


    Problem Description
    A boy named Pirates who wants to develop typing software finds that it’s hard to judge whether a letter is lowercase or uppercase. He searches lots of information about it, and find out the solution, but he doesn’t know how to realize it. Can you help him?
      
    The Solution:
    1: If the caps lock is on, and the letter is typed with shift key down, the letter is lowercase, otherwise it’s uppercase.
    2: If the caps lock is off, and the letter is typed with shift key down, the letter is uppercase, otherwise it’s lowercases.
     
    Input
      The first line is an integer t, which is the number of test case in the input data file. Each test case begins with an integer n (0<n<=100), which means there follow n lines. For each line, if there is only a letter, it means the key is typed, and if there begins with a string “Shift”, then will follows one letter, it means the letter is typed with shift key, and if there begins with a string “Caps”, it means the caps lock key is typed and changes the mood of caps lock. The entire letter is lowercase. At the beginning of each test case, you can assume that the caps lock is off.
     
    Output
    Please output a string which the user typed.
     
    Sample Input
    2
    5
    Caps
    a
    c
    Shift i
    Shift t
    6
    Caps
    a
    c
    Caps
    i
    t
     
    Sample Output
    ACit
    ACit
     
    题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2573
     1 #include <stdio.h>
     2 #include <string.h>
     3 int main()
     4 {
     5     int cas, n, len;
     6     char str[100], result[100], Caps, c;  
     7     scanf("%d", &cas);
     8     getchar();
     9     while ( cas-- )
    10     {
    11         scanf("%d", &n);
    12         getchar();
    13         Caps = '0'; /* 开始时Caps为关, 用'0'表示关, '1'表示开 */
    14         len = 0;
    15         while ( n-- )
    16         {
    17             scanf("%s", str);
    18             getchar();
    19             if (strcmp(str, "Caps") == 0) /* 检验Caps键的状态, 并转换 */
    20             {
    21                 if (Caps == '0')
    22                 {
    23                     Caps = '1';
    24                 }
    25                 else
    26                 {
    27                     Caps = '0';
    28                 }
    29             }
    30             else if (strcmp(str, "Shift") == 0) /* 此时按下了Shift键 */
    31             {
    32                 scanf("%c", &c);
    33                 getchar();
    34                 if (Caps == '1') /* 此时大写已锁定 */
    35                 {
    36                     result[len++] = c;
    37                 }
    38                 else
    39                 {
    40                     c = (c - 32);
    41                     result[len++] = c;
    42                 }
    43             }
    44             else /* 输入是单个字符时 */
    45             {
    46                 if (Caps == '1')
    47                 {
    48                     result[len++] = (str[0] - 32);
    49                 }
    50                 else
    51                 {
    52                     result[len++] = str[0];
    53                 }
    54             }
    55         }
    56         result[len] = '';
    57         printf("%s
    ", result);       
    58     } 
    59     return 0;
    60 }
     
  • 相关阅读:
    win7下安装Linux实现双系统全攻略
    Dreamweaver_CS6安装与破解,手把手教程
    windows Server 2008各版本有何区别?
    如何查看路由器中的pppoe拨号密码?
    xp远程桌面连接最大用户数怎么设置?
    网站的盈利模式
    linux 下安装mysql-5.7.16
    GNS3连接虚拟机
    cain使用教程
    数据中心网络架构的问题与演进 — CLOS 网络与 Fat-Tree、Spine-Leaf 架构
  • 原文地址:https://www.cnblogs.com/yeshadow937/p/3927404.html
Copyright © 2011-2022 走看看