当前位置: 首页 > wzjs >正文

网站公司好做吗制作手机的游戏

网站公司好做吗,制作手机的游戏,官方网站 优帮云,深圳网站开发怎么样时间限制:C/C 1000MS,其他语言 2000MS 内存限制:C/C 256MB,其他语言 512MB 难度:困难 数据解码 指定有一段经过编码的二进制数据,数据由0个或多个"编码单元"组成。"编码单元"的编码方式…
时间限制:C/C++ 1000MS,其他语言 2000MS
内存限制:C/C++ 256MB,其他语言 512MB
难度:困难

数据解码

指定有一段经过编码的二进制数据,数据由0个或多个"编码单元"组成。"编码单元"的编码方式存在如下两种:

1简单编码单元如下所示,其中:

  • TAG所占长度须为1字节,其值须为0xF0
  • SINGLE-VALUE的长度定为4字节

image.png

2.复杂编码单元如下所示,其中:

  • TAG所占长度须为1字节,其值须为0xF1
  • REPEAT所占长度固定为1字节,用于指示值在解码后消息中重复的次数
  • LEN所占长度固定为4字节,用于指示值的字节数,LEN使用大端序表示
  • 值部分必须由0个或多个"编码单元"组成,且长度必须为LEN字设所指示的字节数

image.png

编码后的数据必须完全符合上述两个原则,不允许有任何冗余的字节,请构造符合上述规则的10个编码:

请根据上述规则对一段编码后的数据进行校验,如果完全符合上述约束则输出解码后的长度,否则输出-1

输入描述

输入一行编码后的二进制数据,按字节16进制表示,如

F0 00 08 09 00

表示一串5字节的编码后数据

输入的字节数n,0<=n<=100000

输出描述

输出解码后的值的字节数,不符合约束返回-1

用例输入 1 

F1 02 00 00 00 05 F0 01 02 03 04

用例输出 1 

8

用例输入 2 

F1 01 00 00 00 04 F0 01 05

用例输出 2 

-1

提示

样例1解释:该码流存在一个复杂编码单元,其中包含一个简单编码单元(内容4字节),复杂编码单元的重复数为2,所以解码后的总长度为8字节

样例2解释:第一个编码单元为复杂编码单元,重复数为1,长度为6,其中的内容从第一个字节开始为一个简单编码单元,但简单编码单元后存在数据0303既不属于简单编码单元,也不属于复杂编码单元,为冗余数据,整体数据不合法,应输出-1

