NC222161. ChinoWithClanguage
描述
输入描述
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; }