3 条题解
-
0Infinity_ LV 8 @ 2024-08-28 12:18:13
#include<iostream> using namespace std; int a[10010], b[10010]; int main(){ ios::sync_with_stdio(false); int a1, b1; cin >> a1; for(int i = 1; i <= a1; i++)cin >> a[i]; cin >> b1; for(int i = 1; i <= b1; i++)cin >> b[i]; for(int i = 1; i <= a1; i++){ for(int j = 1; j <= b1; j++){ if(a[i] == b[j])cout << a[i] << ' '; } } return 0; }
-
02021-04-01 21:13:37@
#include<iostream> #include<vector> using namespace std; int main() { vector <int> a,b; int na,nb,j,j1;cin>>na; for(int i=0;i<na;i++) { cin>>j; a.push_back(j); } cin>>nb; for(int i=0;i<nb;i++) { cin>>j1; b.push_back(j1); } for(int i=0;i<a.size();i++) for(int j=0;j<b.size();j++) if(a[i]==b[j]) cout<<a[i]<<" "; return 0; }
-
-12019-03-31 13:28:34@
#include <iostream> using namespace std; class SeqList { int a[205], n; public: SeqList() { } void init(int b[], int n) { this->n = n; for (int i = 0; i < n; i++) { a[i] = b[i]; } } int Search(int x) { for (int i = 0; i < n; i++) { if (a[i] == x) return 1; } return -1; } int *Inter(SeqList Lb) { int *b = new int[n + Lb.n]; int index = 0; for (int i = 0; i < n; i++) { if (Lb.Search(a[i]) == 1) { b[index] = a[i]; index++; } } for (int i = 0; i < index; i++) { cout << b[i] << " "; } return b; } void print() { for (int i = 0; i < n; i++) cout << a[i] << " "; } }; int main() { int na; cin >> na; int b[205]; for (int i = 0; i < na; i++) { cin >> b[i]; } SeqList La; La.init(b, na); int nb; cin >> nb; int c[205]; for (int i = 0; i < nb; i++) { cin >> c[i]; } SeqList Lb; Lb.init(c, nb); int *d = new int[na + nb]; d = La.Inter(Lb); return 0; }
- 1
信息
- ID
- 1015
- 难度
- 3
- 分类
- (无)
- 标签
- 递交数
- 325
- 已通过
- 150
- 通过率
- 46%
- 被复制
- 7
- 上传者