主机访问域名的过程 访问DNS域名服务器,已知域名服务器IP地址,需要知道域名服务器的MAC地址,主机广播ARP请求分组(目的MAC为全1),域名服务器与主机在一个局域网内,域名服务器收到ARP请求分组以后,对比目的IP是自己的IP地址,就发出一个单拨ARP响应分组,携带了自己的MAC地址。主机收到响应后,以客户机的身份向本地域名服务器发送DNS请求报文,本地域名服务器先是查询有两种方法查询域名对应的IP地址,分别是递归查询和递归与迭代查询,本地域名服务器将查询结果存储在本地缓存中,并返回给主机。查询www的MAC地址。...
1074 Reversing Linked List 测试点5、6 测试点5:每k个反转一次,不足k的不反转。错误原因:只有第一组k个反转了,而后的几组都没反转测试用例:00100 6 200000 4 9999900100 1 1230968237 6 -133218 3 0000099999 5 6823712309 2 33218输出12309 2 0010000100 1 0000000000 4 3321833218 3 6823768237 6 9999999999 5 -1测试点6:错误原因:有些节点不在头节点指
关键路径、最长路径 测试用例:6 80 1 30 2 20 3 22 3 51 4 33 5 22 5 34 5 1关键路径一定是有向无环图代码段#include <cstdio>#include <cstring>#include <iostream>#include <math.h>#include <stdio.h>#include <algorithm>#include <stdlib.h>
拓扑排序 c++ #include <cstdio>#include <cstring>#include <iostream>#include <math.h>#include <stdio.h>#include <algorithm>#include <stdlib.h>#include <map>#include <vector>#include <set>#include <.
最长公共子串 字符串hash法 算法笔记P450#include <cstdio>#include <cstring>#include <iostream>#include <math.h>#include <stdio.h>#include <algorithm>#include <stdlib.h>#include <map>#include <vector>#include <set>#i
素数的判定 素数:只能被自己或者1整除的正整数,1不属于素数方法一:bool isPrime(int n){ if(n<=1) return false; int sqr = (int)sqrt(1.0*n); for(int i=2;i<=sqr;i++){ if(n%i==0) return false; } return true;}方法二:过筛法...
进制转换c++ 十进制的转换int d[100];void change10ToOther(int n,int radix)//radix为目标进制{ int len =0; do{ d[len++] = n%radix; n/=radix; }while(n!=0);}//转换后的逆序存储转换为十进制int otherTo10(int n[] ,int radix){ //若输入为顺序的n int len =
c++中map的用法 map简单来说就是实现a到b的映射,可以自定义不同变量类型的映射头文件:#include<map>using namespace std;1. map的定义map<typename1,typename2> mp;注:字符串数组只能用string映射,不能用char数组2. map访问,与访问数组类似,直接用map[键值]访问,map中所有的键值是唯一的map<char,int> mp;mp['c'] = 20;printf("%d"
1075 PAT Judge 测试点四 测试点四试了很多次是因为排序问题,把不能输出的和可以输出的记录一起排序,这里修改一下排序算法就ok了参考了知乎的文章【PAT A1075】PAT Judge(详细解决测试点4!) - 知乎 (zhihu.com)int full[10]={0};bool cmp (Student a,Student b){ if(a.total!=b.total) return a.total>b.total; else if(a.fullCount!=b.fullCount) return a.
c++中sort函数 头文件:#include <algorithm>using namespace std;函数://sort(数组首地址,数组尾地址+1,比较函数cmp(可省略))char a[10];sort(a,a+10,cmp);cmp比较函数伪代码bool cmp(元素A 元素B){ if(A!=B) return A>B //按元素递增次序排序}字符串比较函数strcmp#include <cstring>strcmp(char
输入 空格的陷阱 不可读入空格 char a[300]; scanf("%s",a);// 不能输入空格,即到输入到空格即止可以读入空格 char a; scanf("%c", a) //可以输入空格,和换行,注意不读入换行和空格时要用getchar()吸收 char a[300]; gets(temp); //可以输入空格,到换行即止 //注意 在pat中gets不兼容,要用cin.getline(a,size);.
int与char相互转换 c++ char -> intchar a= '1';int b= a - '0'; int -> char itoa函数(数字,字符串地址,进制)#include<iostream>#include<string>using namespace std;int main(){ int a = 123; char str[100]; itoa(a, str, 10); cout << str << e
1065 A+B and C (64bit) 溢出问题 Given three integersA,BandCin( -,), you are supposed to tell whetherA+B>C.Input Specification:The first line of the input gives the positive number of test cases, T (≤10). Then T test cases follow, each consists of a single line containing ...
1046 Shortest Distance 超时问题 The task is really simple: givenNexits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification:Each input file contains one test case. For each case, the first line conta...
1042 Shuffling Machine dssdsShuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many casinos