#include <iostream>
#include <vector>
#include <cstdint>using namespace std;// Helper function to parse a single encoding unit
pair<int, int> parseUnit(const vector<uint8_t>& data, int index) {if (index >= data.size()) {return {-1, -1}; // Invalid input}uint8_t tag = data[index];index++;if (tag == 0xF0) {// Simple encoding unit: 1 byte TAG + 4 bytes SINGLE-VALUEif (index + 4 > data.size()) {return {-1, -1}; // Not enough bytes for SIMPLE-VALUE}return {index + 4, 4}; // Move past the SIMPLE-VALUE and return decoded length} else if (tag == 0xF1) {// Complex encoding unit: 1 byte TAG + 1 byte REPEAT + 4 bytes LEN + LEN bytes contentif (index + 5 > data.size()) {return {-1, -1}; // Not enough bytes for REPEAT and LEN}uint8_t repeat = data[index];index++;// Read LEN (4 bytes, big-endian)uint32_t len = 0;for (int i = 0; i < 4; ++i) {len = (len << 8) | data[index++];}// Check if we have enough bytes for the contentif (index + len > data.size()) {return {-1, -1}; // Not enough bytes for the content}// Parse the content recursivelyint contentStart = index;int totalDecoded = 0;while (index < contentStart + len) {auto [newIndex, decodedLen] = parseUnit(data, index);if (newIndex == -1) {return {-1, -1}; // Invalid content}index = newIndex;totalDecoded += decodedLen;}// Ensure no extra bytes in the contentif (index != contentStart + len) {return {-1, -1}; // Extra bytes found}return {index, totalDecoded * repeat};} else {// Invalid TAGreturn {-1, -1};}
}// Main function to decode the length
int decodeLength(const vector<uint8_t>& data) {auto [index, decodedLen] = parseUnit(data, 0);// Ensure all bytes are consumedif (index == static_cast<int>(data.size())) {return decodedLen;} else {return -1; // Redundant bytes found}
}// Helper function to convert hex string to byte array
vector<uint8_t> hexToBytes(const string& hex) {vector<uint8_t> bytes;for (size_t i = 0; i < hex.length(); i += 2) {string byteString = hex.substr(i, 2);uint8_t byte = static_cast<uint8_t>(stoul(byteString, nullptr, 16));bytes.push_back(byte);}return bytes;
}int main() {string hexInput;getline(cin, hexInput);// Remove spaces from the inputstring cleanedInput;for (char c : hexInput) {if (c != ' ') {cleanedInput += c;}}// Convert hex string to byte arrayvector<uint8_t> data = hexToBytes(cleanedInput);// Decode the lengthint result = decodeLength(data);cout << result << endl;return 0;
}


文章转载自:

http://ayJLF6sR.LLqky.cn
http://iRzGv1Ju.LLqky.cn
http://momDsdAc.LLqky.cn
http://NpeSuIqj.LLqky.cn
http://95sduqGF.LLqky.cn
http://sW9XAySd.LLqky.cn
http://BqhrK1Qh.LLqky.cn
http://QWTLg0JL.LLqky.cn
http://cYeUFaR1.LLqky.cn
http://eXCRpsFK.LLqky.cn
http://7u5uqO60.LLqky.cn
http://3sN3uKmt.LLqky.cn
http://LDoB8kGP.LLqky.cn
http://7WBnWWBw.LLqky.cn
http://7i282XtT.LLqky.cn
http://Lxv9T1Kz.LLqky.cn
http://sdPEIKGj.LLqky.cn
http://FIJobeZF.LLqky.cn
http://KMzeKBKB.LLqky.cn
http://CLqAlJxO.LLqky.cn
http://iLOsoUhD.LLqky.cn
http://JX8SQJOA.LLqky.cn
http://GsCohM4r.LLqky.cn
http://4D51HxYY.LLqky.cn
http://VWIYvlF7.LLqky.cn
http://cLHSK5dT.LLqky.cn
http://5IGyasdS.LLqky.cn
http://YclsYYsa.LLqky.cn
http://cgr9pAZt.LLqky.cn
http://Yg5aOGtg.LLqky.cn
http://www.dtcms.com/wzjs/757965.html

相关文章:

  • 江西网站备案流程推广公司产品
  • 有哪些网站可以免费推广房产网络
  • 给网站做选题江安县规划和建设局网站
  • 网站商城制作开发公司更换物业公司的请示
  • 上海建筑网站建设电子商务网站建设策划书网站类型
  • 做彩票网站非法吗德州建设网站有
  • 凡客诚品网站特点上海的外贸网站建设公司
  • 做个模板网站多少钱怎样在手机安装wordpress
  • 做自媒体素材搬运网站专业做二手房装修网站
  • 个人在线视频播放网站搭建嵌入式软件开发培训机构
  • 做调查网站赚钱内容型网站的运营
  • 社交网站开发简约 个人网站
  • 郑州网站建设推广渠道wordpress表单设置
  • 创建网站选哪家好给做网站建设的一些建议
  • 做特卖网站有什么网站在招聘网站里做电话销售
  • 两学一做专题网站介绍建工网校论坛
  • 购物网站制作公司网站有死链接怎么办
  • 短网址还原网站怎样做个人网站
  • 南昌建设局网站查询塔吊证wordpress 去掉rss
  • 玖云建站系统python初学者怎么入门
  • 免费数据查询网站wordpress绑定多个域名的方法
  • 如何做淘宝客的网站汕头专业网页设计培训哪个好
  • 济南 网站建设公司 医疗什么网站做的号
  • 网站备案注销 万网现在还有什么推广渠道
  • 做营销型网站的公司秦皇岛城乡建设局网站
  • 做logo有哪些网站wordpress app 发布
  • 建各公司网站要多少钱网络公司给我做网站我有没有源代码版权吗
  • 国外网站都不能上怎么做跨境电商安徽芜湖网站建设
  • 海淀网站制作微信公众号申请
  • 杭州cms建站模板内账免费的财务软件