So Many Skirt
xiaoA is a beautiful girl, and she has so many skirts that she won't wear a skirt a second time before the skirt is washed. Now xiaoA wants to go shopping, how many skirts she can choose to wear?
In order to distinguish these skirts, she gives out every skirt with a unique name.
Input
The first line of input contains a positive integer T (T <= 100), the number of test cases.
Each test case contains two integers N and M (1<=N, M<=100) in the first line.
N is the number of skirts.M is the number of operations.
Then N lines follow. Every line contains a word and the word is not longer than 10.
Then M lines follow. Each line contains a character 'D' or 'W' and the name of a skirt.
'D' indicates that xiaoA has wore the skirt. 'W' indicates that xiaoA has washed the skirt.
Output
After the M operations, you need to output that how many skirts can be chosen by xiaoA to wear.
Sample Input
1
5 5
SkirtA
SkirtB
SkirtC
SkirtD
SkirtE
D SkirtA
D SkirtB
D SkirtC
D SkirtD
W SkirtA
Sample Output
2
#include <iostream> #include <string> #include <map> using namespace std; void main() { map<string,int> skirts; map<string,int>::iterator it; int T; cin >> T; for (int i = 0;i<T;i++) { int N,M; cin >> N>>M; skirts.clear(); string skirtName; for (int j = 0;j<N;j++) { cin >> skirtName; skirts[skirtName] = 1; //表示都洗过了,都能穿 } for (int j = 0;j<M;j++) { string Operator; cin >> Operator >> skirtName; if (Operator == "D") { skirts[skirtName] = 0; }else if (Operator == "W") { skirts[skirtName] = 1; } } //最后输出能穿的衣服的个数 int count = 0; for (it = skirts.begin();it!=skirts.end();it++) { count += it->second; } cout << count << endl; } }
posted on 2010-04-19 19:56 speedmancs 阅读(318) 评论(0) 编辑 收藏 举报