Submit solution
Points:
1.00 (partial)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Author:
Problem source:
Problem type
Allowed languages
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Cho mảng A[], B[] gồm N và M phần tử, hãy chèn mảng B vào chỉ số P của mảng A và in ra mảng A[] sau khi chèn.
Đầu vào
Dòng 1 gồm N, M và P
Dòng 2 gồm các phần trong mảng A[]
Dòng 3 gồm các phần tử trong mảng B[]
Giới hạn
1<=N<=M<=1000
0<=P<=N
0<=A[i], B[i]<=1000
Đầu ra
In ra mảng A[] sau khi chèn
Ví dụ :
Input 01
3 3 0
1 2 3
4 5 6
Output 01
4 5 6 1 2 3
Input 02
3 3 1
1 2 3
4 5 6
Output 02
1 4 5 6 2 3
Comments
FULL AC
include <bits/stdc++.h>
define speed ios::syncwithstdio(false); cin.tie(nullptr); cout.tie(nullptr);
define ll long long
define db double
using namespace std; int dem[10000001]; int n, m, p; void chen(int a[], int b[]){ int c = n; if(p == 0){ while(c){ a[c + m - 1] = a[c - 1]; c--; } for(int i = 0; i < m; i++) a[i] = b[i]; } else if(p == n - 1) for(int i = n; i < n + m; i++) a[i] = b[i - n]; else{ while(c != p){ a[c + m - 1] = a[c - 1]; c--; } for(int i = p; i < p + m; i++) a[i] = b[i - p]; } } int main() { speed cin >> n >> m >> p; int a[2500], b[2500]; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; chen(a, b); for(int i = 0; i < n + m; i++) cout << a[i] << ' '; return 0; }
include <iostream>
include <iomanip>
include <cmath>
using namespace std;
int main(){ int n,m,p; cin >> n >> m >> p; int a[n],b[m]; for(int i=0;i<n;i++){ cin >> a[i]; } for(int i=0;i<m;i++){ cin >> b[i]; } for(int i=0;i<p;i++){ cout << a[i] << " "; } for(int i=0;i<m;i++){ cout << b[i] << " "; } for(int i=p;i<n;i++){ cout << a[i] << " "; } return 0; }
include <stdio.h>
include <math.h>
int main(){ int n, m, p; scanf("%d%d%d", &n, &m, &p); int a[1001], b[1001]; for(int i = 0; i < n; i++){ scanf("%d", &a[i]); } for(int i = 0; i < m; i++){ scanf("%d", &b[i]); } for(int i = 0; i < n; i++){ if(i == p){ for(int j = 0; j < m; j++){ printf("%d ", b[j]); }
} printf("%d ", a[i]);
} if(p == n){ for(int j = 0; j < m; j++){ printf("%d ", b[j]); } } }
include <bits/stdc++.h>
define N 1005
define M 1005
using namespace std; int a[N]; int b[M]; int main() { int n, m, p; cin >> n >> m >> p; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } for (int i = 0; i < n; i++) { if (i == p) { for (int j = 0; j < m; j++) { cout << b[j] << " "; } } cout << a[i] << " "; } if(p==n) { for (int i=0;i<n;i++) cout << b[i] << " "; } cout << endl; return 0; } cho newbie tham khảo(code dễ hiểu)
lưu ý: khi chèn vào thì chỉ số của mảng a tăng m giá trị, mảng b ở vị trí của chỉ số p c
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
p==n
This comment is hidden due to too much negative feedback. Show it anyway.
include <stdio.h>
include <math.h>
int main(){ int n,m,p; scanf("%d%d%d",&n,&m,&p); int a[n],b[m]; for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<m;i++) scanf("%d",&b[i]); for(int i=0;i<n;i++){ if(p==i){ for(int j=0;j<m;j++){ printf("%d ",b[j]); } } printf("%d ",a[i]); } }
Anh Chị ơi, có thể chỉ giúp em sai chỗ nào được không ạ? em không biết em sai ở đâu mà vẫn còn sai 1 testcase ạ.
include<stdio.h>
int main(){ int n,m,p; scanf("%d %d %d", &n, &m, &p); int a[n+m]; int b[m]; for(int i=0;i<n;i++) { scanf("%d", &a[i]); } for(int i=0;i<n;i++) { scanf("%d", &b[i]); } for(int i=n-1;i>=p;i--) { a[i+m]=a[i]; }
}
ơ kè chơi bửn
This comment is hidden due to too much negative feedback. Show it anyway.