簡單題
/*
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
*/
#include <stdio.h>
#include <string.h>
int main()
{
int cas, n, len;
char str[100], result[100], Caps, c;
scanf("%d", &cas);
getchar();
while ( cas-- )
{
scanf("%d", &n);
getchar();
Caps = '0'; /* 开始时Caps为关, 用'0'表示关, '1'表示开 */
len = 0;
while ( n-- )
{
scanf("%s", str);
getchar();
if (strcmp(str, "Caps") == 0) /* 检验Caps键的状态, 并转换 */
{
if (Caps == '0')
{
Caps = '1';
}
else
{
Caps = '0';
}
}
else if (strcmp(str, "Shift") == 0) /* 此时按下了Shift键 */
{
scanf("%c", &c);
getchar();
if (Caps == '1') /* 此时大写已锁定 */
{
result[len++] = c;
}
else
{
c = (char)(c - 32);
result[len++] = c;
}
}
else /* 输入是单个字符时 */
{
if (Caps == '1')
{
result[len++] = (char)(str[0] - 32);
}
else
{
result[len++] = str[0];
}
}
}
result[len] = '\0';
printf("%s\n", result);
}
return 0;
}