Algorithm
Problem Name: beecrowd | 2779
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2779
Album of the Cup
By OBI Brasil
Timelimit: 1
In Soccer World Cup year, the official album of cards is always a great success among children and also among adults. For those who do not know, the album contains spaces numbered from 1 to N to paste the cards; each sticker, also numbered from 1 to N, is a small photo of a player from one of the selections that will play the World Cup. The goal is to paste all the cards in the respective spaces in the album, in order to complete the album (that is, leave no space without the corresponding sticker).
The cards are sold in sealed envelopes, so the buyer does not know which cards he is buying, and it may happen that he has bought a card he has already pasted on the album.
To help users, the company that sells the album and stickers wants to create an application that allows them to easily manage the missing pieces to complete the album and is asking for their help.
Given the total number of spaces and stickers in the album, and a list of already purchased cards (which may contain repeated cards), your task is to determine how many cards are missing to complete the album.
Input
The first line contains an integer (1 ≤ N ≤ 100), on total stickers and spaces in the album. The second line contains an integer M (1 ≤ M ≤ 300) from the number of stickers already purchased. Each of the Múrias closed the entire X (1 ≤ X ≤ N), indicating a card already bought.
Output
Your program should produce a single line containing an integer representing the number of missing cards to complete the album.
Input Samples | Output Samples |
10 3 5 8 3 |
7 |
5 6 3 3 2 3 3 3 |
3 |
3 4 2 1 3 3 |
0 |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <set>
using namespace std;
int main()
{
int n, m, x;
cin >> n >> m;
set < int>s;
for (int i = 0; i < m; ++i)
{
cin >> x;
s.insert(x);
}
cout << n-s.size() << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Java Programming
Code -
Java Programming
import java.util.Locale;
import java.util.Scanner;
import java.util.LinkedHashSet;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Locale.setDefault(new Locale("en", "US"));
Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); //espa�os numerados de 1 a N
int M = sc.nextInt(); //total de figurinhas ja compradas
Set < Integer> X = new LinkedHashSet();//qual figurinha j� foi comprada
for (int i = 0 ; i < M ; i++)
X.add(sc.nextInt());//n�o aceita repeticao ;-)
System.out.println(N-X.size());
sc.close();
}
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("node:fs")
const [totalFigures, boughtFigures, ...lines] = readFileSync("/dev/stdin", "utf8")
.split("\n")
.map(value => Number.parseInt(value, 10))
function main() {
const figures = lines.slice(0, boughtFigures)
const uniqueFigures = new Set(figures)
console.log(totalFigures - uniqueFigures.size)
}
main()
Copy The Code &
Try With Live Editor
Input
Output