Dangerous Dive

Problem E
Dangerous Dive
File: dive.[c|cpp|java]
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 is composed of two lines. The first line contains two integers N and R, 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
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)
在这里插入图片描述

#include <iostream>
using namespace std;
#include <stdio.h>

int f[20000] = {0};

int main() {
    int cases = 0, n, m, sum, x;
    while ((scanf("%d %d", &n, &m)) != EOF) {
        cases++;
        for (int i = 1; i <= m; i++) {
            cin >> x;
            f[x] = cases;
        }
        sum = 0;
        for (int i = 1; i <= n; i++) if (f[i] != cases) {
            sum++;
            cout << i << " ";
        }
        if (sum == 0) cout << "*";
        cout << endl;
    }
}
发布了545 篇原创文章 · 获赞 129 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_43838785/article/details/104155569
今日推荐