NC216212. No114514
描述
输入描述
The first line of the input contains an integer , denoting the length of the sequence.
The second line of the input contains Integers , it's guaranteed that .
输出描述
You should print numbers in one line, denoting the sequence after your operations.
We have proof that a solution always exists. If there are multiple solutions, print any.
End-of-line spaces are allowed in this problem. You can output with or without end-of-line spaces.
示例1
输入:
7 1 1 1 4 5 1 4
输出:
1 4 1 4 5 1 4
C(clang11) 解法, 执行用时: 36ms, 内存消耗: 1532K, 提交时间: 2020-12-26 15:12:17
#include<stdio.h> main() { int n; scanf("%d",&n); int a[n];int i; for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<=n-6;i++) { if(a[i]==1&&a[i+1]==1&&a[i+2]==4&&a[i+3]==5&&a[i+4]==1&&a[i+5]==4) a[i+2]=5; } for(i=0;i<n;i++) { printf("%d ",a[i]); } }
C++(clang++ 11.0.1) 解法, 执行用时: 429ms, 内存消耗: 1612K, 提交时间: 2023-08-05 14:15:12
#include<iostream> using namespace std; const int N=2e5+5; int a[N]; int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; if(i>=6&&a[i]==4&&a[i-1]==1&&a[i-2]==5&&a[i-3]==4&&a[i-4]==1&&a[i-5]==1)a[i]=5; cout<<a[i]<<" "; } }
Python3(3.9) 解法, 执行用时: 106ms, 内存消耗: 6024K, 提交时间: 2020-12-26 15:26:05
n,s=input(),''.join(e for e in input().split()) t = s.find('114514') for e in s.replace('114514','111514'): print(e,end=' ')