C language ALDS1_4_A Linear Search

problem

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_A&lang=jp

code

#include <stdio.h>

int search(int A[], int N, int key)
{
    int i = 0;
    A[N] = key;

    while (A[i] != key)
        i++;
    return (i != N);
}

int main(void)
{
    int N, Q, i, key;
    int S[10000 + 1];
    int count = 0;

    scanf("%d", &N);
    for (i = 0; i < N; i++)
        scanf("%d", &S[i]);

    scanf("%d", &Q);
    for (i = 0; i < Q; i++)
    {
        scanf("%d", &key);
        if (search(S, N, key))
            count++;
    }
    printf("%d\n", count);

    return 0;
}

point

--Linear search using guards

Impressions

--It took too much time

Time required: 40 minutes

Recommended Posts

C language ALDS1_4_A Linear Search
C language ALDS1_4_B Binary Search
[C language algorithm] Binary search tree
C language ALDS1_3_B Queue
Linear search in Python
[C language algorithm] Endianness
[C language algorithm] Block movement
Machine language embedding in C language
Heapsort made in C language
Binary search in Python / C ++
[C language] readdir () vs readdir_r ()
Multi-instance module test in C language
Function pointer and objdump ~ C language ~
Writing C language with Sympy (metaprogramming)
Introduction to Protobuf-c (C language ⇔ Python)
Master linear search! ~ Python implementation version ~
C language 8 queens problem solving 3 patterns
Segfault with 16 characters in C language
Call c language from python (python.h)