Notice
Recent Posts
Recent Comments
Link
알고리즘 모음(C++)
백준 5597 - 과제 안 내신 분..?(C++) 본문
문제 링크입니다. https://www.acmicpc.net/problem/5597
배열을 이용해 푸는 문제입니다.
28명의 학생 출석번호를 입력받고, 빠진 2명이 누구인지 구하는 문제입니다.
배열을 이용하여, 배열에 값을 저장하는 방식으로 풀면 됩니다.
입력받은 학생은 존재한다는 의미이니, 해당 칸에 1의 값을 넣어줍니다.
마지막에 1~30까지 칸을 확인할 때, 0인 칸이 있다면 빠진 학생이라는 것이 됩니다.
자세한 것은 코드를 참고해주세요
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <deque>
#include <stack>
#include <map>
#define pp pair<int, int>
#define F first
#define S second
using namespace std;
int arr[31];
int main() {
cin.tie(0);
cout.tie(0);
for(int i = 1; i <= 28; i++){
int x;
cin >> x;
arr[x] = 1;
}
for(int i = 1; i <= 30; i++){
if(arr[i] == 0) cout << i << "\n";
}
return 0;
}
질문 및 조언은 댓글을 남겨주세요
'백준' 카테고리의 다른 글
백준 17386 - 선분 교차 1(C++) (0) | 2023.02.01 |
---|---|
백준 2166 - 다각형의 면적(C++) (0) | 2023.02.01 |
백준 10807 - 개수 세기(C++) (0) | 2023.01.31 |
백준 7453 - 합이 0인 네 정수(C++) (0) | 2023.01.28 |
백준 11652- 카드(C++) (0) | 2023.01.28 |