计算机网络透明网桥算法时间戳c++
要交CG的兄弟们别抄啊,撞上了严nan谁都不会放过的
好久没写博客了,这次是老师布置的作业,做出来一种,觉得写得很不好,第一种方法把情况都写死在代码里了。
上代码
#include<iostream>
#include<map>
using namespace std;
int main(){
map<char,int>mp1;
map<char,int>mp2;
while(true){
cout<<"请输入源站点、目标站点、1号站接收的接口和2号站接收的接口以空格隔开"<<endl;
char destinatios,source;
int inport1,inport2;
cin>>source>>destinatios>>inport1>>inport2;
mp1[source]=inport1;
mp2[source]=inport2;
if(mp1[destinatios]==0&&mp2[destinatios]==0){
cout<<"查表失败,向所有站点广告"<<endl;
continue;
}
if(inport1==mp1[destinatios]){
cout<<"站点1不需要转发!"<<endl;
continue;
mp1[source]=inport1;
}else cout<<"站点1要转发!"<<endl;
if(inport2==mp2[destinatios]){
cout<<"站点2不需要转发!"<<endl;
mp2[source]=inport2;
continue;
}else cout<<"站点2要转发!"<<endl;
}
return 0;
}


第二种就较友好点,我把网桥的数量可以自定义,我认为这样才是真正的实现了学习的需求
上代码
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
int n;
cout<<"请输入桥数,默认从左到右为0 1 2 n-1"<<endl;
cout<<"请输入源站点左右桥号、起始位置、目标位置。"<<endl;
cout<<"假设网络的两个端点都是网桥,即所有源站点均在两个网桥中间"<<endl;
cin>>n;//桥数
vector<map<char,int> >v(n);
while(true){
char destinatios,source;
int start1,start2;
cin>>start1>>start2>>source>>destinatios;
int f=0;
if(v[start1][destinatios]==0&&v[start2][destinatios]==0){
cout<<"-----------查找失败!向所有站点广播-----------"<<endl;
for(int i=0;i<=start1;i++)
v[i][source]=2;
for(int i=start2;i<n;i++)
v[i][source]=1;
continue;
}
if(v[start1][destinatios]==2){
cout<<"-----------"<<start1<<"号站点不需要转发-----------"<<endl;
f=1;
}
if(v[start2][destinatios]==1){
cout<<"-----------"<<start2<<"号站点不需要转发-----------"<<endl;
if(f==1){
cout<<"-----------目标站点就在"<<start1<<"和"<<start2<<"之间-----------"<<endl;
continue;
}
}
if(v[start1][destinatios]==1){
while(v[start1][destinatios]==1){
cout<<"-----------"<<start1<<"号站点已向左转发-----------"<<endl;
v[start1][source]=2;
start1--;
}
continue;
}
if(v[start2][destinatios]==1){
while(v[start2][destinatios]==1){
cout<<"-----------"<<start2<<"号站点已向右转发-----------"<<endl;
v[start2][source]=1;
start2--;
}
continue;
}
}
}


接下来做的是要加上时间戳,我对时间函数的调用不是很熟悉,就只是实现了这个功能,没有追求精确无误,功能没有问题,但是不是严格得按照打印输出一样显示超过五秒就删除
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <time.h>
#include<iostream>
#include<map>
#include<vector>
#include<time.h>
using namespace std;
int n;
vector<map<char,int> >v(100);
vector<map<char,int> >shijian(100);
void ff(){
for(int k=0;k<n;k++){
for(map<char,int>::iterator it=shijian[k].begin();it!=shijian[k].end();it++){
clock_t start;
start = clock();
char sou=it->first;
if(start-it->second-shijian[k][sou]>5*60){
v[k][sou]=0;
cout<<sou<<"在"<<k<<"号站点的时间大于5秒,记录已被清除"<<endl;
}
}
}
}
int main(){ cin>>n; while(true){
clock_t start;
char des,sou;
int start1,start2;
cin>>start1>>start2>>sou>>des;
int f=0;
if(v[start1][des]==0&&v[start2][des]==0){
cout<<"查找失败,向所有人广播!"<<endl;
for(int i=0;i<=start1;i++){
v[i][sou]=2;
start = clock();
shijian[i][sou]=start;
cout<<i<<"号站点"<<sou<<"的最新时间是"<<shijian[i][sou]<<endl;
}
for(int j=start2;j<n;j++){
v[j][sou]=1;
start = clock();
shijian[j][sou]=start;
cout<<j<<"号站点"<<sou<<"的最新时间是"<<shijian[j][sou]<<endl;
}
ff();
continue;
}
if(v[start1][des]==2){
cout<<"-------------"<<start1<<"号站点不需要转发----------"<<endl;
f=1;
}
if(v[start2][des]==1){
cout<<"------------"<<start2<<"号站点不需要转发------------"<<endl;
if(f==1){
cout<<"------------目标站点就在"<<start1<<"和"<<start2<<"之间----------"<<endl;
ff();
continue;
}
}
if(v[start1][des]==1){
while(v[start1][des]==1){
cout<<"----------"<<start1<<"号站点已向左转发---------"<<endl;
v[start1][sou]=2;
start = clock();
shijian[start1][sou]=start;
cout<<start1<<"号站点"<<sou<<"的最新时间是"<<shijian[start1][sou]<<endl;
start1--;
}
ff();
continue;
}
if(v[start2][des]==1){
while(v[start2][des]==1){
cout<<"----------"<<start2<<"号站点已向右转发---------"<<endl;
v[start2][sou]=1;
start = clock();
shijian[start2][sou]=start;
cout<<start2<<"号站点"<<sou<<"的最新时间是"<<shijian[start2][sou]<<endl;
start2--;
}
ff();
continue;
}
ff();
}
}

