CareerCup Eliminate all ‘b’ and ‘ac’ in an array of characters
来源:互联网 发布:up to date数据库介绍 编辑:程序博客网 时间:2024/04/30 13:49
Eliminate all ‘b’ and ‘ac’ in an array of characters, you have to replace them in-place, and you are only allowed to iterate over the char array once.
Examples:
abc -> ac
ac->''
rbact->rt
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The key point is in-place and iteration once.
int eliminate( char* p){ int deleted = 0; if (! p ) return deleted; while (*p){ if (*p == 'b') deleted++;else if ( ( *p == 'a' ) && ( *(p+1) == 'c')){ deleted += 2; p++;} else if ( deleted > 0 ) *(p-deleted) = *p;p++; } *(p-deleted) = '\0'; return deleted;}
0 0
- CareerCup Eliminate all ‘b’ and ‘ac’ in an array of characters
- CareerCup Fill the array with product of all numbers except the number in that cell
- CareerCup Given an array of (unsorted) integers, arrange them such that a < b > c < d > e... etc.
- CareerCup Sort an array in a special way
- [LinkedIn] Find all triangles in an array
- 442. Find All Duplicates in an Array
- [LeetCode]Find All Duplicates in an Array
- LeetCode Find All Duplicates in an Array
- Leetcode442. Find All Duplicates in an Array
- 442. Find All Duplicates in an Array
- 442. Find All Duplicates in an Array
- Find All Duplicates in an Array
- 442. Find All Duplicates in an Array
- Leetcode Find All Duplicates in an Array
- Find All Numbers Disappeared in an Array
- Find All Numbers Disappeared in an Array
- 442. Find All Duplicates in an Array
- [Leetcode] Find All Duplicates in an Array
- delphi 7编写的代码查看编辑器对注释的着色
- Opencv鼠标绘图程序
- 点双连通模版 求割点,点双缩点
- Rtmp协议简单分析(二)——协议交互过程
- 在VirtualBox中安装QTP10破解报CRC ERROR!
- CareerCup Eliminate all ‘b’ and ‘ac’ in an array of characters
- IOCP完成端口资料整理——"高大上",够全,够详细
- JavaMailSendTest
- Opencv轮廓检测
- innerText
- 集训记录
- JavaMailHtmlSendTest
- 1197 约瑟夫问题
- PCA-SIFT特征分析(提升篇)