zoukankan      html  css  js  c++  java
  • 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
    ",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;
    }
    头一次在九度上看到这么不要脸的题目。颠覆了九度上题目的常规。一般都是可以测试多组数据,而我之前写的测试多组数据居然不能通过。这个一组测试就可以通过了!
  • 相关阅读:
    复合文档(Compound Document)读写栗子
    JavaScript修改IE注册表
    mysql_real_connect 端口号说明
    _beginthreadex创建线程,立即执行?
    Access 是/否 字段
    JavaScript格式化日期输出
    STM32-串行SPI nor
    全球唯一标识符:GUID在线生成
    如何交叉编译Python到ARM-Linux平台(转)
    CMOS Sensor的调试经验分享(转)
  • 原文地址:https://www.cnblogs.com/abc-24990/p/4257464.html
Copyright © 2011-2022 走看看