计算机网络透明网桥算法时间戳c++的更多相关文章
- Python3 透明网桥算法
import time #定义网桥1 b1 = {} port_list1 = [1, 2] #主机列表 L1 = ['a','b','c'] L2 = ['d','e'] L = [L1,L2] d ...
- 【最大团转最大点独立集(匈牙利算法+时间戳优化)】BZOJ2744-[HEOI2012]朋友圈
[题目大意] 有两个国家A和B.存在以下朋友关系: 1.A国:每个人都有一个友善值,当两个A国人的友善值a.b,如果a xor b mod 2=1,那么这两个人都是朋友,否则不是: 2.B国:每个人都 ...
- 关于 centos 7系统,iptables透明网桥实现【转载请注明】
首先建立网桥:(使用bridge) 示例 桥接eth0 与 eth1 网口 /sbin/modprobe bridge /usr/sbin/brctl addbr br0 /sbin/ifup ...
- 关于 centos 7系统,iptables透明网桥实现
首先建立网桥:(使用bridge) 示例 桥接eth0 与 eth1 网口 /sbin/modprobe bridge /usr/sbin/brctl addbr br0 /sbin/ifup ...
- 计算机网络 Computer Networks 期末复习总提纲
平时不学习,期末火葬场. 一周时间靠王道考研和各路 pdf 自学计网,留下的提纲都在这里了.全是干货.全文 pdf 可以在这里下载:http://cloud.billc.io/s/xNHarppQPG ...
- nat模式、路由模式,网桥模式
路由器的几种连接方式 NAT英文全称是“Network Address Translation”,中文意思是“网络地址转换”,它是一个IETF(Internet Engineering Task Fo ...
- 如何计算CDS view里两个时间戳之间的天数间隔
ABAP透明表里的时间戳,数据类型为dec: 有个需求:计算这两个时间戳之间的天数间隔,丢弃时间戳年-月-日8位后面的小时:分钟:秒. 举个例子:如果时间戳是20180918173132,丢弃1731 ...
- TCP/IP(三)数据链路层~2
一.局域网 1.1.局域网和以太网的区别和联系 局域网:前面已经介绍了,其实就是学校里面.各个大的公司里,自己组件的一个小型网络,这种就属于局域网. 以太网:以太网(Ethernet)指的是由Xero ...
- GPON和820.1p学习及资料(zt)
1)hw的两个PPT不错,GPON技术基础.ppt和10G-GPON技术基础.ppt, 介绍了GPON的知识背景,标准的名称,帧协议. 尤其是详细对比了10G-PON和G-PON的区别,以及演进的道路 ...
随机推荐
- 使用VM克隆CentOS后,更改网络配置
在使用VM克隆之后,遇到一件非常郁闷的事,就算我使用‘setup’命令,修改了我的网络配置,依然无法查询到我配置的网卡,也无法开启网卡. 经过百度等一系列手段,总结如下套路--PS:朋友称之为“破釜沉 ...
- [Selenium With C#基础教程] Lesson-05 文本框
作者:Surpassme 来源:http://www.jianshu.com/p/7dca7d0d1ea3 声明:本文为原创文章,如需转载请在文章页面明显位置给出原文链接,谢谢. 文本框在Web页面中 ...
- Appium常用Api实操
本文是基于python语言在android上实操的,仅记录(忽略排版~~~) 会不时更新的: from appium import webdriver from selenium.webdriver. ...
- STL 中的map 与 hash_map的理解
可以参考侯捷编著的<STL源码剖析> STL 中的map 与 hash_map的理解 1.STL的map底层是用红黑树存储的,查找时间复杂度是log(n)级别: 2.STL的hash_ma ...
- CodeForces 122G Lucky Array(一脸懵逼的树状数组)
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal re ...
- VC++下的Unicode编程
ASCII是用来表示英文字符的一种编码规范.每个ASCII字符占用1个字节,因此,ASCII编码可以表示的最大字符数是255(00H—FFH). 其实,英文字符并没有那么多,一般只用前128个(00H ...
- log4net 入门使用
log4net 是dotnet平台下的一个日记记录组件. 一 NuGet中安装log4net包: 二 配置log4net.config文件 配置文件内容: <?xml version=&quo ...
- 利用PhotoShop对大图像进行等分切片
图文介绍利用PhotoShop等分切图 1.调用切片工具,右键选择划分切片 2.指定水平划分.垂直划分的等分数量,点击确定 3.在文件菜单中选择存储为... 4.配置图像质量参数.点击存储.指定存储位 ...
- robot中使用evaluate转化数据格式
如果你使用robot却没有用过evaluate,那你将永远禁锢在框架中. json对象格式入参可以使用字典格式直接传入,但最近有一个接口测试的入参是一个json数组,在传参时总是提示请求参数不合法, ...
- 使用bmfont制作字体
本地显示正常 将制作好的字体上传 别人用不好使 制作完场景没ctrl+s 保存 ctrl+s保存之后生成另外的文件