2014
02-10

# Typing

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.

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.

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.

2
5
Caps
a
c
Shift i
Shift t
6
Caps
a
c
Caps
i
t

ACit
ACit

#include <iostream>
#include <string>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
int flag = 0;
char a[10];
cin >> n;
while(n--)
{
cin >> a;
if(strcmp("Caps", a) == 0)
{
if(flag == 0)
flag = 1;
else
flag = 0;
continue;
}
if(strcmp("Shift", a) == 0)
{
cin >> a;
if(flag == 1)
putchar(tolower(a[0]));
else
putchar(toupper(a[0]));
continue;
}
if(flag == 0)
putchar( tolower(a[0]));
else if(flag == 1)
putchar( toupper(a[0]));
}
cout << endl;
}
return 0;
}

2. 在方法1里面：

//遍历所有的边，计算入度
for(int i=0; i<V; i++)
{
degree = 0;