题解 | #字符串链接#

字符串链接

https://www.nowcoder.com/practice/9f27c74ec91e4c7da96ba351dba235fc

注意!不要忘记加上字符串结束符'\0'

#include <iostream>
using namespace std;
# define N 1000
void MyStrcat(char dstStr[],char srcStr[]){
    char *p = dstStr;
    char *q = srcStr;
    while (*p != '\0'){
        p++;
    }
    while (*q != '\0'){
        *p++ = *q++;
    }
    *p = '\0';	//不要忘记加上字符串结束符'\0'
}
int main() {
    char str1[N],str2[N];
    while (cin >> str1 >> str2) { // 注意 while 处理多个 case
        MyStrcat(str1, str2);
        cout << str1 << endl;
        //cout << str2 << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

头发暂时没有的KFC总裁:找廉价劳动力罢了
点赞 评论 收藏
分享
2024-12-21 18:48
西安邮电大学 C++
黑皮白袜臭脚体育生:按使用了什么技术解决了什么问题,优化了什么性能指标来写会更好另外宣传下自己的开源仿b站微服务项目,GitHub已经390star,牛客上有完整文档教程
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务