小编tek*_*agi的帖子

python - >数字和字母的组合

#!/usr/bin/python
import random
lower_a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
upper_a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

all = []
all = " ".join("".join(lower_a) + "".join(upper_a) …

python arrays string random choice

0
推荐指数
1
解决办法
8126
查看次数

在Perl中返回数组

我正在研究Perl中的递归文件查找功能,它应该返回一个文件名数组.但是,当我尝试打印它们时,会发生什么0.我究竟做错了什么?

use strict;
use File::Basename;
use constant debug => 0;

sub isdir {
    return (-d $_[0]);
}

sub isfile {
    return (-f $_[0]);
}

my $level = 0;

#my @fns = ();

sub getfn {
    my @fns = ();
    my($file, $path) = @_;
    my (undef, undef, $ext) = fileparse($file, qr"\.[^.]+$");
    $level++;
    print "-->>getfn($level): $file : $path\n" if debug;
    print "arg:\t$file\t$path ($ext)\n" if debug;
    if ($ext eq ".bragi") {
        open my $FILE, "<", "$path/$file" or die "Failed to open …
Run Code Online (Sandbox Code Playgroud)

arrays perl return function subroutine

0
推荐指数
1
解决办法
248
查看次数

C - > sizeof string总是8

#include "usefunc.h" //don't worry about this -> lib I wrote
int main()
{
  int i;
  string given[4000], longest = "a"; //declared new typdef. equivalent to 2D char array
  given[0] = "a";
  printf("Please enter words separated by RETs...\n");
  for (i = 1; i < 4000 && !StringEqual(given[i-1], "end"); i++)
    {
      given[i] = GetLine();
      /*
      if (sizeof(given[i]) > sizeof(longest))
    {
      longest = given[i];
    }
      */
      printf("%lu\n", sizeof(given[i])); //this ALWAYS RETURNS EIGHT!!!
    }
  printf("%s", longest);
}
Run Code Online (Sandbox Code Playgroud)

它为什么总是返回8 ???

c string sizeof string-literals

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

C的生活游戏

我以为我会在康威的生命游戏中崭露头角,但我正在努力奋斗......这真是一个惊喜!有人可能暗示算法问题吗?只是一点点轻推?这不是功课.

#include <stdio.h>
#include <stdlib.h>

#define HEIGHT 10
#define WIDTH 10

int *gb[HEIGHT];
int *gb2[HEIGHT];

void copy() {
  int i, j;
  for (i = j = 0; i < HEIGHT; i++) {
    for (; j < WIDTH; j++) {
      gb2[i][j] = gb[i][j];
    }
  }
}

void init() {
  int i, j;
  for (i = 0; i < HEIGHT; i++) {
    gb [i] = malloc(sizeof(int)*WIDTH);
    gb2[i] = malloc(sizeof(int)*WIDTH);
  }
  for (i = j = 0; i < HEIGHT; i++) {
    for …
Run Code Online (Sandbox Code Playgroud)

c algorithm cell conways-game-of-life

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