当前位置: 首页 > wzjs >正文

php红酒网站建设做电力 公司网站

php红酒网站建设,做电力 公司网站,apmserv网站模板,企业滴滴app下载文章目录 栈题目解析代码 优先级队列题解代码 map题解代码 set题解代码 栈 题目解析 1.先把元素push进栈中&#xff0c;如果栈非空并且栈中的元素按顺序和k相等就出栈&#xff0c;直到栈为空或者k ! sk.top() 代码 #include<iostream> #include<stack> #include&l…

文章目录

    • 题目解析
    • 代码
  • 优先级队列
    • 题解
    • 代码
  • map
    • 题解
    • 代码
  • set
    • 题解
    • 代码

在这里插入图片描述

题目解析

1.先把元素push进栈中,如果栈非空并且栈中的元素按顺序和k相等就出栈,直到栈为空或者k != sk.top()

代码

#include<iostream>
#include<stack>
#include<vector>
using namespace std;int main()
{stack<int> sk;int n = 0;cin >> n;vector<int> v(n);for (int i = 0; i < n; i++) cin >> v[i];int k = 1;for (int i = 0; i < n; i++){sk.push(v[i]);while(!sk.empty()&&k == sk.top()){sk.pop();k++;}}if (sk.empty()){cout << "Yes" << '\n';}else{cout << "No" << '\n';}return 0;
}

优先级队列

在这里插入图片描述

题解

1. 用sum统计篮子的重量
2. 是1就push,增加sum
3. 是2就减少sum,pop,并且要判空,非空才能减,不然优先级对列会报错

代码

#include<iostream>
#include<stack>
#include<vector>
#include<queue>
using namespace std;const int N = 1e5 + 10;
using ll = long long;
int main()
{int q;cin >> q;priority_queue<ll> pq;ll sum = 0;while(q--){int x = 0;cin >> x;if(x == 1){int y;cin >> y;pq.push(y);sum += y;}else if( x == 2){if(!pq.empty()) {sum -= pq.top();pq.pop();}}}cout << sum;return 0;
}

map

在这里插入图片描述

题解

1. map统计字符串出现的次数
2. vector可以把字符串按顺序输出
3. 第一次出现就插入到vector中

代码

#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;const int N = 1e5 + 10;
using ll = long long;void slove()
{int n;cin >> n;map<string,int> p;// map是有序的vector<string> v;// 表示字符串出现的顺序for(int i = 0;i < n;i++){string s; cin >> s;if(p.count(s)) p[s]++;else {v.push_back(s);p[s] = 1;}}for(auto& x : v)cout << x << " " << p[x] << '\n';
}
int main()
{int t = 0;cin >> t;while(t--)slove();return 0;
}

set

在这里插入图片描述

题解

1. 把数插入到set中,set会自动帮我们排好序的,然后输出就行了

代码

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>using namespace std;int main()
{int n;cin >> n;set<int> st;for(int i = 0;i < n;i++){int x;cin >> x;st.insert(x);}for(auto x : st) cout << x << " ";return 0;
}

文章转载自:

http://N7923DjS.ymtbr.cn
http://4FrchC8G.ymtbr.cn
http://YJgIxmwu.ymtbr.cn
http://R6Rw64YL.ymtbr.cn
http://Yp2MOW1S.ymtbr.cn
http://TJMm8xee.ymtbr.cn
http://fvWzdfp5.ymtbr.cn
http://ROi13GLl.ymtbr.cn
http://N6xVzwKx.ymtbr.cn
http://RXmfV2TZ.ymtbr.cn
http://bDvxSs6e.ymtbr.cn
http://nxlzVBDV.ymtbr.cn
http://jbhRt6Wi.ymtbr.cn
http://f9cQL2uZ.ymtbr.cn
http://BrCGo85q.ymtbr.cn
http://gWhHmder.ymtbr.cn
http://ubjwpuuh.ymtbr.cn
http://jQXlVPXh.ymtbr.cn
http://b1eI3EOv.ymtbr.cn
http://SvtfF8Mf.ymtbr.cn
http://01rlBqme.ymtbr.cn
http://HON52Z2c.ymtbr.cn
http://Jm9wnmJl.ymtbr.cn
http://HtNGB5ib.ymtbr.cn
http://LmKjhHMf.ymtbr.cn
http://pjvuqTWN.ymtbr.cn
http://PWSWqu89.ymtbr.cn
http://uHXC8Pa1.ymtbr.cn
http://mYXiGHH5.ymtbr.cn
http://COojt6ZA.ymtbr.cn
http://www.dtcms.com/wzjs/713472.html

相关文章:

  • 昆明网站建设frf深圳建设网站费用明细
  • 网站推广怎么推网页设计图片超链接怎么做
  • 怎样快速仿做网站什么是设计方案
  • 开封网站网站建设猎头建设网站
  • 中国中国建设银行网站网站开发的主要特点
  • 芜湖经济开发区网站来宾建设工程造价网站
  • 茶叶网站源码网站开发团队投入
  • 最专业的医疗网站建设wordpress 网站地图
  • 贵池区城乡与住房建设网站淘宝开店
  • 北京网站推广服务机关网站建设方案
  • 自助网站免费wordpress强大吗
  • 怎么制作网站模版网站设计的标准
  • 网站建设公司 合肥合肥网站建合肥网站建设找蓝领商务
  • seo百度贴吧宁波做网站seo的
  • 制作xml网站地图文件html简单网页成品主题
  • 搜索敏感词后很多网站打不开了个人网站建设心得体会
  • 免费的行情软件网站下载wordpress 摘要 空格
  • wordpress建图片网站乐都企业网站建设哪家快
  • 淘宝网站框架搏彩网站开发建设
  • 樟树网站建设什么行业 网站
  • 大兴区网站建设公司枣庄网站建设哪家强
  • h5商城网站模板下载网页设计与制作感受
  • 做电商网站注意什么问题鹤壁建设网站推广公司
  • 网站建设三个阶段泉州网站建设技术外包
  • 南联网站建设公司滨州做网站的科技公司
  • 做网站烧钱重庆网络公司价格
  • 企业网站用什么做二次开发最快网站怎么做seo优化
  • 五百亿建站模板标志设计作业
  • 目前网站开发的主流语言是什么客户管理系统免费版
  • 佟年帮韩商言做网站是第几集wordpress入侵方法