我有一个大文本文件,其中包含嵌入句子中的概率.我想只提取那些概率和它们之前的文本.例
输入:
not interesting
foo is 1 in 1,200 and test is 1 in 3.4 not interesting
something else is 1 in 2.5, things are 1 in 10
also not interesting
Run Code Online (Sandbox Code Playgroud)
通缉输出:
foo is 1/1,200
and test is 1/3.4
something else is 1/2.5,
things are 1/10
Run Code Online (Sandbox Code Playgroud)
到目前为止我所拥有的:
$ sed -nr ':a s|(.*) 1 in ([0-9.,]+)|\1 1/\2\n|;tx;by; :x h;ba; :y g;/^$/d; p' input
foo is 1/1,200
and test is 1/3.4
not interesting
something else is 1/2.5,
things are 1/10
something else …Run Code Online (Sandbox Code Playgroud) 我有一个Vec3课程.更换循环的最佳方法是什么?
for (int x = 20; x < 25; x++)
for (int y = 40; y < 45; y++)
for (int z = 2; z < 4; z++) doStuff({x,y,z});
Run Code Online (Sandbox Code Playgroud)
用这样的东西:
for(Vec3 v: Vec3range({20,40,2}, {25,45,4}))
doStuff(v);
Run Code Online (Sandbox Code Playgroud)
没有任何运行时成本?
我正在尝试从 C++ 运行 libtcc 以使用 C 作为运行时脚本语言。运行时编译的代码必须能够运行外部代码中的函数。当传递整数时,这工作得很好,但是当将结构从 tcc 代码传递到 gcc 代码时,会发生奇怪的事情。
最小运行示例:
#include <libtcc.h>
#include <stdio.h>
struct Vec {
int x;
};
void tmp(struct Vec test) {
printf("got %x\n",test.x);
}
int main() {
TCCState* tcc; tcc = tcc_new();
tcc_set_output_type(tcc, TCC_OUTPUT_MEMORY);
tcc_add_symbol(tcc, "tmp", (void*)&tmp);
tcc_compile_string(tcc, "\
struct Vec {int x;};\
void tmp(struct Vec test);\
void fun() {\
struct Vec x = {0};\
tmp(x);\
}");
tcc_relocate(tcc, TCC_RELOCATE_AUTO);
void (*fun)(void) = (void(*)())tcc_get_symbol(tcc, "fun");
fun();
}
Run Code Online (Sandbox Code Playgroud)
运行:
gcc -ltcc -ldl test.c && ./a.out
> …Run Code Online (Sandbox Code Playgroud)