#include <iostream>
#include <assert.h>
using namespace std;
//模拟实现strcmp函数。 bool my_strcmp(const char *str1,const char *str2)
{
assert(str1!=NULL && str2!=NULL);
const char *p = str1;
const char *q = str2;
while (*p != '\0' && *q != '\0' && *p == *q)
{
p++;
q++;
}
return (*p - *q)!=0;
}
int main()
{
cout << my_strcmp("liwu", "liu") << endl;
return 0;
} #include <iostream>
#include <assert.h>
using namespace std;
//库函数memcopy的实现。
char *my_memcopy(char *dist, const char *src, int len)
{
assert(dist != NULL && src != NULL);
char *p = dist;
int n = len>(strlen(src)+1) ? strlen(src)+1 : len;
while (n-->0)
{
*dist++ = *src++;
}
return p;
}
int main()
{
char s1[20] = "1234";
my_memcopy(s1,"liuhuiyan",2);
cout << s1 << endl;
} #include <iostream>
#include <assert.h>
using namespace std;
char* my_memove(char *dist,const char* src,int len)
{
assert(dist!=NULL && src!=NULL);
char *p = dist;
const char *q = src; int n = len>(strlen(src) + 1) ? strlen(src) + 1 : len;
if (p <= q || q+n<=p)
{
while (n-- > 0)
{
*p++ = *q++;
}
}
else
{
p += n-1;
q += n-1;
while (n-- > 0)
{
*p-- = *q--;
}
}
return dist;
}
int main()
{
char s1[] = "liu hui yan";
char s2[] = "123 456";
cout << my_memove(s1, s2, 6) << endl;
return 0;
} #include <iostream>
using namespace std;
//一个字符串“student a am i”,现要求将这个字符串改动为“i am a student”。
void exchange(char *p1,char *p2)
{
char temp;
while (p1 < p2)
{
temp = *p1;
*p1 = *p2;
*p2 = temp;
p1++;
p2--;
}
}
char* my_exchange(char *src)
{
char *p = src;
char *q = src;
while (*p != '\0')
{
while (*p != ' ' && *p!='\0')
{
p++;
}
exchange(q,p-1);
if (*p == '\0')break;
p++;
q = p;
}
exchange(src,p-1);
return src;
}
int main()
{
char s[] = "student a am i";
cout << my_exchange(s) << endl;
} //字符串打印数字。
#include <iostream>
#include <assert.h>
using namespace std;
int my_int(const char *str)
{
assert(str!=NULL);
int count = 0;
while (*str != '\0')
{
count = (count * 10 + *str - '0');
str++;
}
return count;
}
int main()
{
char s[] = "12345";
cout << my_int(s) << endl;
return 0;
}
#include <iostream>
using namespace std;
char str[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
//输入数字1234,打印对应的字符串。 void Printf(int x)
{ if (x==0)return;
else
{
Printf(x / 10);
cout << str[x % 10] << endl;
} }
int main()
{
Printf(1234);
return 0;
}

C++字符串操作二的更多相关文章

  1. python 字符串操作二 内建函数

    一.查看字符串的内建函数 >>> dir(str) ['__add__', '__class__', '__contains__', '__delattr__', '__dir__' ...

  2. [Redis-CentOS7]Redis字符串操作(二)

    登录Redis # redis-cli 127.0.0.1:6379> 添加字符串 EX 超期时间60s 127.0.0.1:6379> set username 'leoshi' OK ...

  3. 【二】php 字符串操作及三大流程控制

    字符串操作: trim:去除字符串开始位置和结束位置的空格 ltrim:去除开始处的空格 rtrim:去除结束处的空格 strtoupper:将字符串转换为大写 strtolower:将字符串转换为小 ...

  4. python基础(二)-- 列表、字典、集合、字符串操作

    4.列表: 基本操作: 索引 切片 追加 删除 长度 切片 循环 包含 import copy i=0 #persons=['dailaoban','xiekeng',['age',100,50],' ...

  5. java 字符串操作和日期操作

    一.字符串操作 创建字符串 String s2 = new String("Hello World"); String s1 = "Hello World"; ...

  6. C语言字符串操作总结大全

    1)字符串操作 strcpy(p, p1)  复制字符串  函数原型strncpy(p, p1, n)   复制指定长度字符串  函数原型strcat(p, p1)   附加字符串  函数原型strn ...

  7. c# 字符串操作

    一.字符串操作 //字符串转数组 string mystring="this is a string" char[] mychars=mystring.ToCharArray(); ...

  8. C语言字符串操作总结大全(超详细)

    本篇文章是对C语言字符串操作进行了详细的总结分析,需要的朋友参考下 1)字符串操作  strcpy(p, p1) 复制字符串  strncpy(p, p1, n) 复制指定长度字符串  strcat( ...

  9. linux shell 字符串操作

    转:http://justcoding.iteye.com/blog/1963463 在做shell批处理程序时候,经常会涉及到字符串相关操作.有很多命令语句,如:awk,sed都可以做字符串各种操作 ...

随机推荐

  1. Docker网络基础:快速指南

    Docker网络基础:快速指南 原文连接:http://blogxinxiucan.sh1.newtouch.com/2017/07/30/Docker网络基础:快速指南/ 了解有关扩展网络功能的默认 ...

  2. NOJ——1274The battle of Red Cliff(并查集按秩合并)

    [1274] The battle of Red Cliff 时间限制: 1000 ms 内存限制: 65535 K 问题描述 Zero loves palying Sanguo game very ...

  3. BZOJ 2806 [Ctsc2012]Cheat ——后缀自动机 单调队列优化DP

    先建出广义后缀自动机. 然后跑出文章中每一个位置的最大匹配距离. 然后定义$f[i]$表示匹配到以$i$结尾的串时,最长的匹配距离. 显然可以二分$L$的取值. 然后容易得到$DP$方程 $f[i]= ...

  4. [luoguP3231] [HNOI2013]消毒(最小点覆盖 + 状压)

    传送门 考虑贪心,控制某一维为1,另两位最大是最优的,也就是一次选一个厚度为1的面 那么对于每个点,可以有3种面是可以选到它的 然后gg 考虑二维的状态,一个平面,有些点,一次选一行或一列最优 那么每 ...

  5. TroubleShoot:The context has expired (0×80090317)

    网上搜了一下,服务器上的时间不正确,在SharePoint 设置中,可以通过管理中心设置下Time Zone 和服务器的时间上一致.

  6. hdu 5974 A Simple Math Problem gcd(x,y)=gcd((x+y),lcm(x,y))

    题目链接 题意 现有\[x+y=a\\lcm(x,y)=b\]找出满足条件的正整数\(x,y\). \(a\leq 2e5,b\leq 1e9,数据组数12W\). 思路 结论 \(gcd(x,y)= ...

  7. hdu 5443(线段树水)

    The Water Problem Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  8. LeetCode OJ-- Simplify Path **

    https://oj.leetcode.com/problems/simplify-path/ 对linux路径的规范化,属于字符串处理的题目.细节很多. #include <iostream& ...

  9. C++ 细节知识

    1.typedef struct child {string name;struct child* next;}; child* head; head = (child*)malloc(sizeof( ...

  10. Codeforces 600E Lomsat gelral (树上启发式合并)

    题目链接 Lomsat gelral 占坑……等深入理解了再来补题解…… #include <bits/stdc++.h> using namespace std; #define rep ...