列表

详情


NC222161. ChinoWithClanguage

描述

In C language, there are two functions for copying arrays, and . 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 .

The difference between these two functions is that 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 sequentially from left to right, so that can cause the data copied is not equal to original data.

When using the function, if the source address range and the destination address range have overlapping part, will do special processing to ensure that the memory of the destination address range is filled with original data.

Now suppose that both the and function calls require three parameters, p_1, p_2, l, which respectively represent the source address, destination address, and the number of bytes copied. For example, given a string , if you call , the result will be , if you call , the result will be It is .
Now give you a string , and three call parameters, p_1, p_2, l. Please tell Chino what the calling results of and respectively are.

输入描述

The first line of input data  contains only a positive integer  indicates the length of the string. 
The second line of input data contain a string of length includes only lowercase English letters.
The third line of input data contain three integers
And guarantee represents the parameters of calling two functions .

输出描述

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

示例1

输入:

7
abcdefg
1 3 5

输出:

abababa
ababcde

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Python3 解法, 执行用时: 70ms, 内存消耗: 9484K, 提交时间: 2021-10-04 20:55:24

n = int(input())

s = input()

p1, p2, l = map(int, input().split())

ss = list(s)
for i in range(l):
    ss[i + p2 - 1] = ss[i + p1 - 1]
    
print(''.join(ss))

s = list(s)
# print(s)
# print(s[p2 - 1: p2 + l - 1])
# print(s[p1 - 1: p1 + l - 1])
s[p2 - 1: p2 + l - 1] = s[p1 - 1: p1 + l - 1]
if len(s) > n:
    s = s[:n]

print(''.join(s))

C++ 解法, 执行用时: 7ms, 内存消耗: 760K, 提交时间: 2021-05-23 22:52:23

#include <iostream>
using namespace std;
int main ()
{
	int n,a,b,c,i;
	char s[100010],t[100010];
	cin>>n>>s+1>>a>>b>>c;
	for(i=1;i<=n+1;i++) t[i]=s[i];
	for(i=0;i<c;i++) t[b+i]=s[a+i];
	for(i=0;i<c;i++) s[b+i]=s[a+i];
	cout<<s+1<<"\n"<<t+1<<"\n";
	return 0;
}

上一题