两道面试题

两道设计模式的面试题 两道设计模式的面试题 Binhua Liu   这是最近碰到的2个设计模式的面试题,大概如此:   1, Windows Media Player和RealPlayer是常用的媒体播放器,它们的API结构和调用方法非常不同,现在你的应用需要同时支持调用这2种播放器的API。你要怎么设计?   2, 现在有一种空调,它支持3种模式:Hot Air,Cool Air 和DoNot 阅读详情

第一道,比较经典,用代码实现strstr()的功能.

#include <iostream>
using namespace std;
char* findasub(char str1[],int len1,char str2[], int len2)
{
 if (len2>len1)return NULL;
 
 int j=0;
    int i=0;
 
 for (;j<len2;j++)
  for (;i<len1;i++)
  {
   if (str2[j]==str1[i])j++; //当有一个字符匹配时,子串后移一位.
   else j=0;     //任何一次两字符不等时,都要从头匹配.
  
   if (j==len2)              //匹配成功.这里之所以用len2而不用len2-1是因为
   {        //j==len2-1 j还会自增一次.
    int len=len1-i+len2;
    char*str=new char[len];
    for (int k=0;k<len;k++)str[k]=str1[k+i-len2+1];
    return str;
    break;
   }
  
  }
 
  if(j!=len2-1) return NULL;//匹配失败.
 
  return NULL;
}

int main(void)
{
 char str1[]="femalelover is a good man";
 char str2[]="lover";
 char* fn=findasub(str1,strlen(str1),str2,strlen(str2));
 if(fn)
 {
  cout<<fn<<endl;
  delete fn;
 }
 return 0;
}


第二道:用STL接受输入的整数,当输入不是整数时,输出排序后的所有整数:
#include <list>
#include <iostream>
#include <algorithm>
using namespace std;
void main()
{
 list<int>mylist;
 list<int>::iterator myit;
 double test=0;                    //这里必须用double,虽然我们要的是int
 int wathch=0;
 bool isint=true;

 while (isint)
 {
  cin>>test;
  if (test==int(test))      //这里判断一个数是否整数. 如果上面用int,则这里会死循环.
  {
   mylist.push_back(test);
   wathch++;
  }
  else isint=false;
 }
 if (mylist.size()==0)
 {
  cout<<"The list is empty/n";
  return;
 }
 else
 {
  mylist.sort();
 
  for (myit=mylist.begin();myit!=mylist.end();myit++)
   cout<<*myit<<endl;
 }

}

两道面试题所引发的C指针的思考 实际上这道题考察的是大家对于指针的掌握和ascii的一些知识:大家一定要理解*argv[i]意思,如果不注意可能会认为是取命令行参数的第二个字符串的值,其实不然,这样理解的话大家对于指向一个字符串的字符指针的的不理解,指向一个字符串的字符指针实际上是指向一个字符串首字符的地址,命令行参数输入的12 345 678看似数字,实际上是一个个字符串,*argv[i]的意思也就是取各自字符串的首字符也就是取1、3、6,说到这里这道面试题也就引刃而解了。一下的代码段是否正确,如果正确结果是什么?如果不正确如何改正? 阅读详情

相关推荐

关于运算符问题的两道面试题

面试题1:下面程序的结果是多少: #include using namespace std; int main() { unsigned char a = 0xA5; unsigned char b =  ~a>>4+1; cout // printf("b = % d\n ", b); return 0; } A: 245 B: 246 C: 250 D: 2

lplp90908的博客 753

排序练习 (C语言)和快排

给出一个数组,奇数序号降序,偶数序号升序,要求重排成重小到大的数组,时间复杂度为O(n) #include "sort.h" //给出一个数组,奇数序号降序,偶数序号升序,要求重排成重小到大的数组,时间复杂度为O(n) void main() { int a[] = {1,20,2,18,3,2,4,1}; int lenth = 7; int b[10] = { 0 }; int...

maryfei的博客 343

深度学习---双层神经网络中矩阵的运算及其含义记录

