|
|
вернуться в форумHelp me, please! What is wrong? c++ #include <iostream> using namespace std; int main() { int n,m,teacher[1500],student[100000],same=0; cin>>n; for(int i=0;i<n;i++) cin>>teacher[i]; cin>>m; for(int i=0;i<m;i++) cin>>student[i];
for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(teacher[i]==student[j]) same++;
cout<<same; return 0; }
Re: Help me, please! What is wrong? c++ Each date is a positive integer not exceeding 10^9, long long int teacher[], student[] Re: Help me, please! What is wrong? c++ Послано Name 28 ноя 2019 01:42 #include <bits/stdc++.h> using namespace std; #define ll long long int main(){ int n1, n2; cin >> n1; vector <int> m1; vector <int> m2; m1.resize(n1); for (int i = 0; i < m1.size(); i++) cin >> m1[i]; cin >> n2; m2.resize(n2); for (int i = 0; i < m2.size(); i++) cin >> m2[i]; int sum = 0; sort(m1.begin(), m1.end()); for (int i = 0; i < m2.size(); i++){ if (binary_search(m1.begin(), m1.end(), m2[i])) sum ++; } cout << sum; return 0; } |
|
|