小编Con*_*ius的帖子

常量和限制指针有什么区别?

常量和限制指针之间有什么区别,例如:

int * const ptr,  int * restrict ptr
Run Code Online (Sandbox Code Playgroud)

c

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

python程序中使用的变量列表

我们怎样才能在python程序中找到所有变量?例如. 输入

def fact(i):
    f=2
    for j in range(2,i+1):
        f = f * i
        i = i - 1
    print 'The factorial of ',j,' is ',f
Run Code Online (Sandbox Code Playgroud)

产量

变量 - f,j,i

python variables

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

Python中的"列表索引超出范围"错误

我再次制作一个简单的Checkers.并且,为了跟踪检查员移动到的所有位置,我创建了一个列表来添加所有位置.

Locations = [(10, 10), (70, 10), (130, 10), (190, 20), (250, 10), (310, 10), \
         (370, 10), (430, 10), (10, 70), (130, 70), (190, 70), (250, 70), \
         (310, 70), (370, 70), (430, 70), (10, 130), (70, 130), (130, 130), \
         (190, 130), (250, 130), (310, 130), (370, 130), (430, 130), \
         (10, 190), (70, 190), (130, 190), (190, 190), (250, 190), (310, 190), \
         (370, 190), (430, 190)]
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试执行程序时,我总是得到:Ld8 = Locations [31] - 列表索引超出范围

所以,我想也许一个列表只能包含一定数量的数字.因此,我创建了第二个位置列表并添加了行E-H,以便拆分列表.但是,我仍然收到索引超出范围的相同错误.(Ld8是存储行D,第8列的位置的变量)

python pygame

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

使用这种智能指针铸造是否安全?

使用这种智能指针铸造是否安全?

APtr a(new A());
BPtr & b = (Bptr&)a; // this is it
Run Code Online (Sandbox Code Playgroud)

那里,

class A
{
public:
   virtual ~A(){}
   virtual void methodA() = 0;
}
typedef std::tr1::shared_ptr<A> APtr;

class B : public A
{
public:
   virtual ~B(){}
   virtual void methodB() = 0;
}
typedef std::tr1::shared_ptr<B> BPtr;

/////////////////////////////////////////////////////////////////////////////////

BPtr & b = a; //this way doesn't work
Run Code Online (Sandbox Code Playgroud)

c++ casting smart-pointers tr1

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

函数不会接受auto_ptr的迭代器

我写了一些我试图修复的有缺陷的Huff压缩代码.我做的第一件事就是将指针切换到auto_ptr(有理由我没有使用另一个智能指针).我创建了一个向量,auto_ptr但是当我尝试将auto_ptr传递给函数时,*(vector.begin())它不起作用.

我的功能代码我试图将所有权传递给(它是一个成员函数为set_node):

struct Node {
    int weight;
    char litteral;
    auto_ptr<Node> childL;
    auto_ptr<Node> childR;
    void set_node(int w, char l, auto_ptr<Node>& L(), auto_ptr<Node>& R()){
        weight = w;
        litteral = l;
        childL = L;
        childR = R;
    }
};
Run Code Online (Sandbox Code Playgroud)

这就是我尝试调用它的方式(p是节点):

p.set_node(w, '*', *nodes->begin(), *(nodes->begin()+1));
Run Code Online (Sandbox Code Playgroud)

这是向量声明的方式:

vector<auto_ptr<Node> >* nodes = new vector<auto_ptr<Node> >;
Run Code Online (Sandbox Code Playgroud)

c++ auto-ptr standard-library huffman-code

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

Python string.find()给出错误"切片索引必须是整数或无或具有__index__方法"

我试图在Python中做一个简单的子字符串匹配,虽然我记得昨晚它工作正常,但从早上开始这段代码就出现了以下错误.这似乎是一个已知的错误,任何人都可以建议为什么会发生这种错误?

if string.find(row[1],drug) != -1:
    print "abstract id =  ", row[0],"Drug found=", drug
Run Code Online (Sandbox Code Playgroud)

错误:

File "./substring.py", line 31, in <module>
    if string.find(row[1],drug) != -1:
TypeError: slice indices must be integers or None or have an __index__ method
Run Code Online (Sandbox Code Playgroud)

这里row[1]drug两者都是简单的字符串.

python

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

更好的方法是确保4个随机值根本不相等?

我有一个qt表单,有一个乘法问题和4个按钮.4个按钮(选项)是随机生成的,问题也是如此.

我只想将4个选项随机化,因此它们是随机的,但它们都不等同于其他选择.这就是我现在正在做的事情,但是效果并不好:

while (choice1 == choice2 || choice1 == choice3 || choice1 == choice4)
    choice1 = (rand() % max) + 1;
while (choice2 == choice1 || choice2 == choice3 || choice2 == choice4)
    choice2 = (rand() % max) + 1;
while (choice3 == choice1 || choice3 == choice2 || choice3 == choice4)
    choice3 = (rand() % max) + 1;
while (choice4 == choice1 || choice4 == choice2 || choice4 == choice3)
    choice4 = (rand() % max) + 1;
Run Code Online (Sandbox Code Playgroud)

还有其他人有更好的方法吗?

c++

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

通过它的第一个条目替换列表中的元组

我正在使用python 3

我有一个不同元组的列表.每个元组的第一个值总是相同,但其余的变化.如何在包含第一个值的元组之后搜索列表,然后将整个元组替换为列表中的新元组?例如:这是我的元组:(122, 23, 24, 9)

这个元组在列表中,第一个值总是相同,但其余的变化我如何找到列表中的元组,其中第一个值等于我的元组"122"并替换它我的整个元组

(125, 34, 35, 21)

(122, 341, 5, 27)

(124, 31, 51, 7)
Run Code Online (Sandbox Code Playgroud)

python replace tuples list equals

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

链表节点类中的链接数

为链表创建节点时,它可能如下所示:

template <class T>
class node {
 T data;
 node* next;
}
Run Code Online (Sandbox Code Playgroud)

对于双向链表,它可能看起来像这样:

template <class T>
class node {
 T data;
 node* next;
 node* prev;
}
Run Code Online (Sandbox Code Playgroud)

对于BST,它可能看起来像这样:

template <class T>
class node {
 T data;
 node* left_child;
 node* right_child;
}
Run Code Online (Sandbox Code Playgroud)

这可以按以下格式推广:

template <class T>
class node {
 T data;
 node* links[N]; // N = 1 for linked list, N = 2 for tree or doubly linked list, etc...
}
Run Code Online (Sandbox Code Playgroud)

在不使用STL向量的情况下在类ctor中指定N的最佳方法是什么?

c++ pointers linked-list

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

window.VARIABLE_NAME 不起作用

window.VARIABLE_NAME不管用。我收到以下错误,请指导我。

Uncaught SyntaxError: Unexpected token.
Run Code Online (Sandbox Code Playgroud)

我写了以下代码。

var window.testing
Run Code Online (Sandbox Code Playgroud)

javascript

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

请解释用于执行python文件的shell代码

我是shell脚本的新手,请任何人解释下面的代码

ls  *.py > xx
while [ 1 ]
do
read myline || break
python $myline 
python $myline --genxml 
done<xx
service nac-ms restart
Run Code Online (Sandbox Code Playgroud)

Thnaks Mukthyar

python sh

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