ZIP000000c++清理脚本0000000000 7.83MB

m0_73435982需要积分:9(1积分=1元)

资源文件列表:

main.zip 大约有3个文件
  1. main.exe 8.05MB
  2. main.py 876B
  3. build.py 9.59KB

资源介绍:

适合c++代码缩短大小
import re type_key = ["int","char","long","short","bool"] _key = ["if","else","const","typedef","swtch","for","while","do","and","or","xor"] mp = {} code = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_" u = 0 def fun(text): stack = [] c = re.compile("//.*") text = re.sub(c, "", text) run = 1 while run: run = 0 for i in range(0, len(text)): if text[i] == "/" and text[i + 1] == "*": stack.append(i) run = 1 elif text[i] == "*" and text[i + 1] == "/": text = text[: stack[-1]] + text[i + 2 :] stack.pop() run = 1 break run = 1 while run: run = 0 for old, new in [ ["\t", ""], [" ", " "], ["\r\n", "\n"], ["\n\n", "\n"], [";;", ";"], [") {", "){"], [")\n{", "){"], ["( )", "()"], ]: while old in text: text = text.replace(old, new) run = 1 for i in "\n;+-*/()&^%<>[]|=,{}!": text = text.replace(f" {i}", i) text = text.replace(f"{i} ", i) return text def _find(m): n = [[[it.group()], it.start(), it.end()] for it in m] cnt = 0 for i in range(1, len(n)): if n[cnt][2] == n[i][1]: n[cnt][0] += n[i][0] n[cnt][2] = n[i][2] else: n[(cnt := cnt + 1)] = n[i] return n[: cnt + 1] def meger1(text, flag): cin = re.compile(f"{flag}[^;]*;\n") m = re.finditer(cin, text) if not m: return text n = _find(m) for u, b, e in n[::-1]: for j in range(0, len(u) - 1): u[j] = u[j].replace(";\n", "") for j in range(1, len(u)): u[j] = u[j].replace(flag, "") con = "".join(u) text = text[:b] + con + text[e:] return text def meger2(text, flag): c = re.compile(f'{flag}[(]"[^"]*?",[^;]*?[)];\n') m = re.finditer(c, text) if not m: return text c = re.compile(f'{flag}[(]"(?P<greet>[^"]*?)",(?P<orz>[^;]*?)[)];\n') n = _find(m) for i, j, k in n[::-1]: u = [] for item in i: u.append(*re.findall(c, item)) greet = "".join([v[0] for v in u]) orz = ",".join([v[1] for v in u]) con = f'{flag}("{greet}",{orz});\n' text = text[:j] + con + text[k:] return text def meger3(text, flag): c = re.compile(rf"\b(?<![typedef|const] ){flag}[^\w]+\**[^\n]*;\n") m = re.finditer(c, text) if not m: return text n = _find(m) c = re.compile(rf"\b{flag} +\**([^\n;]*);\n") for u, b, e in n[::-1]: u = [j for i in u for j in re.findall(c, i)] for i in u: if i == "": continue for it in i.split(","): while it[0] == "*": it = it[1:] for i in range(0, len(it)): if it[i] == "[" or it[i] == "=": it = it[:i] break if it not in mp: mp[it] = 0 mp[it] += 1 u = ",".join(u) con = f"{flag} {u};\n" text = text[:b] + con + text[e:] return text def meger4(text): c = re.compile(r"\b[a-zA-Z0-9_]+=[^;]*;\n") m = re.finditer(c, text) c = re.compile(r"\b(?P<a>[a-zA-Z_0-9]+)=(?P<b>[^;]*);\n") if not m: return text n = _find(m) m = [] for i, j, k in n: u = [re.findall(c, it) for it in i] u = [j for i in u for j in i] for i in range(len(u) - 1): if u[i][0] == u[i + 1][0]: u[i] = 0 u = [list(it) for it in u if it] for i in range(len(u) - 1): if u[i + 1][1] == u[i][1]: u[i][1] = u[i + 1][0] elif u[i + 1][1] == u[i][0]: tmp = u[i][1] u[i][1] = u[i + 1][0] u[i + 1][1] = tmp m.append([[[]], j, k]) for i in range(len(u)): m[-1][0][-1].append(u[i][0]) m[-1][0][-1].append(u[i][1]) if i + 1 < len(u): if u[i][1] != u[i + 1][0]: m[-1][0].append([]) for i, j, k in m[::-1]: v = [] for orz in i: cnt = 0 for p in range(len(orz)): if orz[cnt] != orz[p]: orz[(cnt := cnt + 1)] = orz[p] v.append("=".join(orz[: cnt + 1])) v = [f"{i};\n" for i in v] v = "".join(v) text = text[:j] + v + text[k:] return text def merge5(text): pattern = re.compile(r"(\w+)=\1(\+|\-|\*|\/|%|&|\||\^)\s*(\w+);") new_text = re.sub(pattern, r"\1 \2= \3;", text) return new_text def number(x): if x // 53: return number(x // 53) + code[x % 53] return code[x % 53] def replace1(text): global u cnt = [i for i in mp] cnt = sorted(cnt, key=lambda x: len(x) * mp[x], reverse=True) ids = [] for i in cnt: key = number(u) u += 1 for j in re.finditer(rf"\b{i}\b", text): ids.append([key, j.start(), j.end()]) ids = sorted(ids, key=lambda x: -x[1]) for i, j, k in ids: text = text[:j] + i + text[k:] return text def replace2(text): global u c = re.compile("\d*") m = re.finditer(c,text) cnt = [j.group() for j in m] cnt = {j: cnt.count(j) for j in cnt} tot = 1 for i in cnt: key = number(u) u += 1 cod = f"#define {key} {i}\n" p =len(cod) + len(key) * cnt[i] q = len(i)*cnt[i] if p> q: u -= 1 else: text = text.replace(i, key) endl = [i for i in range(len(text)) if text[i] == "\n"] idx = endl[tot] tot += 1 text = text[: idx + 1] + cod + text[idx + 1 :] return text def replace3(text): if "#define rep" in text: return text c = re.compile( r"for\(int (?P<i>\w+)\=(?P<a>[^;]*);(?P=i)<\=(?P<b>[^;]*);(?P=i)\+\+\)" ) m = re.findall(c, text) if not m: return text n = [] idx = 0 for i, a, b in m: cod = f"for(int {i}={a};{i}<={b};{i}++)" idx = text.find(cod, idx) n.append([i, a, b, cod, idx]) idx += 1 sl = sum([len(i) for i in n]) codeing = "#define rep(i,a,b) for(int i=a;i<=b;i++)\n" sv = sum([len(f"rep({i},{a},{b})") for i, a, b in m]) if sl < len(codeing) + sv: for i, a, b, cod, idx in n[::-1]: code = f"rep({i},{a},{b})" text = text[:idx] + code + text[idx + len(cod) :] b = [i for i in range(len(text)) if text[i] == "\n"] text = text[: b[1] + 1] + codeing + text[b[1] + 1 :] return text def replace4(text): if "#define lep" in text: return text c = re.compile( r"for\(int (?P<i>\w+)\=(?P<a>[^;]*);(?P=i)>\=(?P<b>[^;]*);(?P=i)\-\-\)" ) m = re.findall(c, text) if not m: return text n = [] idx = 0 for i, a, b in m: cod = f"for(int {i}={a};{i}>={b};{i}--)" idx = text.find(cod, idx) n.append([i, a, b, cod, idx]) idx += 1 sl = sum([len(cod) for _, _, _, cod, _ in n]) codeing = "#define lep(i,a,b) for(int i=a;i>=b;i--)\n" sv = sum([len(f"lep({i},{a},{b})") for i, a, b in m]) if sl > len(code) + sv: for i, a, b, cod, idx in n[::-1]: code = f"lep({i},{a},{b})" text = text[:idx] + code + text[idx + len(cod) :] b = [i for i in range(len(text)) if text[i] == "\n"] text = text[: b[1] + 1] + codeing + text[b[1] + 1 :] return text def replac
100+评论
captcha
    类型标题大小时间
    ZIP基于深度强化学习的dqn和基准p-learning的边缘计算计算卸载方法总结4.9KB9月前
    ZIPlaunch4j安装包,3.50版本,window9.85MB9月前
    ZIPC盘优化清理降低磁盘空间不足工具2.21MB9月前
    ZIPExcel 和 Zip 的导出 & 上传13.5KB9月前
    ZIP武汉理工大学 实训基于verilog的倒计时1.51MB9月前
    ZIPRancher启动hadoop镜像的必要静态文件10.24MB9月前
    ZIPpython安装包-python程序必备81.29MB9月前
    ZIPNavicat连接oracle77.55MB9月前