• ZOJ Problem Set


    题意:给定一个字符串,用字符串ASC2码16进制数输出 ,并在前面输出字符串长度的16进制,输出长度的规则是 先输出长度的二进制数的后七位的十六进制(如果左边还有1 则这在后七位前面加上个1再输出  然后二进制数右移动七位,直到左边没有1)   注:所有16数都必须为两位!

    解题思路:对长度进行输出处理

    解题代码:

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    char str[3000005];
    int bi[100];
    void print(int x)
    {
       if (x < 10)
           printf("0%d",x);
       else if(x < 16)
           printf("0%c",'A'+(x-10));
       else
       {
          if(x /16 <10)
              printf("%d",x/16);
          else if(x/16 < 16)
              printf("%c",'A'+(x/16-10));
          if(x%16 < 10)
              printf("%d",x%16);
          else
              printf("%c",'A'+(x%16-10));
    
       }
    
    }
    int main(){
    
       //freopen("/home/plac/problem/input.txt","r",stdin);
       //freopen("/home/plac/problem/output.txt","w",stdout);
       int t; 
       scanf("%d",&t);
       getchar();
       while(t--)
       {
          gets(str);
          int k = strlen(str);
          int b = 2097152,c = 16384 , d= 128;
         // scanf("%d",&k); 
          if(k >= b)
          {
            print(k%d+d);
            print(k%c/d+d);
            print(k%b/c+d);
            print(k/b);
          }
          else if(k >= c)
          {
             print(k%d+d);
             print(k%c/d+d);
             print(k/c);
          }
          else if(k >= d)
          {
            print(k%d +d);
            print(k/d);
          }
          else print(k);
          
          for(int i = 0 ;i < k ;i ++)
              if(str[i] < 16)
                  print(str[i]);
              else 
                  print(str[i]);
          printf("
    ");
          
       
       }
    return 0 ;
    }
  • 相关阅读:
    NOIP2018 模拟赛(二十二)雅礼NOI
    浅谈左偏树在OI中的应用
    HDU3062&&HDU1814
    2-SAT超入门讲解
    bitset常用用法&&简单题分析
    NOIp2014提高组初赛错题简析
    2018十月刷题列表
    BZOJ 4804: 欧拉心算
    Luogu P2568 GCD
    Luogu P4137 Rmq Problem / mex
  • 原文地址:https://www.cnblogs.com/Alandre/p/3619520.html
Copyright © 2020-2023  润新知