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 }
     
  • 相关阅读:
    对象的强、软、弱和虚引用
    spark运行模式之一:Spark的local模式安装部署
    Spark Tungsten in-heap / off-heap 内存管理机制--待整理
    sparkContext之一:sparkContext的初始化分析
    mysql分区表之四:分区表性能
    服务的升级和降级
    怎样编写高质量的 Java 代码
    Java之代理(jdk静态代理,jdk动态代理,cglib动态代理,aop,aspectj)
    Spark Streaming之六:Transformations 普通的转换操作
    Spark Streaming之五:Window窗体相关操作
  • 原文地址:https://www.cnblogs.com/yeshadow937/p/3927404.html
Copyright © 2011-2022 走看看