首页 > 编程语言 >通过码流串,格式为key,len,val。提供key,查找val的算法。

通过码流串,格式为key,len,val。提供key,查找val的算法。

时间:2024-10-01 14:50:26浏览次数:3  
标签:return String val len length tag key null public

import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;

public class HuaweiTest {

    public static void main(String[] args) {
//        System.out.println("Hello World!");
        String tag = "31";
        String codeStreamStr = "31 01 32";
        String codeStringVal = getCodeStringVal(tag, codeStreamStr);
        System.out.println(codeStringVal);
    }


    public static String getCodeStringVal(String tag, String codeStreamStr) {
        String trim = tag.trim();
        if (trim == null) {
            return null;
        }
        if (trim.isEmpty()) {
            return null;
        }
        if ((codeStreamStr.length() * 4) > 50000) {
            return null;
        }
        String trim1 = codeStreamStr.trim();
        if (trim1 == null) {
            return null;
        }
        if (trim1.isEmpty()) {
            return null;
        }
        String[] split = trim1.split("\\s");
        if (!(split.length % 3 == 0)) {
            return null;
        }
        for (int i = 0; i < split.length; i++) {
            String s = split[i];
            if (s.length() > 2) {
                return null;
            }
            String trim2 = s.trim();
            for (int j = 0; j < trim2.length(); j++) {
                char c = trim2.charAt(j);
                if (Character.isDigit(c)) {
                    continue;
                } else {
                    if (Character.isLowerCase(c)) {
                        return null;
                    }
                    if (!(c >= 'A' && c <= 'F')) {
                        return null;
                    }
                }
            }
        }
        String[] split2 = codeStreamStr.split("\\s");
        HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
        for (int i = 0; i < split2.length; i++) {
            String s = split2[i];
            String trim2 = s.trim();
            if (stringIntegerHashMap.containsKey(trim2)) {
                stringIntegerHashMap.put(trim2, stringIntegerHashMap.get(trim2) + 1);
            } else {
                stringIntegerHashMap.put(trim2, 1);
            }
        }
        System.out.println(stringIntegerHashMap);
        ArrayList<CodeStream> codeStreamArrayList = new ArrayList<>();
        String[] split1 = codeStreamStr.split("\\s");
        int count = 0;
        int codeTagIndex = 0;
        for (int i = 0; i < split1.length; i++) {
            if ((count + 1) % 3 == 0) {
                continue;
            } else {
                CodeStream codeStream = new CodeStream();
                codeStream.setId(UUID.randomUUID().toString());
                String s = split1[codeTagIndex];
                if (extracted(s, stringIntegerHashMap)) return null;
                codeStream.setTag(s);
                String s1 = getString(split1, codeTagIndex);
                if (s1 == null) return null;
                codeStream.setLength(Integer.valueOf(s1));
                String s2 = split1[codeTagIndex + 2];
                codeStream.setValue(s2);
                codeStreamArrayList.add(codeStream);
                count += 3;
                codeTagIndex = count;
            }
        }
        System.out.println(codeStreamArrayList);
        ArrayList<String> stringArrayList = new ArrayList<>();
        codeStreamArrayList.forEach(e -> {
            String tag1 = e.getTag();
            if (tag.equals(tag1)) {
                String value = e.getValue();
                stringArrayList.add(value);
            }
        });
        System.out.println(stringArrayList);
        StringBuilder stringBuilder = new StringBuilder();
        stringArrayList.forEach(e -> {
            stringBuilder.append(e);
            stringBuilder.append("\\s");
        });
        return stringBuilder.toString();
    }

    private static String getString(String[] split1, int codeTagIndex) {
        String s1 = split1[codeTagIndex + 1];
        byte[] bytes1 = s1.getBytes();
//        if (bytes1.length>2){
//            return null;
//        }
        return s1;
    }

    private static boolean extracted(String s, HashMap<String, Integer> stringIntegerHashMap) {
        byte[] bytes = s.getBytes();
        int length = bytes.length;
//        if (length>1){
//            return true;
//        }
        if (stringIntegerHashMap.containsKey(s)) {
            if (stringIntegerHashMap.get(s) >= 2) {
                return true;
            }
        }
        return false;
    }
}

