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

WA#8 - Time limit C++
Posted by vladi 17 Oct 2013 18:19
#include <iostream>
using namespace std;
int main()
{
    int i, j, k = 0, n, m, stud;
    scanf("%d", &n);
    int *prepod = new int[n];
    for (i = 1; i<=n; i++)
    {
        scanf("%d", &prepod[i]);
        if (i>=2)
        {
            if (prepod[i] == prepod[i-1]) prepod[i-1] = -1;
        }
    }
    scanf("%d", &m);
    for (i = 1; i<=m; i++)
    {
        scanf("%d", &stud);
        for (j=1; j<=n; j++)
        {
            if (stud == prepod[j]) k++;
        }

    }
    printf("%d", k);
    return 0;
}

Edited by author 20.10.2013 06:07

Edited by author 20.10.2013 06:08

Edited by author 20.10.2013 06:08
Re: WA#8 - Time limit C++
Posted by vladi 27 Oct 2013 03:39
#include <iostream>
using namespace std;
int main()
{
    int i, j, k = 0, n, m, stud, first = 0, last, temp = 0;
    scanf("%d", &n);
    int *prepod = new int[n];
    for (i = 1; i<=n; i++)
    {
        scanf("%d", &last);
        if (first != last)
        {
            first = last;
            temp++;
            prepod[temp] = last;

        }
    }
    scanf("%d", &m);
    for (i = 1; i<=m; i++)
    {
        scanf("%d", &stud);
        for (j=1; j<=temp; j++)
        {
            if (stud == prepod[j])
            {
                k++;
                break;
            }
        }

    }
    printf("%d", k);
    system("pause");
    return 0;
}