zoukankan      html  css  js  c++  java
  • 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;
    	}
    }
  • 相关阅读:
    Java入门第37课——猜字母游戏之设计数据结构
    Sublime Text 3 常用快捷键
    WEB前端响应式布局之BootStarp使用
    js让页面逐渐变透明,直到消失
    Vue实战之插件 sweetalert 的使用
    搭建jQuery开发环境
    Layui数据表单的编辑
    SpringBoot基于websocket的网页聊天
    layui修改数据的时候下拉框和选择框默认选中
    Linux 软件编译、安装、删除
  • 原文地址:https://www.cnblogs.com/speedmancs/p/1715616.html
Copyright © 2011-2022 走看看