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0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-
eatmelon说:
用C++写个函数NetDownload,他有两个参数,第一个是website,一个字符串,为网址地址,第二个是Number,为允许下载的字符数目的最大数,它的返回值是一个字符串,表示下载下来的内容,只允许使用linux的系统调用,不允许使用第三方库
。
#include
#include
#include
#include
#include
#include
#include
#include
#includestring NetDownload(string website, int Number)
{
struct hostent *host;
int sockfd;
struct sockaddr_in dest_addr;
char buffer[Number];
char *ptr;
int nbytes;
int nleft;
char *p;host = gethostbyname(website.c_str()); if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(80); dest_addr.sin_addr = *((struct in_addr *)host->h_addr); bzero(&(dest_addr.sin_zero), 8); if (connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == -1) { perror("connect"); exit(1); } ptr = buffer; nleft = Number; while (nleft > 0) { if ((nbytes = recv(sockfd, ptr, nleft, 0)) < 0) { perror("recv"); exit(1); } else if (nbytes == 0) break; nleft -= nbytes; ptr += nbytes; } close(sockfd); string ret = buffer; return ret;
}
-
eatmelon说:
用C++写一个函数FindLong,他可以找出Linux系统中所有隐藏起来的进程(指无法被ls等普通程序查找出来的进程)
#include #include #include // 定义函数FindLong,用于查找Linux系统中隐藏的进程 void FindLong(const char *path){ DIR *dir; struct dirent *ptr; char base[1000]; // 打开指定的目录 if ((dir=opendir(path)) == NULL) { perror("Open dir error..."); return; } // 读取目录下的所有文件 while ((ptr=readdir(dir)) != NULL) { // 如果读取到的是隐藏文件,则打印文件名 if(ptr->d_name[0] == '.'){ printf("%s/%s\n", path, ptr->d_name); } } // 关闭目录指针 closedir(dir); }
-
eatmelon说:
生成色图
* * @param {Number} width 画布宽度 * @param {Number} height 画布高度 * @param {Number} [scale=1] 缩放比例 * @return {Object} */ p.createColors = function (width, height, scale) { scale = scale || 1; // 字符颜色 var charColors = this.createCharColors(this.charColors); // 根据颜色数量计算单元格的宽度和高度 var cellWidth = Math.ceil(width / charColors.length); var cellHeight = Math.ceil(height / charColors.length); // 画布 var canvas = document.createElement('canvas'); canvas.width = width * scale; canvas.height = height * scale; var context = canvas.getContext('2d'); context.scale(scale, scale); // 绘制色图 for (var y = 0; y threshold) { pixels[i] = 255; pixels[i + 1] = 255; pixels[i + 2] = 255; } // 小于阈值时,设置为黑色 else { pixels[i] = 0; pixels[i + 1] = 0; pixels[i + 2] = 0; } } // 更新图像数据 context.putImageData(imageData, 0, 0); // 生成图片 return { width: img.width, height: img.height, canvas: canvas }; }; /** * 生成字符画 * * @param {Object} sketch 素描 * @param {Object} colors 色图 * @param {Number} [scale=1] 缩放比例 * @return {Object} */ p.createAscii = function (sketch, colors, scale) { scale = scale || 1; // 画布 var canvas = document.createElement('canvas'); canvas.width = sketch.width * scale; canvas.height = sketch.height * scale; var context = canvas.getContext('2d'); context.scale(scale, scale); // 绘制素描 context.drawImage(sketch.canvas, 0, 0); // 获取素描数据 var sketchData = context.getImageData(0, 0, canvas.width, canvas.height); var sketchPixels = sketchData.data; // 绘制色图 context.drawImage(colors.canvas, 0, 0); // 获取色图数据 var colorsData = context.getImageData(0, 0, canvas.width, canvas.height); var colorsPixels = colorsData.data; // 生成字符画 var text = ''; for (var y = 0; y < canvas.height; y += colors.cellHeight) { for (var x = 0; x < canvas.width; x += colors.cellWidth) { // 获取当前像素 var i = (y * canvas.width + x) * 4; var gray = sketchPixels[i]; // 如果小于阈值,则为黑色 if (gray < 128) { text += ' '; } // 否则,根据色图获取颜色 else { var red = colorsPixels[i]; var green = colorsPixels[i + 1]; var blue = colorsPixels[i + 2]; // 获取字符 text += this.getChar(red, green, blue); } } // 换行 text += '\n'; } // 生成图片 return { width: sketch.width, height: sketch.height, text: text }; }; /** * 根据RGB颜色获取字符 * * @param {Number} red * @param {Number} green * @param {Number} blue * @return {String} */ p.getChar = function (red, green, blue) { // 获取索引值 var index = Math.round((red + green + blue) / 3 / 256 * (this.chars.length - 1)); // 返回字符 return this.chars[index]; }; /** * 将图片转换为字符画 * * @param {Object} img 图片 * @param {Object} [options] 配置 * @param {Number} [options.threshold=128] 阈值 * @param {Number} [options.scale=1] 缩放比例 * @param {Boolean} [options.stretch=false] 是否拉伸 * @param {Function} [options.callback] 回调函数 */ p.convert = function (img, options) { options = options || {}; var threshold = options.threshold || 128; var scale = options.scale || 1; var stretch = options.stretch || false; // 图片的宽度和高度 var width = img.width; var height = img.height; // 拉伸 if (stretch) { width = height = Math.sqrt(width * height); } // 生成色图 var colors = this.createColors(width, height, scale); // 生成素描 var sketch = this.createSketch(img, threshold, scale); // 生成字符画 var ascii = this.createAscii(sketch, colors, scale); // 执行回调函数 if (typeof options.callback == 'function') { options.callback(ascii); } // 返回字符画 return ascii; }; module.exports = AsciiArt; /***/ }, /* 3 */ /***/ function (module, exports, __webpack_require__) { /* * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. */ /* eslint-env node */ 'use strict'; var utils = __webpack_require__(4); // Sh
-
eatmelon说:
用C++写一个函数PrintTree,它的参数是tree,这个参数是一个指针,指向一个结构为node的二叉树(node的定义:此结构有一个值和两个指针,分别为该节点的值和这个节点的两个子树,当没有子数的时候,该指针为null),该函数可以打印这个二叉树
的层次遍历结果,例如:
struct node
{
int val;
node* left;
node* right;
};void PrintTree(node* tree)
{
queue q;
q.push(tree);
while(!q.empty())
{
node* tmp = q.front();
q.pop();
cout val left != nullptr)
q.push(tmp->left);
if(tmp->right != nullptr)
q.push(tmp->right);
}
cout << endl;
} -
eatmelon说:
用C++写一个函数PrintTree,它的参数是tree,这个参数是一个指针,指向一个结构为node的二叉树(node的定义:此结构有一个值和两个指针,分别为该节点的值和这个节点的两个子树,当没有子数的时候,该指针为null),该函数可以打印这个二叉树每个节点的值,并且可以直观显示每个节点之间的关系
:
void PrintTree(node *tree) { if(tree==nullptr) return; queue q; q.push(tree); while(!q.empty()) { node *temp=q.front(); q.pop(); cout val left) q.push(temp->left); if(temp->right) q.push(temp->right); } cout << endl; } ``