online_judge_1475改

#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\n",i++);
            printf("Total length = %d bytes\n",Node.len);
            printf("Source = %d.%d.%d.%d\n",Node.source.a,\
                   Node.source.b,Node.source.c,Node.source.d);
            printf("Destination = %d.%d.%d.%d\n",Node.destination.a,\
                   Node.destination.b,Node.destination.c,Node.destination.d);
            printf("Source Port = %d\n",Node.source_port);
            printf("Destination Port = %d\n\n",Node.destinstion_port);
    }
    return 0;
}
头一次在九度上看到这么不要脸的题目。颠覆了九度上题目的常规。一般都是可以测试多组数据,而我之前写的测试多组数据居然不能通过。这个一组测试就可以通过了!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值