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 ;
}
时间: 2024-11-17 19:01:57

ZOJ Problem Set - 3713的相关文章

ZOJ Problem Set - 3706

#include <cstdio> #include <cstdlib> #include <cstring> #include <set> #include <iostream> #include <algorithm> using namespace std; set<int> ST; int find(int a, int b, int c) { ST.clear(); ST.insert(0); ST.insert

ZOJ Problem Set - 3708 Density of Power Network

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include <stdio.h> #include <string.h> int main(int argc, char *argv[]) {     int T,i,j,lineSum;     int N,M;         int x[505],y[505];  

ZOJ Problem Set - 2397 Tian Ji -- The Horse Racing

#include<iostream> #include<cmath> #include<algorithm> #define REP(i,n) for(int i=0;i<(n);i++) using namespace std; int a[2000],b[2000],n; int main(){ while (cin>>n,n){ REP(i,n)cin>>a[i]; REP(i,n)cin>>b[i]; sort(a,a+

ZOJ Problem Set - 1730 Crazy Tea Party

#include<cstdio> int main(){ int T,n; scanf("%d",&T); while(T--){ scanf("%d",&n); printf("%d\n",n/2*(n/2-1)/2+(n-n/2)*(n-n/2-1)/2); } return 0; }

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 culture entertaining holiday on November 11 for young Chinese to celebrate their bachelor life. With the meaning of single

UVa 10038 / POJ 2575 / ZOJ 1879 Jolly Jumpers (water ver.)

10038 - Jolly Jumpers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=979 http://poj.org/problem?id=2575 http://acm.zju.edu.cn/onlinejudge/showProblem.do?

算法:zoj 3201 Tree of Tree(树形背包dp)

题意 给一棵节点带权的树,找到一个有k个节点的子树,求这个子树的最大权值 思路 树形 dp+背包. f(i, j) 表示以i为根节点的有j个节点子树的最大权值 然后对i的每个子节点做分组背包, 因为对于i的每个儿子,可以选择分配 1,2,3...j-1个节点给它 f(i, j) = max{ max{f(i, j-p) + f(v, p) | 1<=p<j} | v是i的儿子节点} ans = max{ f[i][k] | 0<=i<n && i 子树节点个数>

UVa 575 / ZOJ 1712 / Mid-Central USA 1997 Skew Binary

UVa 575 / ZOJ 1712 / Mid-Central USA 1997 Skew Binary (water ver.&斜二进制) 575 - Skew Binary Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=516 http://

ZOJ 1096. Subway 和 ZOJ 1086. Octal Fractions

(一)ZOJ 1096:Subway   链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1096 题意:给出下列参数(所有参数均为小于等于1000的正整数),求地铁列车从一个站点到下一个站点之间的最短时间(精确到 0.1 秒).   d - 地铁站之间的距离(米); m - 列车的最大速度(米 / 秒); a1 - 最大加速度(绝对值)(米 / 秒^2); j1 - 最大 jerk (绝对值)(米 / 秒^3).