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

南通网站群建设企业网站推广建议

南通网站群建设,企业网站推广建议,网站建设的发展历史与新方向,西充县住房和城乡规划建设局网站首先学习队列,队列有先进先出的特性。广度优先遍历需要基于队列实现,C中的stl引入了队列的实现方式。队列支持push(),进入队尾,pop()出队,队头出队,front()获取队首元素,back()获取队尾元素&…

首先学习队列,队列有先进先出的特性。广度优先遍历需要基于队列实现,C++中的stl引入了队列的实现方式。队列支持push(),进入队尾,pop()出队,队头出队,front()获取队首元素,back()获取队尾元素,empty()判断队列是否为空。

第一题是约瑟夫环问题。

#include <stdio.h>
#include <queue>
using namespace std;
int main()
{queue<int> myqueue;int n,p,m;while(scanf("%d%d%d", &n,&p,&m)!=EOF){if(n ==0&&p==0&&m==0) break;//生成第一轮报数的队列//p, p+1,p+2,...,n,1,2,....int no = p;//孩子编号for(int i = 0; i < n;i++){myqueue.push(no);no++;if(no>n) no=1;}//开始报数int say = 1;while(1){int cur = myqueue.front();myqueue.pop();if(say == m){say = 1;if(myqueue.empty()){printf("%d\n", cur);break;}else{printf("%d,", cur);}}else {say++;myqueue.push(cur);}}}return 0;
}

第二题是排队打饭,分情况讨论即可,主要注意time是long long类型,使用int这题过不了。

#include <stdio.h>
#include <queue>
using namespace std;
struct Student{int a;//到达时刻int t;//打饭耗时int b;//最大等待时间
};
int main(){queue<Student> que;int n;scanf("%d", &n);for(int i = 0; i<n;i++){int ai,ti,bi;scanf("%d%d%d", &ai, &ti,&bi);Student s1;s1.a = ai;s1.b = bi;s1.t = ti;que.push(s1);//读入学生序列}long long time = 1;//记录当前时刻while(!que.empty()){Student stu = que.front();if(time>(stu.a+stu.b)){printf("-1 ");que.pop();}else if(time>=stu.a&&time<=(stu.a+stu.b)){printf("%d ", time);time += stu.t;que.pop();}else if(time<stu.a){time = stu.a;printf("%lld ", time);time += stu.t;que.pop();}}
}

下面学习栈,后进先出。深度优先遍历、表达式解析、递归会使用栈。stack支持push()入站,pop()出栈,top()获取栈顶元素,栈只支持获取栈顶元素,empty()获取栈是否为空。

第三题是编排字符串。栈的简单应用。

#include <stdio.h>
#include <stack>
#include <string>
using namespace std;
int main(){int n;scanf("%d", &n);stack <string> st1;for(int i = 0; i<n;i++){char mid[20];scanf("%s", mid);string str = mid;st1.push(str);stack<string> mystack;mystack = st1;int num = 1;while(!mystack.empty()){if(num>4) break;string str1 = mystack.top();printf("%d=%s ", num, str1.c_str());num++;mystack.pop();}printf("\n");}}

第四题是括号匹配,经典题目。

#include <stdio.h>
#include <stack>
#include <string>
using namespace std;
int main()
{char arr[20000];scanf("%s", arr);string str = arr;stack<char> mystack;mystack.push(str[0]);for(int i = 1;i < str.size();i++){if(str[i] == '<'||str[i] == '('||str[i] == '{'||str[i] == '['){mystack.push(str[i]);}else if(str[i]=='>'){if(mystack.empty()) {printf("no");return 0;}char res = mystack.top();if(res == '<') mystack.pop();else {printf("no");return 0;}}else if(str[i]==')'){if(mystack.empty()) {printf("no");return 0;}char res = mystack.top();if(res == '(') mystack.pop();else {printf("no");return 0;}}else if(str[i]=='}'){if(mystack.empty()) {printf("no");return 0;}char res = mystack.top();if(res == '{') mystack.pop();else {printf("no");return 0;}}else if(str[i]==']'){if(mystack.empty()) {printf("no");return 0;}char res = mystack.top();if(res == '[') mystack.pop();else {printf("no");return 0;}}}if(mystack.empty()==true) printf("yes");else printf("no");return 0;
}

第五题是堆栈的使用​​​​​​​,简单模拟。

#include <stdio.h>
#include <string>
#include <stack>
using namespace std;
int main() {int n;while (scanf("%d", &n) != EOF) {stack <int> mystack;for (int i = 0; i < n; i++) {char op[2];scanf("%s", op);string op2=op;if (op2 == "A") {if (mystack.empty()) printf("E\n");else printf("%d\n", mystack.top());} else if (op2 == "O") {if (!mystack.empty()) mystack.pop();} else if (op2 == "P") {int num;scanf("%d", &num);mystack.push(num);}}}return 0;
}

第六题是计算表达式,写了半天代码逻辑不对,气完了。建立运算符栈与运算数栈。从左向右扫描表达式,遇到操作数就加入操作数栈,扫描到运算符,若运算符栈为空,则直接压入运算符栈,若运算符栈不为空但当前运算符优先级大于栈顶运算符,也执行压栈操作。若运算符栈不为空但当前运算符优先级低于栈顶运算符,则弹出栈内的运算符,同时弹出操作数,直到当前运算符优先级再次大于栈顶运算符,压入栈中。

#include <stdio.h>
#include <string>
#include <stack>
#include <map>
using namespace std;
int main() {char str[1000] = {0};map<char, int> prio = {{'\0', 0}, {'+', 1}, {'-', 1}, {'*', 2}, {'/', 2}};while (scanf("%s", str) != EOF) {string numstr = "";stack <char> opstack;stack <double> numstack;for (int i = 0;; i++) {if (str[i] >= '0' && str[i] <= '9') {numstr.push_back(str[i]);} else {double num = stod(numstr);numstr = "";//数值提取numstack.push(num);//什么时候弹栈?栈非空&&新的op的优先级不高于栈顶的优先级//循环弹栈和计算while (!opstack.empty() && prio[str[i]] <= prio[opstack.top()]) {double right = numstack.top();numstack.pop();double left = numstack.top();numstack.pop();char curop = opstack.top();opstack.pop();if (curop == '+') numstack.push(left + right);else if (curop == '-') numstack.push(left - right);else if (curop == '*') numstack.push(left * right);else if (curop == '/') numstack.push(left / right);}//栈为空或者新运算符的优先级大于栈顶运算符if (str[i] == '\0') {printf("%d\n", (int)numstack.top());break;} else opstack.push(str[i]);}}}return 0;
}

第七题是模拟出入栈​​​​​​​。

#include <bits/stdc++.h>
using namespace std;int main() {string s;while (cin >> s) {stack<char> stk;int j = 0; //j用来扫描出栈序列s的for (char i = 'a'; i <= 'z'; ++ i) {stk.push(i); //每次按顺序入栈一个while (stk.size() && stk.top() == s[j]) {j++; //出栈序列向后走匹配下一个stk.pop(); //出栈}}if (stk.empty()) cout << "yes\n"; //栈空了,就是匹配的else cout << "no\n";}return 0;
}

http://www.ds6.com.cn/news/10000.html

相关文章:

  • 网站推广怎么做 知乎大连百度seo
  • 番禺知名网站建设公司小红书关键词热度查询
  • 锦州网站制作2023年最新时政热点
  • 湖北网站seo设计网店运营培训哪里好
  • 小红书网站开发费用百度关键词优化软件如何
  • 网站建设报价方案对比廊坊seo外包
  • 小额贷网站建设百度网络小说排行榜
  • 白山市住房和建设局网站seo实战培训王乃用
  • wordpress驳回评论优化百度百科
  • 已有网站可以做服务器吗国外网站怎么推广
  • hph做动态网站阿里云域名注册流程
  • 优秀网站模板欣赏网络广告公司
  • 关于购物网站建设的论文市场推广方案范文
  • 公司做网站会计凭证怎么做淘宝推广费用一般多少
  • 佛山网站优化推广方案seo的基本步骤包括哪些
  • 在哪做网站好广州百度快速优化排名
  • 企业网站模板下载562佛山网站建设模板
  • 图书馆网站建设需求方案品牌营销策划案例ppt
  • 网站项目建设计划免费培训课程
  • 北医三院生殖科做试管的网站有人看片吗免费的
  • 网站建设与规划实验总结网站分析报告
  • asp iis设置网站路径免费seo推广软件
  • 企业网站设计的特点百度推广登陆网址
  • 织梦网站地图底部互联网推广是什么工作内容
  • net网站开发找那家济南优化哪家好
  • 做计算机网站有哪些功能长沙seo网站
  • 模板网站 可以做推广吗线上运营推广
  • 建设手机网站如何做一个自己的电商平台
  • 视频网站建设服务计算机培训机构排名前十
  • 音乐网站模板免费源码百度号注册官网