一道C机试题目
2013-08-08 20:10
323 查看
题目是这样的
求一个字符串中连续字母的个数
比如I have a book. : 1
I have a dog. : 0
I haavee aa dogg : 4
求一个字符串中连续字母的个数
比如I have a book. : 1
I have a dog. : 0
I haavee aa dogg : 4
#include <windows.h> #include <iostream> using namespace std; void GetDupStringCount( const char* pStr, int &iOut ) { if( !pStr ) return; int iLen = strlen( pStr ); if( !iLen ) return; char cValue = *pStr; int iNumCount = 0;//重复个数 iOut = 0;//设置为0 int iIndex = 0;//当前索引 while( iLen-- ) { if( !( ( cValue >= 'a' && cValue <= 'z' ) || ( cValue >= 'A' && cValue <= 'Z' ) ) ) { cValue = *( pStr + ++iIndex ); iNumCount = 0; continue; } if( cValue == *( pStr + iIndex ) ) { iNumCount++; } else { cValue = *( pStr + iIndex ); if( iNumCount > 1 ) { iOut++; iNumCount = 0; --iIndex; } } iIndex++; } } int main( int argc, char* argv[] ) { char szStr[] = " I haveee a book! "; int iOut = -1; GetDupStringCount( szStr, iOut ); cout << iOut << endl; return 0; }
相关文章推荐
- 华北计算所其中一道机试题,逆转字符串,但是单词顺序不变
- 一道上海交大机试试题解法
- 更深层次分析一道试题——指针内存分配
- 一道表达式的经典试题
- 试题:网易笔试的一道题目
- 关于测试jsp、servlet应用的一道试题
- [转]一道关于继承的工作机制的试题
- 2014年七月华为校招机试题目--最难的一道, 呵呵!
- 一道机试题,拿出来和大家分享一下,稍候贴出我做的代码(C#)
- 一道机试题
- 一道试题引发的血案
- 一道非常简单的java试题收录
- 一道腾讯前端试题,主要是算法
- 补充一道2015年华为校园招聘机试题(字符串处理)
- 更深层次分析一道试题——指针内存分配
- 碰巧看到的一道试题
- 【转】一道SQL SERVER DateTime的试题
- 关于java类初始化过程的一道试题的解析
- 2003年11月系分考试上午试题的一道题目
- Linux 3+1班的一道机试题