Cracking The Coding Interview 1.5
//原文:
//
// Write a method to replace all spaces in a string with ‘%20’.
//
#include <iostream>
using namespace std;
char* replace(char * str)
{
if (str == NULL)
{
return NULL;
}
int size = strlen(str);
char *tem = new char[size+1];
int i = 0;
int num = 0;
while(str[i]!='\0')
{
if (str[i] == ' ')
{
num++;
}
tem[i] = str[i];
i++;
}
tem[i] ='\0'; char *s = new char[size + 1 + 2*num];
int ii=0;
int jj=0;
while(tem[ii]!='\0')
{
if (tem[ii] != ' ')
{
s[jj] = tem[ii];
ii++;
jj++;
}
else
{
s[jj]='%';
s[jj+1]='2';
s[jj+2]='0';
jj += 3;
ii++;
}
}
s[jj]='\0';
return s;
}
int main()
{
char s[] ="i am chinese";
cout<<replace(s)<<endl;
return 0;
}
Cracking The Coding Interview 1.5的更多相关文章
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- Cracking the Coding Interview(Stacks and Queues)
Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- 《Cracking the Coding Interview》——第13章:C和C++——题目6
2014-04-25 20:07 题目:为什么基类的析构函数必须声明为虚函数? 解法:不是必须,而是应该,这是种规范.对于基类中执行的一些动态资源分配,如果基类的析构函数不是虚函数,那么 派生类的析构 ...
- 《Cracking the Coding Interview》——第5章:位操作——题目7
2014-03-19 06:27 题目:有一个数组里包含了0~n中除了某个整数m之外的所有整数,你要设法找出这个m.限制条件为每次你只能用O(1)的时间访问第i个元素的第j位二进制位. 解法:0~n的 ...
- 二刷Cracking the Coding Interview(CC150第五版)
第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...
- 《Cracking the Coding Interview 》之 二叉树的创建 与 遍历(非递归+递归version)
#include <iostream> #include <cstdio> #include <vector> #include <stack> #de ...
随机推荐
- 管家基因 | Human housekeeping genes
管家基因就是在细胞里稳定表达的基因,及时在胁迫状态下,表达的差异也不大. 以前做实验的时候就经常听说管家基因,因为在做RT-PCR的时候需要同时检测管家基因,这样可以用于矫正我们不同批次的结果. Li ...
- Lasso linear model实例 | Proliferation index | 评估单细胞的增殖指数
背景:We developed a cell-cycle scoring approach that uses expression data to compute an index for ever ...
- sql---->sql-summary&mysql-summary
数据库操作: 1.创建数据库,并修改默认字符编码 create database 数据库名 [charset=字符编码]; ee: create database dog charset=utf8; ...
- English trip M1 - PC1 Are you a Model? 你是模特吗? Teacher:Taylor
In this lesson you will learn to talk about jobs. 课上内容(Lesson) What's your partner name? Her name is ...
- You Don't Know JS: this & Object Prototypes (第6章 Behavior Delegation)附加的ES6 class未读
本章深挖原型机制. [[Prototype]]比类更直接和简单! https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%2 ...
- android -------- Data Binding的使用(二)
分享一下Data Binding在项目中一些常用的基础,点击事件和输入框的一些操作. DataBinding允许我们在xml中view的一些事件属性(如onClick等)中填写DataBinding表 ...
- Digital Deletions HDU - 1404
Digital deletions is a two-player game. The rule of the game is as following. Begin by writing down ...
- Redis之下载安装及基本使用
redis window系统的redis是微软团队根据官方的linux版本高仿的 官方原版: https://redis.io/ 中文官网:http://www.redis.cn 1.1 redis下 ...
- Coprime Arrays CodeForces - 915G (数论水题)
反演一下可以得到$b_i=\sum\limits_{d=1}^i{\mu(i)(\lfloor \frac{i}{d} \rfloor})^n$ 整除分块的话会T, 可以维护一个差分, 优化到$O(n ...
- GPLT L2-004 这是二叉搜索树吗?
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805070971912192 类似题目有FBI树 这两个题有个小 ...