class CodeStream {
    private String id;
    private String tag;
    private Integer length;
    private String value;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return "CodeStream{" +
                "id='" + id + '\'' +
                ", tag='" + tag + '\'' +
                ", length=" + length +
                ", value='" + value + '\'' +
                '}';
    }
}

标签:return,String,val,len,length,tag,key,null,public
From: https://blog.csdn.net/competes/article/details/142670992

相关文章

  • 论文解读《MASTERKEY: Automated Jailbreaking of Large Language Model Chatbots》
    导言​ 在参加东南大学网络安全学院夏令营的契机下,我第一次接触大模型安全领域。L老师是网络安全领域的一位大牛,在和L老师交流期间,被告知需要准备一次paperpresentation介绍四大会中感兴趣的一篇文章,我选择了汇报这篇来自NDSS2024的《MASTERKEY:AutomatedJailbreakingofLarg......
  • php的urlencode和rawurlencode区别
    urlencode和rawurlencode都是用于对URL进行编码的函数,但它们在处理方式和应用场景上存在明显的区别。以下是关于这两个函数的详细比较:一、定义与标准urlencode:基于rawurlencode标准,但有略微的不同,它定义在rfc1866,这个rfc属于html标准的一部分,编码方式和application/x-www-for......
  • [FlareOn3]Challenge11
    载入PE.32bit,无壳.载入IDA(32bit).寻找main函数.int__cdeclmain(intargc,constchar**argv,constchar**envp){charBuffer[128];//[esp+0h][ebp-94h]BYREFchar*Str1;//[esp+80h][ebp-14h]char*Str2;//[esp+84h][ebp-10h]HANDLEStdHandl......
  • selenium过webdriver检测
    js/*!*Note:Auto-generated,donotupdatemanually.*Generatedby:https://github.com/berstend/puppeteer-extra/tree/master/packages/extract-stealth-evasions*Generatedon:Sun,13Feb202212:56:05GMT*License:MIT*/(({_utilsFns:_utilsFns......
  • Selenium+WebDriver 各浏览器驱动下载与使用
    Selenium+Python之WebDriver驱动下载与使用一、Firefox(火狐)浏览器驱动下载地址:https://github.com/mozilla/geckodriver/releases/下载对应驱动:根据自己的操作系统下载相对应的驱动。使用方法:把文件存放在python根目录下,例如:C:\xxx\Python\Python38下。(安装最新版......
  • WPF Calendar DisplayMode SelectionMode FirstDayOfWeek Start End BlackoutDates
    //xaml<Windowx:Class="WpfApp427.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • sizeof vs strlen - 关于代码可读性、性能考量和编译器优化
    1、起因经常在咱们代码里面见到sizeof(“HEADER”)这类代码来计算常量字符串的长度,例如上次的一个代码review:之所以这么写可能基于以下几点考虑:(1)sizeof()是运算符而不是函数调用,编译时确定而不是运行时执行,因此不占用运行时时间(2)strlen()是GLIBC标准库函数,运行时需要进行......
  • Interval GCD(单点修改线段树)
    细节不少//根据更相减损法gcd(x,y)=gcd(x,y-x)//推广到三项为gcd(x,y,z)=gcd(x,y-x,z-y)//可以推广到n项#include<bits/stdc++.h>usingnamespacestd;#definexfirst#defineysecondtypedefpair<int,int>PII;typedeflonglongll;typedefunsignedlonglong......
  • @Validated和@Valid简单使用
    当使用apifox时,我们需要必传字段做标记,可以使用@NotEmpty(message="id不能为空")同时在入参位置添加@Valid@RequestBody其中@Valid起到关键作用效果图 同时在apifox中 这样测试或者前端去测试接口的时候就知道哪些字段一定要传,哪些是非必要的@NotEmpty引入jar包impor......
  • 基于卷积神经网络的宠物皮肤病识别系统,resnet50,mobilenet模型【pytorch框架+python】
       更多目标检测和图像分类识别项目可看我主页其他文章功能演示:基于卷积神经网络的宠物皮肤病识别系统,resnet50,mobilenet【pytorch框架,python,tkinter】_哔哩哔哩_bilibili(一)简介基于卷积神经网络的宠物皮肤病识别系统是在pytorch框架下实现的,这是一个完整的项目,包括代码......