小编Hol*_*lon的帖子

三种颜色三角形

我正在尝试为此问题制作代码:

(来源:https://www.codewars.com/kata/insane-coloured-triangles/train/c)

彩色三角形由一排颜色创建,每一种颜色都是红色,绿色或蓝色.通过考虑前一行中的两种触摸颜色,生成连续的行,每行包含比最后一种颜色少的颜色.如果这些颜色相同,则在新行中使用相同的颜色.如果它们不同,则在新行中使用缺少的颜色.这将持续到最后一行,只生成一种颜色.

例如,不同的可能性是:

Colour here:            G G        B G        R G        B R 
Becomes colour here:     G          R          B          G 

With a bigger example:
   R R G B R G B B  
    R B R G B R B
     G G B R G G
      G R G B G
       B B R R
        B G R
         R B
          G
Run Code Online (Sandbox Code Playgroud)

您将获得三角形的第一行作为字符串,并且您的工作是返回最终颜色,该颜色将作为字符串显示在底行中.在上面的例子的情况下,你会被给予'RRGBRGBB',你应该返回'G'.

约束:

1 <= length(row) <= 10 ** 5
Run Code Online (Sandbox Code Playgroud)

输入字符串只包含大写字母' B', …

c math probability factorial

5
推荐指数
1
解决办法
1024
查看次数

计算一个段中的个数(二进制)

我现在正在解决一个问题,如下所示:

有两个数 x1 和 x2,且 x2 > x1。

例如 x1 = 5;x2 = 10;

我必须找到二进制表示中 x1 和 x2 之间的总和。

5 = 101   => 2 ones
6 = 110   => 2 ones
7 = 111   => 3 ones
8 = 1000  => 1 one
9 = 1001  => 2 ones
10= 1010  => 2 ones
so the sum will be 
sum = 2 + 2 + 3 + 1 + 2 + 2 = 12 ones;
Run Code Online (Sandbox Code Playgroud)

所以我成功地编写了一个代码,甚至没有将数字转换为二进制并浪费执行时间。

2^n我注意到每个with中的个数n >= …

c algorithm math binary

4
推荐指数
1
解决办法
2936
查看次数

如何从 Prometheus 中删除旧作业?

我有 2 份工作。一个是新的,另一个是旧的。

我需要删除旧的,以便它也从 Grafana 仪表板中删除。

grafana prometheus

3
推荐指数
1
解决办法
2万
查看次数

汇编中(进位标志)和系统调用之间的关系是什么(Mac Os 上的 x64 Intel 语法)?

我是新来的汇编语言,我必须做出的实现读取用汇编语言功能x64MAC。到目前为止,这就是我所做的:

;;;;;;ft_read.s;;;;;;

global _ft_read:
section .text
extern ___error

_ft_read:
    mov rax, 0x2000003 ; store syscall value of read on rax 
    syscall            ; call read and pass to it rdi , rsi, rdx  ==> rax read(rdi, rsi, rdx)
    cmp rax, 103       ; compare rax with 103 by subtracting 103 from rax ==> rax - 103
    jl _ft_read_error  ; if the result of cmp is less than 0 then jump to _ft_read_error
    ret                ; else return …
Run Code Online (Sandbox Code Playgroud)

c macos assembly errno system-calls

3
推荐指数
1
解决办法
388
查看次数

在linux上实现汇编64中的strcmp函数

我正在尝试实现strcmp,它是C程序集 64 中的一个函数,这是迄今为止我的工作代码:

global ft_strcmp

section .text

ft_strcmp:              ;rax ft_strcmp(rdi, rsi)
        mov     r12, 0  
loop:
        mov r13b, [rdi + r12]
        cmp byte [rdi + r12], 0
        jz exit
        cmp byte [rsi + r12], 0
        jz exit
        cmp r13b, byte [rsi + r12]
        jnz  exit
        inc r12
        jmp loop

exit:
        sub r13b, [rsi + r12]
        movsx rax, r13b
        ret 
Run Code Online (Sandbox Code Playgroud)

当我尝试用这个编译它时main.c

#include <stdio.h>
#include <string.h>

int     ft_strcmp(const char *str1, const char *str2);

int     main()
{
        const …
Run Code Online (Sandbox Code Playgroud)

c linux assembly nasm strcmp

2
推荐指数
1
解决办法
729
查看次数

如何在 alpine:latest image 中使用 rc-service 命令启动 Nginx 服务器

我正在尝试Nginx使用apline:latest图像创建自己的图像,在修复了很多错误之后,多亏了互联网,我设法做到了并且一切正常,但是问题是当我运行以下命令时:

rc-service nginx status
 * status: stopped
Run Code Online (Sandbox Code Playgroud)

当我尝试启动服务时,这就是它给我的内容,如下所示:

rc-service nginx start
 * WARNING: nginx is already starting
Run Code Online (Sandbox Code Playgroud)

即使服务停止,第二个命令的输出告诉它已经启动?!

于是我打开了我的docker-machine的localhost来验证服务是开启还是关闭,成功出现nginx html页面。

我尝试运行rc-service nginx reload,结果如下:

rc-service nginx reload
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/blkio/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpu/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpuacct/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpuset/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/devices/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: …
Run Code Online (Sandbox Code Playgroud)

service nginx docker dockerfile alpine-linux

0
推荐指数
2
解决办法
2024
查看次数