CH1-3: remove duplicate char in a string, with/without additional buffer

【高分子材料工程】嵌件注塑结构设计与工艺优化:金属-塑料复合件界面强度及失效预防技术规范 内容概要:本文系统阐述了嵌件注塑(Insert Molding)的设计参数、模具关键技术及失效预防措施,聚焦黄铜H62或304不锈钢与PA66-GF30材料组合的基准工况,提供可用于工程图纸、DFM检查、模具验收和工艺规程的量化依据。内容涵盖工艺边界界定、材料匹配与界面力学分析、结构设计参数(如包覆壁厚、滚花、倒角)、模具设计要点(定位、浇口、排气、冷却)、工艺参数窗口、八大失效模式及其对策、验证验收标准以及量产控制要求,强调通过DFM仿真、模流分析和DOE试模优化工艺,并列出常见设计误区与纠正方案。; 适合人群:从事注塑产品设计、模具开发、工艺工程及质量管理的工程技术人员,尤其适用于汽车、电子、医疗等行业中具备1-3年及以上相关经验的研发人员; 使用场景及目标:①指导嵌件注塑零件的可制造性设计与结构优化;②支持模具设计评审与验收;③制定试模调机与量产工艺规范;④开展失效分析与质量改进; 阅读建议:此资源兼具理论机制与工程实践,建议结合实际项目对照查阅,重点关注包覆壁厚、预热温度、浇口布置等关键参数的取值边界,并在应用非基准材料时进行线膨胀系数与收缩率的换算修正,避免直接套用数据。 立即下载

感谢Hawstein的答案,然后再整理一边,make sure自己完全理解了。

所有代码在http://www.compileonline.com/compile_cpp11_online.php 上面测试,方便快捷,同时在本地和csdn git上面备份。


1. 记录各个字符出现情况的bool型scoreboard可以保存下标大于size的吗?

其实没关系,因为ASCII的decimal范围是0~127(其实还有128个,那些是extended ASCII,所以需要8位来保存全部的ascii码)。所以所有值都在0~255;

eg: 

bool a[256]; //cuz it stored the ASCII 
memset(a,0,sizeof(a));
void block(char* s){
     const int* curptr = s;
   for (int i = 0; i<len; ++i){
     int v = *curptr;
     curptr++;
     a[v] = true;  // eg: A的ASCII值是65,a的是97
   }
}


但是就算是定义了一个size为1的array:a[1],也可以定义a[300],a[301],a[302]...不知道为什么。。。

#include 
  
   
#include 
   
    
using namespace std;

double atest(double a){
    cout << a << endl;
    a = a+3.2;
    cout << a << endl;
}

void st(char *s){
    int l = strlen(s);
    cout << "\nl::" << l << endl;
}


