要通过命令行显示消息,您可以使用 MsgBox 函数创建一个 .vbs 文件
(echo MsgBox "Line 1" ^& vbCrLf ^& "Line 2", 262192, "Title") > popup.vbs
常数从哪里来262192
?您会看到一个带有声音的警告图标和一个“确定”按钮,但官方帮助说您可以只使用 vbExclamation - 48。那么它来自哪里262192
?
该程序运行良好,但是当它结束(返回 0)并且解构器尝试成对处理类对象时,它会给出错误:
HEAP [program.exe]:指定给 RtlValidateHeap 的地址无效(0000021B54F40000, 0000021B54F50CA0)
这是完整的程序代码:
主文件
#include <iostream>
#include <utility>
#include "IntSet.h"
using namespace std;
int main() {
size_t temp = 0;
IntSet intset1;
IntSet intset2;
intset1.pushBack(1);
intset1.pushBack(2);
intset1.pushBack(2);
intset1.pushBack(5);
intset1.pushBack(6); // [1, 2, 5, 6]
intset2.pushBack(6);
intset2.pushBack(8);
intset2.pushBack(2);
intset2.pushBack(15);
intset2.pushBack(27); // [6, 8, 2, 15, 27]
IntSet* intset3 = intset1.relative_complement(intset2); // [1, 2, 5, 6] / [6, 8, 2, 15, 27] = [1, 5]
IntSet* intset4 = intset1.union_(intset2); // [1, 2, 5, 6] + [6, 8, 2, 15, 27] = [1, 2, 5, 6, 8, 15, 27]
pair<IntSet, IntSet> p = intset1.even_odd_division(intset2);
temp = intset3->size();
for (size_t i = 0; i < temp; i++) {
cout << (*intset3)[i] << std::endl;
}
cout << "\n" << std::endl;
temp = intset4->size();
for (size_t i = 0; i < temp; i++) {
cout << (*intset4)[i] << std::endl;
}
return 0;
}
整数集.h
#ifndef INT_SET_H
#define INT_SET_H
class IntSet {
public:
IntSet();
~IntSet();
public:
size_t size() const;
public:
void pushBack(const int value);
void remove(size_t index);
int search(int num);
IntSet* union_(IntSet& object_1);
IntSet* relative_complement(IntSet& object_1);
std::pair<IntSet, IntSet> even_odd_division(IntSet& object_1);
public:
int operator[](size_t index);
private:
int* arr_;
size_t size_{};
size_t capacity_{};
void addMemory();
};
#endif // !INT_SET_H
整数集.cpp
#include <utility>
#include "IntSet.h"
void IntSet::pushBack(const int value) {
if (search(value) == -1) {
if (size_ >= capacity_) addMemory();
arr_[size_++] = value;
}
}
void IntSet::remove(size_t index) {
for (size_t i = index + 1; i < size_; ++i) {
arr_[i - 1] = arr_[i];
}
--size_;
}
int IntSet::search(int num) {
for (size_t i = 0; i < size_; i++) {
if (arr_[i] == num) {
return (int)i;
}
}
return -1;
}
IntSet* IntSet::union_(IntSet& object_1) {
IntSet* NewIntSet = new IntSet;
for (size_t i = 0; i < size(); i++)
{
NewIntSet->pushBack(arr_[i]);
}
for (size_t i = 0; i < object_1.size(); i++)
{
NewIntSet->pushBack(object_1.arr_[i]);
}
return NewIntSet;
}
IntSet* IntSet::relative_complement(IntSet& object_1) {
IntSet* NewIntSet = new IntSet;
int index = 0;
for (size_t i = 0; i < size(); i++)
{
NewIntSet->pushBack(arr_[i]);
}
for (size_t i = 0; i < object_1.size(); i++)
{
index = NewIntSet->search(object_1.arr_[i]);
if (index >= 0) NewIntSet->remove(index);
}
return NewIntSet;
}
void IntSet::addMemory() {
capacity_ *= 2;
int* tmp = arr_;
arr_ = new int[capacity_];
for (size_t i = 0; i < size_; ++i) arr_[i] = tmp[i];
delete[] tmp;
}
int IntSet::operator[](size_t index) {
return arr_[index];
}
size_t IntSet::size() const {
return size_;
}
std::pair<IntSet, IntSet> IntSet::even_odd_division(IntSet& object_1) {
IntSet EvenIntSet;
IntSet OddIntSet;
for (size_t i = 0; i < size(); i++) {
if (arr_[i] % 2 == 0) EvenIntSet.pushBack(arr_[i]);
else OddIntSet.pushBack(arr_[i]);
}
for (size_t i = 0; i < object_1.size(); i++) {
if (object_1.arr_[i] % 2 == 0) EvenIntSet.pushBack(object_1.arr_[i]);
else OddIntSet.pushBack(object_1.arr_[i]);
}
return std::make_pair(EvenIntSet, OddIntSet);;
}
IntSet::~IntSet() {
delete arr_;
}
IntSet::IntSet() {
arr_ = new int[1];
capacity_ = 1;
}
需要生成一个不包含0的十六进制数字列表,其中的数字之和不超过十进制的11。
到目前为止,我只想到了这个:
import itertools
nums = [list(x) for x in itertools.product((1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'), repeat=7) if (x[-1] == x[-2])]
它仍然只是检查金额,但如何?
是否有可能以某种方式在 if 条件中规定 'A' = 10、'B' = 11 等等?
您需要创建 N 个空列表。我以为我可以通过 for 来完成,但是我在命名变量时遇到了一个问题:你不能只在变量名中添加一个循环参数。如何做到这一点,是否可以不通过循环,而是以更简单的方式完成?