ZOJ Problem Set - 3713

简介:

题意:给定一个字符串,用字符串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("\n");
      
   
   }
return 0 ;
}

相关文章
ZOJ - Problem Set - 3960 What Kind of Friends Are You?
ZOJ - Problem Set - 3960 What Kind of Friends Are You?
88 0
ZOJ - Problem Set - 3960 What Kind of Friends Are You?
ZOJ - Problem Set - 3985 String of CCPC
ZOJ - Problem Set - 3985 String of CCPC
102 0
ZOJ Problem Set - 3758 素数
ZOJ Problem Set - 3758 素数
102 0
|
机器学习/深度学习 人工智能 BI
ZOJ Problem Set - 3758 素数
Singles’ Day Time Limit: 2 Seconds Memory Limit: 65536 KB Singles’ Day(or One’s Day), an unofficial holiday in China, is a pop cu...
928 0
|
存储 算法 索引
ZOJ 3505. Yet Another Set of Numbers 解题报告
    ZOJ 3505:Yet Another Set of Numbers     地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3505       题意:有一个数字集合,集合中的数遵循以下规则:       ( 1 ).
928 0