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 }
     
  • 相关阅读:
    【转】正确设置php-fpm子进程用户,提高网站安全性防挂马
    Linux修改SSH端口,并禁止Root远程登陆
    [转]PHP5 session 详解
    【转】PHP调试开发工具你认识多少?
    [转]浅谈php web安全
    【笔记】InnoDB内存分配
    【转】推荐介绍几款小巧的Web Server程序
    【转】定时自动启动任务crontab命令用法
    Tornado笔记
    Python笔记:open函数和with临时运行环境(文件操作)
  • 原文地址:https://www.cnblogs.com/yeshadow937/p/3927404.html
Copyright © 2011-2022 走看看