深度学习---双层神经网络中矩阵的运算及其含义记录神经网络的正向传播与反向传播正向传播第一层的权重矩阵第一层的输入矩阵Z^1^ = W^1^X^1^ + b^1^A^1^ = σ(Z^1^)第二层的权重矩阵第二层的输入矩阵Z^2^ = W^2^A^1^ + b^2^反向传播dz^2^ = A^2^ - Ydw^2^ = 1/n dz^2^A^1T^db^2^ = 1/n np.sum(dz^2...

qq_43228441的博客 3757

剑指Offer and Leetcode刷题总结之xx:面试真题

1. n个[0,n)的数,求每个数的出现次数(不能开辟额外空间) 基本思路:把每个数都sum到其对应相等的index上,取余(%)取到原位置真实数的方法;最后取商(//)可以得到出现次数;

DaBaiNiHaoBaiA的博客 1077

开发者的避坑指南:在Apple Silicon Mac上构建RocketMQ Python客户端的完整心路历程

本文详细记录了在Apple Silicon Mac上构建RocketMQ Python客户端的完整过程,重点解决了架构兼容性问题。通过源码编译rocketmq-client-cpp库,修复构建脚本和CMake配置,最终成功在M2芯片MacBook Pro上部署RocketMQ Python客户端,为开发者提供了实用的避坑指南。

Pepper的专栏 699

别再纠结了!实测罗技Flow、对拷线、微软Mouse without Borders,我的最终选择是...

本文通过实测对比罗技Flow、对拷线和微软Mouse without Borders等多设备控制方案,详细分析了各自的优缺点及适用场景。作者最终选择了对拷线与罗技键鼠的组合方案,为专业用户提供了稳定可靠的多设备协同办公解决方案,特别适合需要频繁传输大文件和跨设备操作的用户。

weixin_33696106的博客 414

排序奇升偶降链表

一.题目描述 给定一个奇数位升序,偶数位降序的链表,将其重新排序。 输入: 1->8->3->6->5->4->7->2->NULL 输出: 1->2->3->4->5->6->7->8->NULL 二.题目解析 1.分别是拆分链表,反转链表,合并两个有序链表三个问题的结合 /** 排序奇升偶降链表: 给定一个奇数位升序,偶数位降序的链表,将其重新排序为升序链表。 */ public class Solut

执子手 吹散苍茫茫烟波 1200

从厘米级到公里级:北斗网格10级精度在ArcPro中的完整应用指南

本文提供了北斗网格十级精度体系在ArcGIS Pro中的完整应用指南。详细解析了从660公里到1.5厘米的十级网格尺度及其编码逻辑,并重点演示了如何在ArcPro中生成网格、计算编码,以及根据项目需求(如滑坡监测)选择合适精度层级的实战策略。指南旨在帮助GIS专业人士利用这套统一的网格框架,高效管理多尺度空间数据并优化分析工作流。

Black的专栏 487

奇数位升序偶数位降序的链表进行排序

题目描述:一个链表,特点是奇数位升序偶数位降序,使得链表变成升序的。分析代码节点类:main方法:初始化方法:按照奇偶位拆分成两个链表:反转链表:合并两个有序链表(非递归):合并两个有序链表(递归): 分析 这道题可以分成三步: 首先根据奇数位和偶数位拆分成两个链表。 然后对偶数链表进行反转。 最后将两个有序链表进行合并(合并两种实现方式一种是递归另外一种是非递归)。 代码 节点类: class Node { int value; Node next; Node(int

qq_29494693的博客 1927

Eclipse邂逅Deepseek:本地化部署全攻略

通过前面一系列的步骤,我们成功地在 Eclipse 中完成了 Deepseek 的本地化部署,并且对部署后的功能进行了测试和优化,还解决了可能遇到的一些常见问题。这一过程不仅让我们体验到了将强大的大语言模型与高效的开发环境相结合的魅力,也为我们在软件开发过程中带来了诸多便利。本地化部署 Deepseek 到 Eclipse,使得我们在代码编写过程中能够获得智能的代码补全和精准的问答支持,大大提高了开发效率。同时,本地化部署保障了数据的安全性和隐私性,避免了数据在传输过程中可能面临的风险。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 4568

强化学习(Reinforcement Learning)与动态系统控制方法

一个具体的 RBC 的例子是自动驾驶汽车中的交通规则。在训练过程中,代理通过与环境交互获取奖励信号,并学习如何在某个状态下采取最佳的行动,以最大化长期的累积奖励。在化工过程中,通过对生产过程中的温度、压力、流量等参数的控制来实现产品的质量和产量的提高。需要注意的是,以上代码只是一个简单的示例,实际的 MPC 系统可能会更加复杂,并包含更多的模型预测和控制算法来实现更复杂的控制任务。需要注意的是,以上代码只是一个简单的示例,实际的自动驾驶汽车系统可能会更加复杂,并包含更多的规则和条件来确保安全行驶。

AI天才研究院 4092

排序算法——先按先奇后偶再按从小到大排序

问题: 有一组数据,排序规则是:要求按照奇数在前,偶数在后,然后在按照大小顺序排序 算法思想: 法一: 可以先把奇数和偶数分开,再用sort()排序,然后再合并输出; 法二: 利用sort()的二级排序 //先按先奇后偶再按从小到大 #include<iostream> using namespace std; #include<algorithm> bool cmp(int a, int b) { if (a % 2 == b & 2) return

weixin_66033926的博客 654

YOLOv8【第九章:模型部署篇·第2节】一文搞懂,模型剪枝与压缩技术!

🏆 本文收录于 《YOLOv8实战:从入门到深度优化》 专栏。该专栏系统复现并梳理全网各类 YOLOv8 改进与实战案例(当前已覆盖分类 / 检测 / 分割 / 追踪 / 关键点 / OBB 检测等方向),坚持持续更新 + 深度解析,质量分长期稳定在 97 分以上,可视为当前市面上 覆盖较全、更新较快、实战导向极强 的 YOLO 改进系列内容之一。

**My Coding Family** 1542

两道需要在半个小时内完成的面试题

知无涯 1万+

10、网络安全工具:Bettercap 与 Web 应用测试工具全解析

本文详细解析了网络安全工具Bettercap及其在中间人攻击和无线攻击中的应用,同时介绍了多种Web应用测试工具,如Amass、Cadaver、Dirb等,并探讨了工具的使用场景、流程、注意事项以及未来发展趋势,为网络安全测试提供了全面的指导。

u0v1w2x3的博客 237

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

近期背的两道面试题

面试题

shaadnglvsada的博客 257

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

美团曾经的两道算法面试题

大家要是有内推码也可以放在我的评论区,供大家一起使用可以吗?这是美团曾经的两道算法面试题,与诸君共勉!现在小美想知道,如果那些未知的元素在区间[l,r][l,r]范围内随机取值的话,数组所有元素之和的最小值和最大值分别是多少?现在,小美希望你回答有多少个i∗ii∗i的完美矩形区域。小美认为一个矩形区域是完美的,当且仅当该区域内 0 的数量恰好等于 1 的数量。小美拿到了一个n∗nn∗n的矩阵,其中每个元素是 0 或者 1。小美拿到了一个由正整数组成的数组,但其中有一些元素是未知的(用 0 来表示)。

2401_82689064的博客 539

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

JavaScript关于函数作用域的两道面试题

目录- 面试题1- 面试题1答案及解析- 面试题2- 面试题2答案及解析 - 面试题1 // 问题:请问以下代码的输出结果 var a = 1 function fn() { console.log(a) } function fn2(f) { var a = 2 f() } fn2(fn) - 面试题1答案及解析 // 问题:请问以下代码的输出结果 var a = 1 function fn() { console.log(a) } function fn2(f) { var a

Scorpio_sky的博客 1922

两道简单的前端面试题

今天面试的两道题,记录一下。 1.下面代码会输出什么 function printArr(){ var arr = [1,2,3] for(i = 0;i<arr.length;i++){ console.log(arr[i]) } } var arr = [4,5,6] for(var i = 0;i<arr.length...

weixin_30600503的博客 72

两道腾讯面试题

两道腾讯面试题 分类: C++ Win32 common 面试题2012-03-29 16:17 2437人阅读 评论(8) 收藏 举报 面试腾讯functionclasscrashnull       首先娱乐一下,看看这道学龄前儿童智力题,学龄前哦~真心伤不起!       反正我看完之后是直接泪奔了,这道题目不是文艺儿童都做不出啊……              好

Cloud-Datacenter-Renewable Energy-Big Data-Model 728

两道很有意思的面试题[转载]

两 道很有意思的面试题http://www.cppblog.com/OnTheWay2008/archive/2010/03/28/110724.html第一题是:求一个字符串中出现频率最高的那个字符及其出现此时?具体代码如下:1voidGetMost(char*pStr,char&ch,int&size)2{3ch='\0';...

weixin_34261739的博客 87

两道JVM面试题,竟让我回忆起了中学时代!

考虑到可能有部分粉丝对JVM参数不清楚,所以我们参照中学的授课模式,给大家做一些知识上的普及。理论上,JVM参数主要分为三类1.标配参数该类型参数在JDK各个版本之间稳定,很少有大的变化。比如查看版本号java -version 2.X参数这些用的不多,看看就好。// 解释执行 -Xint // 第一次使用就编译成本地代码 -Xcomp // 混合模式 -Xmixed 3.XX参数3.1 布尔...

十指波课堂的博客 181

分享两道有关回文数的常见面试题

回文数是正反读都是相同的数,如回文数 123321,正反读都是一样的,如回文字符串 “abccba”。面试官常常会考回文数的编程题,今天小编分享两道关于回文数的面试题。1. 求字符串中最大...

机器学习算法那些事 511

重温两道页面重构面试题

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34037977的博客 118

两道生成器面试题

什么时候使用生成器呢,当你不想一次性把所有值都列出来,要一个个调用的时候。 # yield执行的模式 def gen(): print('start') m = yield 2 # 可以看作yield返回值为2,send(3)把3传递给m,并调用,m变成3了,同下 print(m) n = yield 3 print(n) #...

weixin_30389003的博客 85
上一篇: 冒泡与选择排序
下一篇: 我的大学
biblereader
博客等级 码龄20年 11粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址