strstr函数与翻转字符串
来源:互联网 发布:人海战术 知乎 编辑:程序博客网 时间:2024/05/21 02:19
//模拟实现strstr函数//
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
const char *my_strstr(const char *str, const char *dest)
{
assert(*str != 0);
assert(*dest != 0);
for (int i = 0; str[i] != '\0'; i++)
{
int tmp = i;
int j = 0;
while (str[i++] == dest[j++])
{
if (dest[j] == '\0')
{
return &str[tmp];
}
}
i = tmp;
}
return NULL;
}
int main()
{
char *s = "bit6661234";
char *d = "612";
printf("%s\n", my_strstr(s, d));
printf("%s\n", strstr(s, d));
system("pause");
return 0;
}
//实现一个函数翻转字符串(将一个字符串的内容,逆序存储)//
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
char* my_reverse(char *dest,const int len)
{
int i = 0;
int j = len - 1;
for (i = 0; i < j; i++, j--)
{
dest[i] ^= dest[j];
dest[j] ^= dest[i];
dest[i] ^= dest[j];
}
return dest;
}
int main()
{
char dest[20] = "welcome to bit";
int len = strlen(dest);
printf("%s\n", my_reverse(dest,len));
system("pause");
return 0;
}
//每瓶汽水1元,两个空瓶可以置换一瓶汽水,现在有20元,最多能喝多少瓶汽水。//
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include<stdlib.h>
int main()
{
int bottle = 20;
int count = 0;
count = bottle;
while (bottle >= 2)
{
count += bottle / 2;
bottle = bottle / 2 + bottle % 2;
}
printf("喝了%d瓶\n", count);
system("pause");
return 0;
}
0 0
- strstr函数与翻转字符串
- PHP 字符串获取 substr 与 strstr 函数
- PHP 字符串获取 substr 与 strstr 函数
- PHP 字符串获取 substr 与 strstr 函数
- 字符串函数strstr
- 字符串函数strstr
- strstr字符串查找函数
- strstr函数[字符串处理]
- 搜索字符串strstr()函数
- [C/C++] 字符串处理函数 strstr 与 strncpy
- strchr与strstr函数
- strchr与strstr函数
- strchr与strstr函数
- 中英文字符串翻转函数
- php 字符串翻转函数
- strstr字符串函数的作用
- 字符串操作函数 strstr 实现
- linux字符串函数strchr strstr
- AngularJS API
- 异步编程之Promise
- 使用html5,css,实现品字形布局
- 重磅!8大策略让你对抗机器学习数据集里的不均衡数据
- Struts+Spring+Hibernate整合入门详解
- strstr函数与翻转字符串
- Ubuntu 安装rabbitvcs
- c++使用luabind示例
- 使用HTML5技术控制电脑或手机上的摄像头
- 求二进制数中1的个数
- redis和memcache
- open系统调用
- CodeForces 534C - Polycarpus' Dice
- iOS errorcode为-1011 问题及解答