北邮新OJ98
来源:互联网 发布:友窝能看m3u8源码 编辑:程序博客网 时间:2024/06/02 05:47
http://code.bupt.edu.cn/problem/p/98/
这题其实很蛋疼,在九度OJ一直过不了,但是在北邮OJ相同的代码直接AC
主要就是考虑数据包长度不是固定的即可
当时被九度的判题整疯了,代码也写的很长很繁琐
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>using namespace std; void P(char str[],int n){ //int len=strlen(str); cout<<"Case #"<<n<<endl; //求数据包长度 int temp1,temp2,temp3,temp4; if('0'<=str[6]&&str[6]<='9') temp1=str[6]-'0'; else if('a'<=str[6]&&str[6]<='z') temp1=str[6]-'a'+10; else temp1=str[6]-'A'+10; if('0'<=str[7]&&str[7]<='9') temp2=str[7]-'0'; else if('a'<=str[7]&&str[7]<='z') temp2=str[7]-'a'+10; else temp2=str[7]-'A'+10; if('0'<=str[9]&&str[9]<='9') temp3=str[9]-'0'; else if('a'<=str[9]&&str[9]<='z') temp3=str[9]-'a'+10; else temp3=str[9]-'A'+10; if('0'<=str[10]&&str[10]<='9') temp4=str[10]-'0'; else if('a'<=str[10]&&str[10]<='z') temp4=str[10]-'a'+10; else temp4=str[10]-'A'+10; int T_len=temp1*4096+temp2*256+temp3*16+temp4; cout<<"Total length = "<<T_len<<" bytes"<<endl; //求源IP int a,b; if('0'<=str[36]&&str[36]<='9') a=str[36]-'0'; else if('a'<=str[36]&&str[36]<='z') a=str[36]-'a'+10; else a=str[36]-'A'+10; if('0'<=str[37]&&str[37]<='9') b=str[37]-'0'; else if('a'<=str[37]&&str[37]<='z') b=str[37]-'a'+10; else b=str[37]-'A'+10; temp1=a*16+b; if('0'<=str[39]&&str[39]<='9') a=str[39]-'0'; else if('a'<=str[39]&&str[39]<='z') a=str[39]-'a'+10; else a=str[39]-'A'+10; if('0'<=str[40]&&str[40]<='9') b=str[40]-'0'; else if('a'<=str[40]&&str[40]<='z') b=str[40]-'a'+10; else b=str[40]-'A'+10; temp2=a*16+b; if('0'<=str[42]&&str[42]<='9') a=str[42]-'0'; else if('a'<=str[42]&&str[42]<='z') a=str[42]-'a'+10; else a=str[42]-'A'+10; if('0'<=str[43]&&str[43]<='9') b=str[43]-'0'; else if('a'<=str[43]&&str[43]<='z') b=str[43]-'a'+10; else b=str[43]-'A'+10; temp3=a*16+b; if('0'<=str[45]&&str[45]<='9') a=str[45]-'0'; else if('a'<=str[45]&&str[45]<='z') a=str[45]-'a'+10; else a=str[45]-'A'+10; if('0'<=str[46]&&str[46]<='9') b=str[46]-'0'; else if('a'<=str[46]&&str[46]<='z') b=str[46]-'a'+10; else b=str[46]-'A'+10; temp4=a*16+b; cout<<"Source = "<<temp1<<"."<<temp2<<"."<<temp3<<"."<<temp4<<endl; //目的IP if('0'<=str[48]&&str[48]<='9') a=str[48]-'0'; else if('a'<=str[48]&&str[48]<='z') a=str[48]-'a'+10; else a=str[48]-'A'+10; if('0'<=str[49]&&str[49]<='9') b=str[49]-'0'; else if('a'<=str[49]&&str[49]<='z') b=str[49]-'a'+10; else b=str[49]-'A'+10; temp1=a*16+b; if('0'<=str[51]&&str[51]<='9') a=str[51]-'0'; else if('a'<=str[51]&&str[51]<='z') a=str[51]-'a'+10; else a=str[51]-'A'+10; if('0'<=str[52]&&str[52]<='9') b=str[52]-'0'; else if('a'<=str[52]&&str[52]<='z') b=str[52]-'a'+10; else b=str[52]-'A'+10; temp2=a*16+b; if('0'<=str[54]&&str[54]<='9') a=str[54]-'0'; else if('a'<=str[54]&&str[54]<='z') a=str[54]-'a'+10; else a=str[54]-'A'+10; if('0'<=str[55]&&str[55]<='9') b=str[55]-'0'; else if('a'<=str[55]&&str[55]<='z') b=str[55]-'a'+10; else b=str[55]-'A'+10; temp3=a*16+b; if('0'<=str[57]&&str[57]<='9') a=str[57]-'0'; else if('a'<=str[57]&&str[57]<='z') a=str[57]-'a'+10; else a=str[57]-'A'+10; if('0'<=str[58]&&str[58]<='9') b=str[58]-'0'; else if('a'<=str[58]&&str[58]<='z') b=str[58]-'a'+10; else b=str[58]-'A'+10; temp4=a*16+b; cout<<"Destination = "<<temp1<<"."<<temp2<<"."<<temp3<<"."<<temp4<<endl; //IP头的长度 int len; if('0'<=str[1]&&str[1]<='9') len=str[1]-'0'; else if('a'<=str[1]&&str[1]<='z') len=str[1]-'a'+10; else len=str[1]-'A'+10; len=len*4*2;//以一个符号为单位 int st=len/2*3;//st是TCP的起始地址 //源端口 int s; if('0'<=str[st]&&str[st]<='9') temp1=str[st]-'0'; else if('a'<=str[st]&&str[st]<='z') temp1=str[st]-'a'+10; else temp1=str[st]-'A'+10; if('0'<=str[st+1]&&str[st+1]<='9') temp2=str[st+1]-'0'; else if('a'<=str[st+1]&&str[st+1]<='z') temp2=str[st+1]-'a'+10; else temp2=str[st+1]-'A'+10; if('0'<=str[st+3]&&str[st+3]<='9') temp3=str[st+3]-'0'; else if('a'<=str[st+3]&&str[st+3]<='z') temp3=str[st+3]-'a'+10; else temp3=str[st+3]-'A'+10; if('0'<=str[st+4]&&str[st+4]<='9') temp4=str[st+4]-'0'; else if('a'<=str[st+4]&&str[st+4]<='z') temp4=str[st+4]-'a'+10; else temp4=str[st+4]-'A'+10; s=temp1*4096+temp2*256+temp3*16+temp4; cout<<"Source Port = "<<s<<endl; //目的端口 st=st+6; int d; if('0'<=str[st]&&str[st]<='9') temp1=str[st]-'0'; else if('a'<=str[st]&&str[st]<='z') temp1=str[st]-'a'+10; else temp1=str[st]-'A'+10; if('0'<=str[st+1]&&str[st+1]<='9') temp2=str[st+1]-'0'; else if('a'<=str[st+1]&&str[st+1]<='z') temp2=str[st+1]-'a'+10; else temp2=str[st+1]-'A'+10; if('0'<=str[st+3]&&str[st+3]<='9') temp3=str[st+3]-'0'; else if('a'<=str[st+3]&&str[st+3]<='z') temp3=str[st+3]-'a'+10; else temp3=str[st+3]-'A'+10; if('0'<=str[st+4]&&str[st+4]<='9') temp4=str[st+4]-'0'; else if('a'<=str[st+4]&&str[st+4]<='z') temp4=str[st+4]-'a'+10; else temp4=str[st+4]-'A'+10; d=temp1*4096+temp2*256+temp3*16+temp4; cout<<"Destination Port = "<<d<<endl; } int main(){ int n; while(scanf("%d",&n)!=EOF) { getchar(); for(int i=1;i<=n;i++) { char str[1001]; gets(str); P(str,i); cout<<endl; } //cout<<endl; } return 0;}
0 0
- 北邮新OJ98
- 北邮新OJ87
- 北邮新OJ88
- 北邮新OJ89
- 北邮新OJ90
- 北邮新OJ91
- 北邮新OJ92
- 北邮新OJ93
- 北邮新OJ94
- 北邮新OJ95
- 北邮新OJ96
- 北邮新OJ97
- 北邮新OJ99
- 北邮新OJ100
- 北邮新OJ101
- 北邮新OJ103
- 北邮新OJ104
- 北邮新OJ105
- log4j.jar包没有导入错误
- 数字证书使用Javascript在浏览器中自动安装的解决方案
- 一步一步写算法(之字符串查找 中篇)
- Ubuntu11密码忘记解决
- 阿里数据分析师面试准备二:对阿里数据分析师岗位的理解
- 北邮新OJ98
- TabHost的使用方法(不继承TabActivity)
- oracle11g RAC GI ORA-15003: diskgroup "XXXX" already mounted in another lock name space
- 一步一步写算法(之字符串查找 下篇)
- Java SE之旅_02_i=i++的内部原理
- ftp上传和下载文件的java实现
- 正则表达式(python)
- android 用sharepreferences实现仿QQ登录多账号的保存的效果
- 一步一步写算法(之“数星星”)