ComputerScience/Coding Test
백준 5597번: 과제 안 내신 분..?
VirtualDever
2022. 11. 10. 06:03
다른 사용자가 제출한 코드를 보면 간결하다.
반면, 내가 짠 코드는 너무 길다.
using System;
class Program
{
static void Main(string[] args)
{
int[] studentsArray = new int[30];
for (int i = 0; i < studentsArray.Length - 2; i++)
{
string stringStudentID = Console.ReadLine();
int studentId = System.Convert.ToInt32(stringStudentID);
studentsArray[i] = studentId;
}
bool[] hasArrays = new bool[30];
for (int i = 0; i < hasArrays.Length; i++)
{
hasArrays[i] = false;
}
for (int i = 1; i < 31; i++)
{
for (int j = 0; j < studentsArray.Length - 2; j++)
{
if (i == studentsArray[j])
{
hasArrays[i - 1] = true;
}
}
}
int notAttendedA = -1;
int notAttendedB = -1;
for (int i = 0; i < hasArrays.Length; i++)
{
if (hasArrays[i] == false)
{
if (notAttendedA == -1)
{
notAttendedA = i + 1;
}
else if (notAttendedB == -1)
{
notAttendedB = i + 1;
}
}
}
if (notAttendedA > notAttendedB)
{
Console.WriteLine(notAttendedB);
Console.WriteLine(notAttendedA);
}
else
{
Console.WriteLine(notAttendedA);
Console.WriteLine(notAttendedB);
}
}
}
문제 출처
https://www.acmicpc.net/problem/5597
5597번: 과제 안 내신 분..?
X대학 M교수님은 프로그래밍 수업을 맡고 있다. 교실엔 학생이 30명이 있는데, 학생 명부엔 각 학생별로 1번부터 30번까지 출석번호가 붙어 있다. 교수님이 내준 특별과제를 28명이 제출했는데,
www.acmicpc.net