K. chino with c language(水题)
题目大意
memcpy不检查源地址和目标地址是否有重叠
memmove考虑重叠的情况
具体区别以及代码
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
char s[maxn], t[maxn];
void solve()
{
int n,l,p1,p2;
cin >> n >> s + 1 >> p1 >> p2 >> l;
memcpy(t + 1, s + 1, n * sizeof(char));
memmove(t + p2, t + p1, l * sizeof(char));
for (int i = 0; i < l; ++i) s[p2 + i] = s[p1 + i];
cout << s + 1;
cout << endl;
cout <<t + 1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
solve();
return 0;
}
还没有评论,来说两句吧...