Test

作者: amberfjx | 来源:发表于2017-05-24 22:52 被阅读0次

···
/*
1(60分)
题目:一个整数集 , 该整数集可以有重复元素, 初始为空集合 。可以指定如下指令:

  1. add x 将x加入整数集
  2. del x 删除整数集中所有与x相等的元素
  3. ask x 对整数集中元素x的情况询问
    下面为指令解释,并要求进行如下输出:
  4. add 输出操作后集合中x的个数
  5. del 输出操作前集合中x的个数
  6. ask 先输出0或1表示x是否曾被加入集合(0表示不曾加入),再输出当前集合中x的个数,中间用空格格开。
    提示
    请使用STL中的 set 和multiset 来完成该题

输入
第一行是一个整数n,表示命令数。0<=n<=100000。
后面n行命令。
输出
共n行,每行按要求输出。

样例输入
7 //第一行是整数,表示为命令数目
add 1
add 1
ask 1
ask 2
del 2
del 1
ask 1
样例输出
1
2
1 2
0 0
0
2
1 0
*/

include <iostream>

include <set>

include <string>

include <iterator>

include<ctime>

include<cstdlib>

include<array>

include<vector>

include<algorithm>

using namespace std;
/*
在VS 2012环境中编译通过 Win7 X64

样例输入在工程文件夹下面 STL_1.in 文件中
输出结果在工程文件夹下面 STL_1.out 文件中
如有问题请直接在群里 :@北京 - amberfjx
*/

define COMAND_LINE

int main()
{

ifdef COMAND_LINE

freopen("STL_1.in","rt",stdin);
freopen("STL_1.out","wt",stdout);

endif

ifndef COMAND_LINE

cout<<"请输入测试用例:\n"<<endl;

endif

multiset<int> mset;
set<int> mm;
char command[5];
int i,n,num,amount;
multiset<int>::iterator it;

cin >> n;

for (i = 0; i < n; i++)
{
    cin >> command >> num;
    switch(command[1])//这里取command[1] 而不是command[0] 是为了区分 {ask del add} 中的 add 和 ask 命令
    {
    case 'd': //add
        mset.insert(num);
        mm.insert(num);
        cout << mset.count(num) << endl;
        break;                
    case 'e': //del
        cout << mset.count(num) << endl;
        mset.erase(num);
        break;
    case 's': //ask
        if (mm.find(num) == mm.end())
            cout << "0 0" << endl;
        else
        {
            cout << "1 ";
            cout << mset.count(num) << endl;
        }
        break;
    }
}
return 0;

}
···

相关文章

  • 泰斯拓

    TEST test Test TEST test test test test test test test

  • makedown test

    test test test test test test test ####### test test test...

  • 无标题文章

    test test test test test test test test

  • 2019-01-14

    test test test test test test test test

  • test2

    test test test test test test

  • 简书

    简书 test test test test test test

  • Test

    Test test Test Test Test

  • 无标题文章

    test test test test test

  • 此处为标题?

    测试test测试test测试test测试test测试test测试test测试test测试test测试test测试t...

  • Mardown

    Mardown test+test+test+test+test

网友评论

      本文标题:Test

      本文链接:https://www.haomeiwen.com/subject/tafaxxtx.html