//http://www.cplusplus.com/doc/tutorial/pointers/
void sj(char *s){
    int len = strlen(s);
    const char *current = s;
    for (int i=0; i
    
   
  



2种情况的T(n)会不一样:


#include 
 
  
#include 
  
   
using namespace std;

void a0(char* s){
    int len = strlen(s);
    int p = 0;
    if (len < 2) return;
    for (int i = 0; i
   
     
    

1. 如果不可以用另外的array的话,就要In place 的修改,也就是见到一个char就和他后面的所有字符比较一遍,当发现duplicate的情况,把那个字符置为一个flag的值,好让后面s[p++]=s[i]的时候的判定是根据(s[i]!=flag). Hawstein的flag是‘\0’,这样就不用想一个不是ASCII的字符了。不过这样就不会复制最后一个真正的结束符号,所以在循环完之后要s[p] = '\0'. 记得K&R的解答也用了这个方法。

当然,用这个方法的话,T(n)=n+(n-1)+(n-2)+...+1 = O(n^2);


2. 如果可以用additional buffer,则只需要1次循环,而modify一遍scoreboard需要O(n)的时间复杂度。


在这里的2个method都是针对输入是char型字符串:char ss1[] = "abcde";

而如果是string的话,就要用string的method,修改的话 需要用str+=,而不能s[p++].


智慧医共体AI大模型赋能智能体平台及AI场景应用规划方案(决策评审版).pptx 立即下载

相关推荐

逆向选择启示录:一个失败高频策略如何意外跑赢市场

本文探讨了高频交易中的逆向选择现象,揭示了一个失败的高频策略如何通过简化意外跑赢市场。通过加密货币市场的实证分析和蒙特卡洛模拟,研究发现低预测性的简单策略反而更具鲁棒性,有效规避了逆向选择风险。文章还提供了小币种做市策略的优化框架和实践建议,为量化交易者提供了宝贵洞见。

weixin_29191669的博客 401

Ch1_3(初尝试自定义函数)

1 /*比较两数大小并输出最大值的平方根*/ 2 #include<iostream> 3 #include<cmath> 4 using namespace std; 5 double Max(double x, double y); 6 //声明Max函数,函数名前为函数体中返回数据类型,形参前必须加数据类型,且一参一类型,不可共...

dingda2029的博客 153

TM1621/HT1621 段码LCD驱动器

TM1621 LCD 驱动器

qq_45325304的博客 1万+

去除字符串中重复字符

字符串去重

每天进步一点点 4239

电力-平衡式IEC 60870-5-101规约报文解析

本文详细介绍了电力自动化中平衡式IEC 60870-5-101规约的应用,包括链路建立与初始化、对时、遥控操作、数据上送和总召唤等关键步骤,通过实例解析了报文格式和交互过程,是理解配网自动化通信的重要参考资料。

让你爱上电路设计 5686

告别反复格式化!用Ventoy制作2025年终极启动盘,Windows/Linux/macOS一网打尽

本文详细介绍了如何使用Ventoy制作2025年终极多系统启动盘,彻底告别反复格式化U盘的烦恼。Ventoy通过创新的引导加载器架构,允许用户在一个U盘内同时存放并直接启动Windows、Linux、macOS等多种系统镜像和WePE等维护工具,实现真正的非破坏性管理和极高的U盘利用率。文章涵盖从安装配置、镜像库构建到安全启动设置等全流程实战指南。

weixin_29280219的博客 245

cc150做题计划

计划:12.29.2013 - 1.29.2013 做完第一遍题目,然后2月做leetcode。 2月底面试前完成200题C++。 这里记录一下ctci学习的参考资料。 1. hawstein的blog 2. https://github.com/ChengTian/CtCI 3. absolute C++ 5th 4. Primer C++ 5. learncpp:http

纯黑老白的专栏 2909

智能优化算法-北方苍鹰优化算法(NGO)(附源码)

北方苍鹰优化算法 (Northern Goshawk Optimizer, NGO) 是一种基于群体智能的元启发式优化算法,它模拟了北方苍鹰(Northern Goshawk)的捕食行为、领地行为以及社交互动,用于解决复杂的优化问题。总之,NGO作为一种新颖的优化算法,在处理复杂优化问题方面展现出了潜力。随着进一步的研究和应用,NGO有望成为解决实际问题的有效工具。

w971656545的博客 1362

ch4.6: find the LCA of 2 nodes in a binary tree with 3 different methods

In this problem, it is important to fully understand the definition of least common ancestor of 2 nodes: it means: (from leetcode blog: 点击打开链接) _______3______ / \

纯黑老白的专栏 1330

检测头篇 | 手把手教你如何去更换YOLOv8的检测头为ASFF_Detect

自适应空间特征融合(ASFF)的主要原理旨在解决单次检测器中不同尺度特征的不一致性问题。具体来说,ASFF通过动态调整来自不同尺度特征金字塔层的特征贡献,确保每个检测对象的特征表示是一致且最优的。本文所做出的改进是将YOLOv8的检测头更换为ASFF_Detect。🌈

小哥谈 2501

innovus获取mem pin shape box脚本

innovus mem 的pin shae只能通过attitude editor看属性获取其pin shape的box,但是想用脚本处理一定box时,没有别的办法能直接获取box属性。我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?

m0_61544122的博客 1116

Ch1.6: IN-place-ly rotate a pic(NxN matrix) by 90 digree in Verilog(CPP)

这个有点像DSP FPGA Chang Choo的题目,一般是放大插值,DFT,IIR之类的Verilog题目。 题目在这:Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees.

纯黑老白的专栏 1295

RT-DETR改进目录一览 | 涉及卷积层、轻量化、注意力、损失函数、Backbone、SPPF、Neck、检测头等全方位改进

1️⃣本专栏已更新260多种不同的改进方法,所使用并改进的每一个模块均包含详细的模块分析、原理讲解、个人总结、多种改进方式以及完整的修改流程,所有改进100%可直接运行。2️⃣所有改进点均为近三年顶会,顶刊提出的先进算法,将其融入到中,紧跟学术热点,适应不同的任务场景。3️⃣团队内发表数篇SCI论文,熟悉完整的发表流程,订阅专栏即可进群享受模型训练、模型改进、论文写作、投稿选刊,从入门到论文的各种答疑内容。4️⃣专栏内容会持续更新,最近更新时间:2024-12-4。项目介绍在大家购买专栏后,加入学习

Limiiiing的博客 2万+

Ch2-2: return the nth to the last node data of a singly linked list

In this problem, I need to find the nth to the last node data of a singly linked list.  In order to do so, one good way is to use recursion, since it is automatically put recursion part into stack an

纯黑老白的专栏 1290

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

1/22/2014: 纪念第一个C++ programmer电面--F家

经过20天的CC刷题(其实是学习),才刚刚做到第四章。看看其他非ACM牛人,都是leetcode,CC,EPI滚瓜烂熟才去面。而且onsite确实是靠实力,要有做过大project之后才能真正融会贯通C++精神。 Anyway,谢谢郭志给的refer,不然连电面的机会都没有。 开头是C++基础题: 1. Fib的2种写法:recursive和DP 2. Struct和Class的区别;在C

纯黑老白的专栏 1274

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Ch1-7: clear the row i and column j iff a[i][j]==0

in this problem, both monish001 and hawstein use O(n^2) solution which first tranverse the char** a to find the a[i][j]==0 and mark that row/col to be: TRUE. Then the send loop make the TURE row/col

纯黑老白的专栏 1207

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

复习一下dfs和bfs 用java

dfs 和 bfs都是用来找从source 到 target的path的算法。 dfs用的是recursion,bfs则用queue

纯黑老白的专栏 1191

Ch3-1: use a single array to implement three stacks.

Here it explains why Hawstein use this in his constructor, because he use size a parameter in his constructor while "size" is also a member variable(it's private), so he use this->size = size, explici

纯黑老白的专栏 1097

ch4.7: given 2 huge Binary tree t1, t2(>1millon nodes), decide if one tree is subtree of another one

// Ch4.7: You have two very large binary trees: T1, with millions of nodes, and T2, // with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1 #include #include #includ

纯黑老白的专栏 1030

复习recursion

1. 如果这样 private void lop(int x, int size, double[] jerry){ if(x==size-1){ jerry[x] = -1; return; } if(jerry[x+1]==0){ jerry[x+1] = jerry[x]- 1; //if so, lop(x+1, size, jerry); }

纯黑老白的专栏 1009

Ch2-5: find the beginning of loop in a circular linked list---two solutions

Given a circular linked list, implement an algorithm which returns node at the beginning of the loop. DEFINITION Circular linked list: A (corrupt) linked list in which a node’s next pointer poin

纯黑老白的专栏 986

Ch3-2: implement min() for a stack with O(1)

Here will show the thinking flow from bad to good. idea 1: const int MAX_INT = ~(1<<31);//2147483647 struct node{ int val, min; }; class StackWithMin{ public: StackWithMin(int size){

纯黑老白的专栏 956

Ch8.8: 8 queen problem

In order to solve this problem efficiently, need to use backtracking method instead of iterations. Aka: Backtracking is a general algorithm for finding all (or some) solutions to some computational p

纯黑老白的专栏 949

Ch3-3: popat(int idx) of setofstack

Continue to use class to design solution, also, start to use STL, such as container (vector, stack, set, ...). save time and to be more professional. The design without popat method is similar to the

纯黑老白的专栏 948

Ch4-2: find if 2 given vertices are connected in a directed map,BFS + JUST fix the DFS recursion

In this problem, there are 2 ways: BFS or DFS. Hawstein used BFS: #include #include #include #include using namespace std; const int maxn = 100; bool g[maxn][maxn], visited[maxn]; int n;

纯黑老白的专栏 938
上一篇: 跟着做openRISC1200和minSoC---从2013.11.12
下一篇: Ch1-4: anagram string
纯黑老白
博客等级 码龄18年 30粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值