字符串
bxyill
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【每日一题】2012.5.27:删除多余的空格-非原创
#include #include #include #include int Remove(char str[]) { if (NULL == str) { return 0; } //删除空格计数 int removeCnt = 0; //扫描头 int i = 0; //当前字符为'\n',new_line为真,初始为真,可去除开头的空格 bool newli转载 2012-05-27 16:58:56 · 1186 阅读 · 0 评论 -
【100题】翻转句子中单词的顺序
#include using namespace std; //翻转一个字符串 void Reverse(char *pBegin,char *pEnd) { if(pBegin == NULL || pEnd == NULL) { return ; } while(pBegin < pEnd) { char temp = *pBegin; *pBegin = *pEnd转载 2012-07-18 18:21:00 · 967 阅读 · 0 评论 -
【100题】找出一个字符串中第一个只出现一次的字符
#include using namespace std; char lmf(char *pString) { if(!pString) { return 0; } //定义并初始化hash表 unsigned int hash[256] = {0}; char *pHashKey = pString; //根据字符串,计数!!! while(*pHashKey !=转载 2012-07-21 15:09:32 · 1018 阅读 · 0 评论 -
字符串查重-玩赖版
//字符串查重,利用set容器的特性 #include #include #include using namespace std; void deleteSame(const char *str) { assert(str != NULL); set s; for(int i=0; str[i] != '\0'; ++i) { s.insert(str[i]); } fo转载 2012-04-24 18:39:26 · 1597 阅读 · 0 评论 -
字符串查找:(第一次)&&(只出现一次的字符)
#include #include using namespace std; void FindChar(string &s) { int str[256]; for(int i=0; i<256; ++i) { str[i] = 0; } for(unsigned int i=0; i<s.size(); ++i) { str[s[i]]++; } for(unsig转载 2012-05-18 07:52:46 · 1045 阅读 · 0 评论 -
【100题】最长公共子串--非连续子串----动态规划
//最长公共子串----动态规划 #include using namespace std; //定义移动的方向 enum decreaseDir { kInit = 0, kLeft, kUp, kLeftUp }; int **LCS_length = NULL; int **LCS_direction = NULL; //根据生产的方向矩阵,来打印出最大公共子串 void L转载 2012-07-28 09:40:11 · 1220 阅读 · 0 评论 -
【100题】左旋转字符串-----整体翻转+局部再次翻转
//使用两次翻转的方法来对付左旋转字符串 //即----字符串的循环左移 #include using namespace std; void ReverseString(char *pStart,char *pEnd) { if(pStart != NULL || pEnd != NULL) { while(pStart <= pEnd) { swap(*pStart,*转载 2012-07-29 09:16:01 · 530 阅读 · 0 评论 -
【C++面试题】:从第一个字符串中去掉第二个字符串中的所有字符
#include using namespace std; #define NUMBER 256 void Delete(char *first, char *second) { int hash[NUMBER]={0}; char *p=second; while(*p) { hash[*p]=1; p++; } char *slow=first; char *fas转载 2012-06-29 17:24:12 · 2282 阅读 · 0 评论 -
【字符串】字符串拷贝和长度
#include #include using namespace std; //字符串长度 int strlen_bxy(const char *str) { assert(str != NULL); int len = 0; while(*str++ != '\0') { ++len; } return len; } //字符串拷贝 char *strcpy_bxy(c转载 2012-08-30 18:04:01 · 1609 阅读 · 0 评论 -
字符串第一个重复出现的字符_超级牛逼的死想
//找出一个字符串中第一个重复出现的字符 //超级牛逼的方法 #include #include #include //memset #include #include #define N 256 char Find(char str[], int n) { char temp[N] = {0}; char dst; //memset((void *)temp,0x00,N*siz转载 2012-04-24 21:08:53 · 3804 阅读 · 0 评论 -
【每日一题】2012.5.27:删除多余空格-非原创-方法2
#include #include #include #include void RemoveExtraSpace(char* str, int len) { assert(len != 0); if(str == NULL) { return; } //当前已经处理好的结果字符串的尾指针 char* result_tail = str; //顺序扫描字符串的每个字符的指转载 2012-05-27 17:00:29 · 1379 阅读 · 0 评论 -
【面试题】最长回文子串
在网上找了几个版本,改编的,好难啊。加油。 //最大回文子串问题 #include #include using namespace std; //返回最长的回文子串 char *Max_SubString_bxy(char *str,int &length) { assert(str != NULL); int n = strlen(str); int len=n; int转载 2012-10-10 08:28:11 · 1128 阅读 · 2 评论 -
2013多玩YY-校招-分割字符串
函数void SplitString(const char *aString,char aSeperator)以aSeperator为分隔符aString拆分打印输出,但注意:当aSeperator存在于“引用的字符串中时,或两个aSeperator在一起时,将不作为分隔符,比如假定分隔符是+时,如下为不同情形下的输出示例: (1)abc+"quoted+quoted"+plus+plus 输原创 2013-05-11 09:52:49 · 3057 阅读 · 2 评论 -
【面试题】:从第一个串中去除第二个串中的字符
题目: 函数原型:void fun(char *str1,const char *str2); 参数:"00+f-988-77+9897" "-+" 输出: 00 f 988 77 9897 NULL 请按任意键继续. . . #include #include #include #include using namespace std; void转载 2012-06-30 10:59:29 · 737 阅读 · 0 评论 -
【每日一题】2012.6.29:全排列问题(非原创)
#include using namespace std; #include //在[nBegin,nEnd)区间中是否有字符与下标为pEnd的字符相等 bool IsSwap(char* pBegin , char* pEnd) { char *p; for(p = pBegin ; p < pEnd ; p++) { if(*p == *pEnd) { return fa转载 2012-06-29 17:14:08 · 766 阅读 · 0 评论 -
【每日一题】2012.5.26:查找字符串中单词的个数
#include using namespace std; int fun(const char *str) { int flag = 0; int count = 0; for(int i=0; str[i] != '\0'; ++i) { if( (str[i]>='a' && str[i] = 'A' && str[i] <= 'Z') ) { if(0 == fl原创 2012-05-27 09:51:04 · 1201 阅读 · 0 评论 -
循环移位
将字符串进行循环移位 abcdefg-----defgabc #include #include #include #define MAX_LEN 100 //方法1 void LoopMove1(char *pStr, int steps) { int n = strlen(pStr)-steps; char tmp[MAX_LEN]; strcpy (tmp, pSt原创 2013-06-07 09:55:23 · 3000 阅读 · 0 评论
分享