小编ram*_*rur的帖子

尽可能以最快的方式生成所有n位二进制数

如何生成所有可能的n位字符串组合?我需要以最快的方式生成20位字符串的所有组合.(我目前的实现是通过按位AND和右移操作完成的,但我正在寻找更快的技术).

我需要将位串存储在数组(或列表)中以获得相应的十进制数,例如 -

0 --> 0 0 0

1 --> 0 0 1

2 --> 0 1 0 ...等

任何的想法?

algorithm bitstring

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

如何将bash变量重定向到可执行文件?

我有一个可执行文件,说它被称为a.out.提示后需要两行输入 -

> ./a.out 
> give me input-1: 0 0 10
> give me input-2: 10 10 5
> this is the output: 20 20 20
Run Code Online (Sandbox Code Playgroud)

我可以将输入存储在一个文件(input.txt)中并将其重定向到a.out,文件看起来像这样 -

0 0 10
10 10 5
Run Code Online (Sandbox Code Playgroud)

我可以a.out像 -

> ./a.out < input.txt
> give me input-1: 0 0 10 give me input-2: 10 10 5
> this is the output: 20 20 20
Run Code Online (Sandbox Code Playgroud)

现在我想在该文件中存储多个输入并重定向到a.out.该文件看起来像2个输入 -

0 0 10
10 10 5
0 0 20 …
Run Code Online (Sandbox Code Playgroud)

bash redirect

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

c ++ 11使用std :: fill来填充2D动态分配的数组

沿着这条线的讨论可以在这个问题中找到,也可以在这里找到,但我的情况略有不同,因为我正在处理一个动态分配的内存.

还请注意,memset并不是很有double价值.

无论如何,我试图用来std::fill填充动态分配的2D数组 -

#include <iostream>
#include <algorithm>

using std::cout ; using std::endl ;
using std::fill ;

