5 条题解
-
2
呵呵,好简单,只需要开个变量判断是否到第x个数了,如果到就输出y,不到就正常输出即可
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int n, x, y, a[15]; cin >> n; for(int i=1;i<=n;i++) cin >> a[i]; cin >> x >> y; int ans=0; for(int i=1;i<=n;i++) { ans++; if(ans == x) cout<<y<<" "; cout<<a[i]<<" "; } return 0; }
-
1
这道题可以使用
vector
向量实现快速插入,使用insert
函数,vector
操作函数如下:-
erase
删除元素 -
insert
插入元素 -
pop_back
删除最后一个元素 -
push_back
在最后加入AC代码如下:
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int n,x,y; cin >> n; for (int i = 1;i <= n;i++) { int t; cin >> t; v.push_back(t); } cin >> x; cin >> y; v.insert(v.begin() + x - 1,y); for (int i = 0;i < v.size();i++) { cout << v[i] << " "; } return 0; }
-
-
0
这题挺简单,判断到没到插入位置直接输出就行ㄟ( ▔, ▔ )ㄏ
#include<bits/stdc++.h> using namespace std; int n, m, y; int a[114514]; int main() { cin >> n; for(int i = 1; i <= n; i ++) { cin >> a[i]; } cin >> m >> y; for(int i = 1; i <= n; i ++) { cout << a[i] << " "; if(i + 1 == m) { cout << y << " "; } } return 0; }
- 1
信息
- ID
- 211
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 1
- 标签
- 递交数
- 48
- 已通过
- 41
- 上传者