文章

14

粉丝

0

获赞

13

访问

548

头像
字符串链接 题解:题目没给字符串长度限制,写麻烦了
P1356 哈尔滨工业大学机试
发布于2026年2月11日 12:04
阅读数 14

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;

char* MyStrcat(char dstStr[],char srcStr[]) {
    int len1 = strlen(dstStr);
    int len2 = strlen(srcStr);
    char *res = new char[len1+len2+1];
    int len  = 0;
    for(int i = 0; i < len1; i++) res[len++] = dstStr[i];
    for(int i = 0; i < len2; i++) res[len++] = srcStr[i];
    res[len] = '\0';
    return res;
}

int main() {
    string str1,str2;
    while(cin >> str1 >> str2) {
        char* dst = new char[str1.length() + 1];
        char* src = new char[str2.length() + 1];
        strcpy(dst, str1.c_str());
        strcpy(src, str2.c_str());
     ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发