北邮2012年复试上机题目
前言每次让我看到北邮的上机题目不管当时多忙我都必须把它们ac,原因是当年北邮复试,上机题目竟然一道也没有做出来,旁边一同学还抱怨和我坐一起连个讨论的人都没有!唉,往事不堪回首,这里记录一下2012年北邮上机的题目吧,每年复试前才会放出上一年的上机题目
二进制数题目
#include <stdio.h>#include <stdlib.h>#include <string.h> #define LEN 1000 int change_tint(char *str, int begin, int num){ int i; char *temp = (char *)malloc(sizeof(char) * (num + 1)); for(i = 0; i < num; i ++) { temp[i] = str[begin + i]; } temp[i] = '\0'; return strtol(temp, NULL, 16);} void ip_field(char *str, int begin, int num){ int i, flag, ip; for (i = 0, flag = 1; i < num; i += 2) { ip = change_tint(str, begin + i, 2); printf("%d", ip); if (flag <= 3) { printf("."); flag ++; } } printf("\n");} int main(){ int index, i, j, n, length, ihl; char ipstr[LEN], temp[LEN]; while (scanf("%d\n", &n) != EOF) { if (n != 0) { for (index = 1; index <= n; index ++) { memset(ipstr, 0, sizeof(ipstr)); memset(temp, 0, sizeof(temp)); gets(temp); // 去除空格 for (i = j = 0, length = strlen(temp); i < length; i ++) { if (temp[i] != ' ') { ipstr[j ++] = temp[i]; } } ipstr[j] = '\0'; // 当前测试数据的序号 printf("Case #%d\n", index); // 整个ip数据包的长度 length = change_tint(ipstr, 4, 4); printf("Total length = %d bytes\n", length); // 源ip地址和目的ip地址 printf("Source = "); ip_field(ipstr, 24, 8); printf("Destination = "); ip_field(ipstr, 32, 8); // 源端口号和目的端口号 ihl = change_tint(ipstr, 1, 1) * 4 * 2; printf("Source Port = %d\n", change_tint(ipstr, ihl, 4)); printf("Destination Port = %d\n", change_tint(ipstr, ihl + 4, 4)); printf("\n"); } } } return 0;} /************************************************************** Problem: 1475 User: wangzhengyi Language: C Result: Accepted Time:10 ms Memory:908 kb****************************************************************/
后记2011年北邮复试一道上机题都不会做的我,现在两年后确实秒杀北邮的这些复试上机题,总共加调试差不多花了一个半小时,不过2012年北邮计算机院复试题目确实没神马难度!