2021 ICPC新疆省赛 K - chino with c language(水题)

In C language, there are two functions for copying arrays, memcpy and
memmove

. These two C language functions have a same purpose is copying the
contents of a certain section of memory to a section of memory in
units of bytes.

The difference between these two functions is that memcpy

does not check whether the source address range and the destination
address range in memory have overlapping parts. It follows the logic
of copying each byte sequentially from left to right, so that can
cause the data copied is not equal to original data.

When using the memmove function, if the source address range and the
destination address range have overlapping part, memmove

will do special processing to ensure that the memory of the
destination address range is filled with original data.

Now suppose that both the memcpy and memmove function calls require
three parameters, p1,p2,l, which respectively represent the source
address, destination address, and the number of bytes copied. For
example, given a string “abcdefg”, if you call memcopy(1,3,5), the
result will be “abababa”, if you call memmove(1,3,5)

, the result will be It is “ababcde”.

Now give you a string S, and three call parameters, p1,p2,l . Please
tell Chino what the calling results of memcopy and memmove

respectively are. Input

The first line of input data contains only a positive integer n(1≤n≤105)

indicates the length of the string.

The second line of input data contain a string S of length n. S
includes only lowercase English letters.

The third line of input data contain three integers
p1,p2,l(1≤p1,p2,l≤n)

And guarantee 1≤p1+l−1,p2+l−1≤n

represents the parameters of calling two functions . Output

Please output two lines, the first line represents the result of calling the memcopy function, the second line represents the result of

calling memmove

.  Example
Input

7
abcdefg
1 3 5

Output

abababa
ababcde

思路

看懂题就能过,按照题目模拟两种拷贝方式,一种是从左至右边覆盖边拷贝,另一种要求不能覆盖,需要拷贝原始数据。

#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005;
char s[MAXN],t[MAXN];
int n,p1,p2,l;
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    strcpy(t+1,s+1);
    scanf("%d %d %d",&p1,&p2,&l);
    for(int i=0;i<l;i++)t[p2+i]=s[p1+i];//还是按照原来的进行复制
    for(int i=0;i<l;i++)s[p2+i]=s[p1+i];//直接覆盖
    printf("%s\n%s\n",s+1,t+1);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值