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] = '\0';
57         printf("%s\n", result);       
58     } 
59     return 0;
60 }

 

 

转载于:https://www.cnblogs.com/yeshadow937/p/3927404.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值