3:Set

3:Set

时间限制:
5000ms
内存限制:
100000kB
描述
现有一整数集(允许有重复元素),初始为空。我们定义如下操作:

add x 把x加入集合

del x 把集合中所有与x相等的元素删除

ask x 对集合中元素x的情况询问

对每种操作,我们要求进行如下输出。

add 输出操作后集合中x的个数

del 输出操作前集合中x的个数

ask 先输出0或1表示x是否曾被加入集合(0表示不曾加入),再输出当前集合中x的个数,中间用空格格开。
输入
第一行是一个整数n,表示命令数。0<=n<=100000。

后面n行命令,如Description中所述。
输出
共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
提示
Please use STL’s set and multiset to finish the task

C++语言: Codee#2383101/

02+++++++++++++++++++++++++++++++++++++++

03author: chm

04+++++++++++++++++++++++++++++++++++++++

05
/

06

07

08#include



09#include

10#include

11#include

12#include

13#include

14#include

15#include

16#include

17#include

18#include

19#include

20#include

21#include

22#include

23#include

24#include

25

26usingnamespacestd;

27

28FILE*fin=stdin;

29FILE*fout=stdout;

30constintmax_size=10086;

31

32multiset<int>st;

33set<int>st1;

34intmain()

35{

36

37intn;

38intnum;

39inttmp;

40charstr[15];

41scanf("%d\n",&n);

42

43while(n--)

44{

45gets(str);

46num=strtol(str+4,NULL,10);

47switch(str[2])

48{

49case'd'://add

50st.insert(num);

51st1.insert(num);

52fprintf(fout,"%d\n",st.count(num));

53break;

54

55case'k'://ask

56tmp=st.count(num);

57fprintf(fout,"%d %d\n",st1.count(num)?1:0,tmp);

58break;

59

60case'l'://del

61tmp=st.count(num);

62fprintf(fout,"%d\n",tmp);

63st.erase(num);

64break;

65}

66}

67

68return0;

69}原文链接: https://www.cnblogs.com/invisible/archive/2011/11/06/2238457.html

**欢迎关注**

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/35875

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 下午12:41
下一篇 2023年2月8日 下午12:42

相关推荐