ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

Help me, please! What is wrong? c++
Posted by Koloskova Mariia 10 Jul 2018 20:15
#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++
Posted by David Espinoza 27 Dec 2018 23:36
Each date is a positive integer not exceeding 10^9, long long int teacher[], student[]
Re: Help me, please! What is wrong? c++
Posted by Name 28 Nov 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;
}