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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

去重+排序板子(set+map)

發布時間:2025/3/15 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 去重+排序板子(set+map) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

給定n個數,去重排序后輸出個數和每個數

1.map實現

#pragma GCC optimize("O2") #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<set> #include<map> #include<limits.h> #include<ctime> #define N 100001 typedef long long ll; const int inf=999999999; const int maxn=2017; using namespace std; inline int read() {int f=1,x=0;char ch=getchar();while(ch>'9'|ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}return f*x; } typedef map<int,bool> mp; mp m; int main() {int n=read();for(int i=1;i<=n;i++){int k=read();m[k]=1;}cout<<m.size()<<endl;for(mp::iterator i=m.begin();i!=m.end();i++)cout<<i->first<<endl; }

?2.set實現

#pragma GCC optimize("O2") #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<set> #include<map> #include<limits.h> #include<ctime> #define N 100001 typedef long long ll; const int inf=999999999; const int maxn=2017; using namespace std; inline int read() {int f=1,x=0;char ch=getchar();while(ch>'9'|ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}return f*x; } set<int>s; int main() {int n=read();for(int i=1;i<=n;i++){int k=read();s.insert(k);}printf("%d",s.size());for(set<int>::iterator i=s.begin();i!=s.end();i++)cout<<*i<<endl; }

?

轉載于:https://www.cnblogs.com/tsunderehome/p/7476710.html

總結

以上是生活随笔為你收集整理的去重+排序板子(set+map)的全部內容,希望文章能夠幫你解決所遇到的問題。

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