当前位置:网站首页>Niu Ke's entry record of C language
Niu Ke's entry record of C language
2022-04-22 02:44:00 【_ Qiqi】
Hello, everyone , Recently, major Internet layoffs , Many people received the graduation notice , Some have stayed directly at home for more than a week , I haven't found a job yet , It's hard to find , I'm also in a low mood
The problems you will encounter in the interview , You can find the answer on Niuke online :
1、 What does big factory interview ask ?
2、 When you encounter a written test question, you panic , No simulated environment
3、 There is no interviewer to help you simulate the interview
4、 Received more than one offer, I don't know which is good ?
All questions can be answered here ——> Poke me directly jump to brush the algorithm problem
Those who want to brush questions can go to niuke.com 《C/C++, Algorithm ,Java Practice the classic interview questions every day 》 Very friendly to Xiaobai

Cattle from [ Programming questions ] Replace blank space
Title Description
Please implement a function , Replace each space in a string with “%20”. for example , When the string is We Are Happy. The replaced string is We%20Are%20Happy.

Topic analysis
because 1 Space occupied 1 Characters , But replace with “%20” The words are 3 Characters . So you need to add position to the string . because “we are happy” There is 2 A space , Therefore, it is natural to increase 4 A place , That is, the length of the string increases 4.
Algorithm steps
1. First, make sure there are several spaces in this string . Then determine the length of the new string according to the space .
2. Move the string after the space back in turn .
3. Then fill in “%20” These three characters .
Code
class Solution {
public:
void replaceSpace(char *str,int length) {
int spacecnt = 0;
char* cur = str;
while (*cur)
{
if (*cur == ' ')
{
spacecnt++;
}
cur++;
}
int newlen = length + spacecnt * 2;
int end1 = length - 1;
int end2 = newlen - 1;
while (end1 != end2)
{
if (str[end1] != ' ')
{
str[end2--] = str[end1--];
}
else
{
str[end2--] = '0';
str[end2--] = '2';
str[end2--] = '%';
end1--;
}
}
}
};
版权声明
本文为[_ Qiqi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220242425792.html
边栏推荐
- Delphi自动适应屏幕大小
- Five cool login pages that can be used
- Development management · Huawei IPD
- The interface needs to be forward compatible. If it is incompatible, open V2 interface
- C pointer and array depth summary
- STM32 CAN通信实验
- Eight common probability distribution formulas and visualization
- 【小杨带你玩转C语言】循环结构(详解篇)
- Development details of swap exchange arbitrage clip robot system
- Verse protocol: a wonderful idea to optimize NFT liquidity
猜你喜欢

Softmax operation

Notes: Sword finger offer 04 Search in two-dimensional array -- an error report

Or1k startup file analysis

二叉排序树基本性质详解

Quick start NFT from technical principle, mainstream platform and market prospect

(进阶)C函数调用

How to restrict the unity of code

Detailed explanation of basic properties of binary sort tree

Complete solution of closure operation in Discrete Mathematics

Wu Enda's machine learning assignment -- Logical Regression
随机推荐
Will you "sell" SQL?
[timing] dcrnn: a spatiotemporal prediction network for traffic flow prediction combining diffusion convolution and GNN
金融信息安全实训——22/4/19(上)
MySQL的深入学习
使用navicat将mangodb的数据做转储
Basic commands and practice of DOS command line
二叉排序树基本性质详解
谁有CDMA手机的AT指令集啊?连电脑遇到的奇怪问题。[email protected]
离散数学(Closure operation)闭包运算全解
Analysis on the development status of meta universe
Excel tips - automatically fill adjacent cells
Training set: alexnet classification
【时序】DCRNN:结合扩散卷积和GNN的用于交通流量预测的时空预测网络
All primes - ladder training competition
Development details of swap exchange arbitrage clip robot system
MODEM拨号放音,原来写在大富翁,汇总过来。
STM32 can communication experiment
Share price plummeted Robinhood acquired British encryption company for expansion
循环链表的创建及可控输出
Excel tips - vlookup automatic matching