Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1471

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1471

Dangerous Dive

 

Maratona de Programação da SBC Brasil

Timelimit: 1

The recent earthquake in Nlogonia did not affect too much the buildings in the capital, which was at the epicenter of the quake. But the scientists found that it affected the dike wall, which now has a significant structural failure in its underground part that, if not repaired quickly, can cause the
collapse of the dike, with the consequent flooding the whole capital.

The repair must be done by divers, at a large depth, under extremely difficult and dangerous conditions. But since the survival of the city is at stake, its residents came out in large numbers to volunteer for this dangerous mission.

As is traditional in dangerous missions, each diver received at the start of his/her mission a small card with an identification number. At the end of their mission, the volunteers returned the nameplate, placing it in a repository.

The dike is safe again, but unfortunately it seems that some volunteers did not return from their missions. You were hired for the grueling task of, given the plates placed in the repository, determine which volunteers lost their lives to save the city.

 

Input

 

The input contains several test cases and ends with EOF. Each test case is composed of two lines. The first line contains two integers N and R ( 1 ≤ RN ≤ 104), indicating respectively the number of volunteers that went to the mission and the number of volunteers that returned from the mission. Volunteers are identified by numbers from 1 to N. The second line contains R integers, indicating the volunteers which returned from the mission (at least one volunteer returned).

 

Output

 

For each test case your program must produce a single line containing the identifiers of the volunteers who did not return from their missions, in ascending order of their identifications. Leave a blank space after each identifier (notice that, therefore, there must be a blank space after the last identifier in the line). If every volunteer returned, the line must contain a single character ‘*’ (asterisc).

 

 

 

Sample Input Sample Output

5 3
3 1 5
6 6
6 1 3 2 5 4

2 4
*

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void) {
    int n, r, i, x, q;
    int v[1000];

    while (scanf("%d %d", &n, &r) == 2) {
        for (i = 0; i  <  n; ++i)
            v[i] = i+1;
        for (i = 0; i  <  r; ++i) {
            scanf("%d", &x);
            v[x-1] = 0;
        }
        q = 0;
        for (i = 0; i  <  n; ++i)
            if (v[i] != 0) {
                ++q;
                printf("%d ", v[i]);
            }
        if (q == 0) printf("*");
        printf("\n");
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5 3
3 1 5
6 6
6 1 3 2 5 4

Output

x
+
cmd
2 4
*

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

using namespace std;

int main(void) {
    int n, r, i, x, q;
    int v[1000];

    while (cin >> n >> r) {
        for (i = 0; i  <  n; ++i)
            v[i] = i+1;
        for (i = 0; i  <  r; ++i) {
            cin >> x;
            v[x-1] = 0;
        }
        q = 0;
        for (i = 0; i  <  n; ++i)
            if (v[i] != 0) {
                ++q;
                cout << v[i] << " ";
            }
        if (q == 0) cout << "*";
        cout << endl;
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5 3
3 1 5
6 6
6 1 3 2 5 4

Output

x
+
cmd
2 4
*

#3 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        n = int(str(input()).split()[0])
        e = [int(x) for x in str(input()).split()]
        v = []
        for i in range(1, n+1):
            if not i in e: v.append(i)
        if len(v) == 0: print('*')
        else:
            for j in v:
                print(j, end=' ')
            print()
    except EOFError: break
Copy The Code & Try With Live Editor

Input

x
+
cmd
5 3
3 1 5
6 6
6 1 3 2 5 4

Output

x
+
cmd
2 4
*
Advertisements

Demonstration


Previous
#1467 Beecrowd Online Judge Solution 1467 Zero or One Solution in C, C++, Java, Js and Python
Next
#1472 Beecrowd Online Judge Solution 1472 Triangles Solution in C, C++, Java, Js and Python