小编Abh*_*hay的帖子

在Python中生成置换词列表的子集

我有一个单词列表,我需要生成所有这些可能的排列,但需要注意一点.

我目前使用以下代码:

from itertools import permutations

wordlist = ["word1", "word2", "word3"]

for perm in permutations(wordlist):
    print "".join(perm)
Run Code Online (Sandbox Code Playgroud)

它给出了输出:

word1word2word3
word1word3word2
...
word3word2word1
Run Code Online (Sandbox Code Playgroud)

但是我还需要它来打印这些单词的子集,例如:

word1    
word1word2
word2word1
...
Run Code Online (Sandbox Code Playgroud)

但我对如何做到这一点没有丝毫想法.我该从哪里开始?我该怎么读?

python permutation subset python-itertools

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

在哪里可以找到 Web 攻击字符串的详尽列表

我正在寻找 Web 攻击字符串的详尽列表,其中包括尽可能多的可能注入字符串,包括 SQLis、XSS、XPATH 注入、SSI 等。最好以各种格式编码。有谁知道在哪里可以找到这些?

xss sql-injection penetration-testing

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

在单词列表中查找字谜

我有一个单词列表和一个包含许多字谜的文件.这些字谜是单词列表中的单词.我需要开发一种算法来查找匹配的单词并在输出文件中生成它们.到目前为止我开发的代码只适用于前两个单词.另外,我无法让代码与包含数字的字符串一起玩得很好.请告诉我如何修复代码.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main (void)
{
int x = 0, y = 0;
int a = 0, b = 0;
int emptyx, emptyy;
int match = 0;
ifstream f1, f2;
ofstream f3;
string line, line1[1500], line2[50];
size_t found;

f1.open ("wordlist.txt");
f2.open ("file.txt");
f3.open ("output.txt");

while (f1.eof() == 0)
{
    getline (f1, line);
    line1[x] = line;
    x++;
}

while (f2.eof() == 0)
{
    getline (f2, line);
    line2[y] = line;
    y++;
}

//finds position …
Run Code Online (Sandbox Code Playgroud)

c++ anagram

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

在编译时将继承限制为所需数量的类

我们有一个限制,即一个类不能作为超过7个类的基类.有没有办法在编译时强制执行上述规则?

我知道Andrew Koenig的Usable_Lock技术可以防止类被继承,但只有当我们尝试实例化类时它才会失败.在推导自己时不能这样做吗?

允许基类知道谁是其子女.所以我想我们可以声明友好类的组合并封装它们来强制执行此规则.假设我们尝试这样的事情

class AA {
   friend class BB;
   private:
      AA() {}
      ~AA() {}
};

class BB : public AA {

};

class CC : public AA 
{};
Run Code Online (Sandbox Code Playgroud)

类CC的推导将生成编译器警告abt无法访问的dtor.然后,我们可以使用编译器调整(例如将所有警告标记为错误)将这些警告标记为错误,但我不想依赖这些技术.

另一种方式,但对我来说看起来很笨拙是: -

class B;

class InheritanceRule{
    class A {
    public:
        A() {}
        ~A() {}
    };
    friend class B;
};

class B {
public:
    class C : public InheritanceRule::A
    {};
};


class D : public InheritanceRule::A{};
Run Code Online (Sandbox Code Playgroud)

D类的派生将被标记为编译器错误,这意味着要派生的所有类都应该在B类中派生.这将允许至少检查从A类派生的类的数量,但不会阻止任何人添加更多.

这里有谁有办法吗?如果基类不需要知道谁是它的孩子,那就更好了.

注意:充当基类的类本身可以实例化(它不是抽象的).

提前致谢,

编辑1:根据jon.h的评论,略有修改

// create a template class without a body, so all …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance friend

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

写出尽可能长的循环

最近我在技术讨论中被问到了这个问题.考虑到运行它的机器/体系结构,可以在计算科学中编写的最长循环是什么?这个循环必须尽可能长,但不是无限循环,不应该最终崩溃程序(递归等...)

老实说,我不知道如何解决这个问题,所以我问他是否真的有可能.他说使用一些计算机科学概念,你可以得出一个假设的数字,这个数字可能不实用,但它仍然不会是无限的.

这里有人; 知道如何分析/攻击这个问题.

PS为可以存储最高数值的类型选择某个最高限制显然不是答案.

提前致谢,

computer-science loops programming-languages

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

投掷析构函数,内存腐败?

我们有一个类的语义行为如下: -

struct Sample
{
  ~Sample() throw() 
  {
    throw 0;
  }
};

void f ()
{
  try
  {
    delete new Sample;
  }
  catch (...){
  }
}
Run Code Online (Sandbox Code Playgroud)

我知道在dtors中抛出异常是邪恶的; 但放弃第三方图书馆资源是一个例外(但可以立即重新获得,有些奇怪!).还有一个这个资源的池,比如一个Sample类的数组/容器.因此,有两种情况需要考虑:破坏动态分配的对象和破坏动态分配的对象数组.

目前,只有在使用阵列版本(池)时,应用程序才会在不同的执行点随机崩溃.我们认为这是由于内存损坏,但那么为什么unpooled版本有效呢?

分配的内存会发生什么?是不确定的行为?在阵列的情况下会发生什么?是否调用了数组所有元素的dtors(至少,而不是内存)(比如第一个元素的dtor是否被抛出)?

提前致谢,

EDIT-1:嗯,我们跟踪了一些没有被调用的数组元素.但分配的内存似乎没有问题......以下是SC22-N-4411.pdf的第5.3.5.7节)

