日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

3:Set

發布時間:2025/5/22 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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#23831 01 /*
02 +++++++++++++++++++++++++++++++++++++++
03 ??????????????? author: chm
04 +++++++++++++++++++++++++++++++++++++++
05 */
06
07
08 #include <map>
09 #include <set>
10 #include <list>
11 #include <queue>
12 #include <cmath>
13 #include <stack>
14 #include <bitset>
15 #include <cstdio>
16 #include <cctype>
17 #include <vector>
18 #include <cstdlib>
19 #include <cstring>
20 #include <fstream>
21 #include <sstream>
22 #include <iomanip>
23 #include <iostream>
24 #include <algorithm>
25
26 using namespace std;
27
28 FILE*??????????? fin???????? = stdin;
29 FILE*??????????? fout???????? = stdout;
30 const int??????? max_size???? = 10086;
31
32 multiset<int> st;
33 set<int> st1;
34 int main()
35 {
36
37 ??? int n;
38 ??? int num;
39 ??? int tmp;
40 ??? char str[15];
41 ??? scanf("%d\n", &n);
42
43 ??? while(n--)
44 ??? {
45 ??????? gets(str);
46 ??????? num = strtol(str + 4, NULL, 10);
47 ??????? switch(str[2])
48 ??????? {
49 ??????? case 'd': //add
50 ??????????? st.insert(num);
51 ??????????? st1.insert(num);
52 ??????????? fprintf(fout, "%d\n", st.count(num));
53 ??????????? break;
54
55 ??????? case 'k': //ask
56 ??????????? tmp = st.count(num);
57 ??????????? fprintf(fout, "%d %d\n", st1.count(num) ? 1 : 0, tmp);
58 ??????????? break;
59
60 ??????? case 'l': //del
61 ??????????? tmp = st.count(num);
62 ??????????? fprintf(fout, "%d\n", tmp);
63 ??????????? st.erase(num);
64 ??????????? break;
65 ??????? }
66 ??? }
67 ???
68 ??? return 0;
69 }

轉載于:https://www.cnblogs.com/invisible/archive/2011/11/06/2238457.html

總結

以上是生活随笔為你收集整理的3:Set的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。