int main()
{
    double **data ;
    int row = 10, col = 10 ;
    data = new double*[row] ;
    for(int i = 0 ; i < col ; i++)
        data[i] = new double[col];

    // fill(&(data[0][0]), 
    //      &(data[0][0]) + (row * col * sizeof(double)), 1); // approach 1
    // fill(&(data[0][0]), &(data[0][0]) + (row * …
Run Code Online (Sandbox Code Playgroud)

c++ arrays dynamic-memory-allocation c++11

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

为什么"我没有这样的文件或目录"出现在我的环境变量中?

我使用标准方式为我的系统设置了环境变量(即在〜/ .bashrc中设置它们).一切都编译并正常工作,但当我尝试查看$ CLASSPATH变量时,变量字符串末尾会显示"No such file or directory"消息,如下所示 -

user@user-pc:/media/Data$ $CLASSPATH [press enter]
bash: .:/opt/jdk1.7.0_03/lib/tools.jar:/opt/jdk1.7.0_03/lib/dt.jar:/usr/local/lib/JMF-2.1.1e/lib/jmf.jar:/usr/local/lib/jfreechart-1.0.13/lib/jfreechart-1.0.13.jar:/usr/local/lib/jfreechart-1.0.13/lib/jcommon-1.0.16.jar: No such file or directory
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?所有的jar位置都是正确的,没有遗漏/拼写错误,我做了双重检查.

编辑注意:我这样设置它们 -

JAVA_HOME=/opt/jdk1.7.0_03;export JAVA_HOME
JMFHOME=/usr/local/lib/JMF-2.1.1e;export JMFHOME
JFRC_HOME=/usr/local/lib/jfreechart-1.0.13;export JFRC_HOME
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
:$JMFHOME/lib/jmf.jar:$JFRC_HOME/lib/jfreechart-1.0.13.jar
:$JFRC_HOME/lib/jcommon- 1.0.16.jar;export CLASSPATH
Run Code Online (Sandbox Code Playgroud)

我正在使用Ubuntu 10.04,请忽略上面的所有"新行",它们归功于SO的降价编辑器.

bash classpath environment-variables

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

makefile编译所有文件而不是最后编辑的文件

请注意,在SO上有类似的问题,但我认为我的情况不同,而且我的Makefile非常简单直接.我是Makefile的新手.

假设我需要编译一个看起来像这样的项目 -

.
??? [4.0K]  bin
??? [ 517]  Makefile
??? [4.0K]  obj
??? [4.0K]  src
    ??? [ 117]  func1.cpp
    ??? [  76]  func2.cpp
    ??? [ 137]  global.h
    ??? [  97]  main1.cpp
Run Code Online (Sandbox Code Playgroud)

我的Makefile看起来像这样 -

CC          := g++
CFLAGS      := -g -Wall -std=c++0x
LDFLAGS     := -lm

NAMES   := func1.cpp func2.cpp main1.cpp
SRC     := $(addprefix src/,$(NAMES))
OBJ     := $(addprefix obj/,$(NAMES:.cpp=.o))
DEPS    := $(OBJ:.o=.d)

.PHONY: clean all debug

all: prog

debug:
    $(info $$SRC: ${SRC})
    $(info $$OBJ: ${OBJ})
    $(info $$DEPS: ${DEPS})

prog: bin/prog …
Run Code Online (Sandbox Code Playgroud)

c++ makefile

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

使C程序写入标准输出,即使它需要输出文件名

我有一个C程序,它接受输出文件名并将数据转储到其中.很可能该程序使用FILE*指针.是否可以将终端stdout传递给该C程序?我无权访问该代码.

我的意思是,该计划的工作原理如下 -

> ./program out.txt # --> dumps data into out.txt
Run Code Online (Sandbox Code Playgroud)

我想做的是像 -

> ./program &1 # --> dumps data on the terminal.
Run Code Online (Sandbox Code Playgroud)

可能吗?怎么做到呢?

c file-descriptor

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

c ++重载operator(),用于在动态2D数组中分配值

我正在尝试使用overload()运算符将值分配给动态分配的2D数组,这是我的代码 -

class test {
    private:
        int** data ; int row, col ;

    public:
        test(int row = 2, int col = 2)  {
            this->row = row ; this->col = col ;
            this->data = new int*[this->row] ;
            for(int i = 0 ; i < this->row ; i++)
                this->data[i] = new int[this->col] ;
        }

        ~test() {
            for(int i = 0 ; i < this->row ; i++)
                delete [] this->data[i] ;
            delete [] this->data ;
        }

        const int operator() (int row, int col) …
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading dynamic-memory-allocation c++11

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

c ++使用赋值运算符模拟类型转换

这是我的班级 -

class stuff
{
    private:
        char s_val = 'x';
        char e_val = 'y';
    public:
        stuff() {;}

        stuff(const string &s) {
            this->s_val = s[0];
            this->e_val = s[s.length() - 1];
        }

        stuff(const stuff &other) {
            this->s_val = other.s_val ;
            this->e_val = other.e_val ;
        }

        stuff& operator=(const stuff &other)
        {
            this->s_val = other.s_val;
            this->e_val = other.e_val;
            return *this;
        }

        stuff& operator=(const string &s)
        {
            *this = stuff(s);
            return *this ;
        }

        stuff& operator=(const char *c)
        {
            string s(c);
            *this = stuff(s);
            return …
Run Code Online (Sandbox Code Playgroud)

c++ constructor operator-overloading c++11

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

java:深度复制列表列表的最佳方法

我正在尝试编写一个程序来执行 的深拷贝List<List<Integer>>,我正在这样做:

public static List<List<Integer>> clone(final List<List<Integer>> src)
{
    List<List<Integer>> dest = new ArrayList<List<Integer>>();
    for( List<Integer> sublist : src) {
        List<Integer> temp = new ArrayList<Integer>();
        for(Integer val: sublist) {
            temp.add(val);
        }
        dest.add(temp);
    }
    return dest ;
} 
Run Code Online (Sandbox Code Playgroud)

这是一个好方法吗?是否有可能摆脱内循环?事实上,每个内部子列表都可以增长到很大的长度。

java clone list arraylist deep-copy

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