If the value of the operand of the delete-expression is not a null pointer value, the delete-expression will
call a deallocation function (3.7.4.2). Otherwise, it is unspecified whether the deallocation function will be
called. [ Note: The deallocation function is called regardless of whether the destructor for the …
Run Code Online (Sandbox Code Playgroud)

c++ destructor exception

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

除非指定较低的字体质量,否则ExtTextOut将失败,并且字符串非常长

有时我们的应用程序需要使用ExtTextOut绘制非常长的字符串(例如6,000个字符).有时ExtTextOut失败并返回零,GetLastError也返回零.

要重新创建该情境,请创建一个简单的MFC Single Document应用程序,然后将OnDraw设置为:

void CTestExtTextView::OnDraw(CDC* pDC)
{
 CTestExtTextDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 if (!pDoc)
  return;

 LOGFONT lfDetail = {0};
 lfDetail.lfHeight = -(::MulDiv(100, pDC->GetDeviceCaps(LOGPIXELSY), 720));
 lfDetail.lfCharSet = ANSI_CHARSET;
 lfDetail.lfOutPrecision = OUT_DEFAULT_PRECIS;
 lfDetail.lfQuality = CLEARTYPE_QUALITY;
 lfDetail.lfWeight = 400;
 _tcscpy_s(lfDetail.lfFaceName, LF_FACESIZE, _T("Arial"));

 CFont font;
 font.CreateFontIndirectW( &lfDetail );

 CFont * pold = pDC->SelectObject( &font );

 CString str = L"2 <office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:ooo=\"http://openoffice.org/2004/office\" xmlns:ooow=\"http://openoffice.org/2004/writer\" xmlns:oooc=\"http://openoffice.org/2004/calc\" xmlns:dom=\"http://www.w3.org/2001/xml-events\" xmlns:xforms=\"http://www.w3.org/2002/xforms\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" …
Run Code Online (Sandbox Code Playgroud)

c++ mfc draw

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

Ctor Initializer:自我初始化导致崩溃?

我很难调试生产崩溃.只是想与这里的人们确认语义.我们有一个类......

class Test {
public:
  Test()
  {
    // members initialized ...
    m_str = m_str;
  }
  ~Test() {}
private:
  // other members ...
  std::string m_str;
};
Run Code Online (Sandbox Code Playgroud)

有人改变了初始化以使用ctor初始化列表,这在我们的代码语义中是合理正确的.初始化顺序及其初始值是正确的.所以班级看起来像......

class Test {
public:
  Test() 
    : /*other inits ,,, */ m_str(m_str)
  {
  }
  ~Test() {}
private:
  // other members ...
  std::string m_str;
};
Run Code Online (Sandbox Code Playgroud)

但是代码突然崩溃了!我在这段代码中分隔了很长的列表m_str(m_str).我通过链接文本证实了这一点.

它必须崩溃吗?标准对此有何看法?(这是不确定的行为吗?)

c++ constructor ctor-initializer

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

使用哈希表的不同值

在循环遍历值列表或字段时,我正在做不同的值.

Dictionary<string, int> _ddistinctValues = new Dictionary<string, int>();

foreach(string _word in _words) {
 if(!_ddistinctValues.ContainsKey(_word)) {
    _ddistinctValues.Add(_word, 1);
 }
}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来实现这一点而不保存"1"整数值以节省空间?我正在使用哈希表来更快地获得不同的值.也许哈希没有值的wordname,只是不同的键?C#中有一个类可以做到这一点吗?

这不是一个大问题.就是想.

谢谢.

c# linq hashset

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