4 条题解
-
1
#include <bits/stdc++.h> using namespace std; int main() { //1.用向量输入 vector<int> v; int n,y; cin >> n; for (int i = 1;i <= n;i++) { int t; cin >> t; v.push_back(t); } cin >> y; //2.找最大值的送代器 vector<int>::iterator maxj = v.begin(); for (vector<int>::iterator it = v.begin();it != v.end();it++) { if (*maxj <= *it) { maxj = it; } } //3.插入 v.insert(maxj + 1,y);//注意不要写成v.insert(maxj,y); //4.输出 for (int i = 0;i < v.size();i++) { cout << v[i] << " "; } return 0; }
-
1
很简单的题目👀️上代码🎉️
#include <bits/stdc++.h> using namespace std; int main() { int n , a[100] , y , maxx = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > maxx) maxx = a[i];//最大数值 } cin >> y; for (int i = 0; i < n; i++) { cout << a[i] << " ";//先输出数组中的数 if (a[i] == maxx) cout << y << " ";//如果是最大数,在后面插入y } return 0; }
AC,放心食用
-
0
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n; int a[n + 1]; cin >> a[1]; int maxx = a[1]; for (int i = 2; i <= n; i++) { cin >> a[i]; maxx = max(maxx, a[i]); } cin >> x; for (int i = 1; i <= n; i++) { cout << a[i] << " "; if (a[i] == maxx) { cout << x << " "; } } return 0; }
-
0
#include<bits/stdc++.h> using namespace std; int a[110],n,p,ma = INT_MIN,y,i; int main() { cin >> n; //找出最大数的下标 for(i = 1; i <= n; i++){ cin >> a[i]; if(a[i] > ma){ ma = a[i]; p = i; } } cin >> y; //从最大的数开始所有的数后移一位 for(i = n; i > p; i--){ a[i+1] = a[i]; } //插入这个数 a[i+1] = y; n++; //输出结果 for(i = 1; i <= n; i++) cout << a[i] << " "; return 0; }
- 1
信息
- ID
- 214
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 1
- 标签
- 递交数
- 68
- 已通过
- 48
- 上传者