#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct IP { int a; int b; int c; int d; }IP; typedef struct S { int len; IP source; IP destination; int source_port; int destinstion_port; }S; int tran(char e) { if(e>='0'&&e<='9') return e-'0'; else if(e>='a'&&e<='z') return e-'a'+10; return 0; } int main() { int n,i; char str[500]; S Node; int x; scanf("%d",&n); gets(str); i=1; while(n--) { gets(str); x=4*tran(str[1]); Node.len=16*256*tran(str[6])+256*tran(str[7])+ 16*tran(str[9])+tran(str[10]); Node.source.a=tran(str[36])*16+tran(str[37]); Node.source.b=tran(str[39])*16+tran(str[40]); Node.source.c=tran(str[42])*16+tran(str[43]); Node.source.d=tran(str[45])*16+tran(str[46]); Node.destination.a=tran(str[48])*16+tran(str[49]); Node.destination.b=tran(str[51])*16+tran(str[52]); Node.destination.c=tran(str[54])*16+tran(str[55]); Node.destination.d=tran(str[57])*16+tran(str[58]); Node.source_port=4096*tran(str[3*x])+256*tran(str[3*x+1])+ 16*tran(str[3*x+3])+tran(str[3*x+4]); Node.destinstion_port=4096*tran(str[3*x+6])+256*tran(str[3*x+7])+ 16*tran(str[3*x+9])+tran(str[3*x+10]); printf("Case #%d ",i++); printf("Total length = %d bytes ",Node.len); printf("Source = %d.%d.%d.%d ",Node.source.a, Node.source.b,Node.source.c,Node.source.d); printf("Destination = %d.%d.%d.%d ",Node.destination.a, Node.destination.b,Node.destination.c,Node.destination.d); printf("Source Port = %d ",Node.source_port); printf("Destination Port = %d ",Node.destinstion_port); } return 0; }头一次在九度上看到这么不要脸的题目。颠覆了九度上题目的常规。一般都是可以测试多组数据,而我之前写的测试多组数据居然不能通过。这个一组测试就可以通过了!