TIL day 35

2025. 2. 7. 11:14·TIL

1. C++ 과제


오늘 오전에는 코딩테스트 대신 알고리즘 수업 과제를 풀었습니다.

  • 과제 목적 : 온라인 학습 관리 시스템 구현
  • 개요
    • 2개 이상의 STL 사용하기
    • 실용적인 프로그램 작성 (적합한 컨테이너 사용하기)
  • 구현해야할 내용
    • 성적 추가 기능
      • 학생 ID(int), 과목명(string), 점수(int) 를 저장
      • 한 학생이 여러 과목 수강 가능
      • 동일 학생의 동일 과목 입력시 최신 점수로 갱신
      • 0~100까지가 점수의 유효 범위 (미완) 해결
    • 성적 조회 기능
      • 학생의 모든 과목 성적 출력
      • 과목명 정렬
      • 존재하지 않는 ID 예외처리
    • 전체 학생 평균 출력
      • 과목별 평균 점수 출력 -> 중복 제거
      • 소수점 둘째자리 출력
    • 과목별 최고 점수 학생 조회
      • 동점자 있을 경우 ID 오름차순 정렬해서 출력 (미완)해결
    • 추가 구현
      • 성적 구간 검색
      • 과목별 통계
  • 코드
#include <iostream>
#include <unordered_map>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

int n;
int q1, q2;

//id로 찾기
map<int, map<string, int>> student; //id, name, score

//과목명으로 찾기
map <string, map<int, int, greater<int>> > scores; //name, id, score (ID 중복값 없애기 위한 순서)

int main()
{
	cout << "입력할 성적의 수: ";
	cin >> n;

	while (n--)
	{
		int id;
		string name;
		int score;

		cout << "id, 과목명, 점수 순서로 입력: ";
		cin >> id >> name >> score;
		
		//점수 예외 처리
		if (score < 0 || score > 100)
		{
			cout << "잘못된 점수 입력\n";
			continue;
		}

		student[id][name] = score;		
		scores[name][id] = score;
	}

	cout << "\n\n조회할 학생 수 : ";
	cin >> q1;

	while (q1--)
	{
		int id;
		cout << "학생 ID 입력: ";		
		cin >> id;

		//예외 처리
		if (student.find(id) == student.end())
		{
			cout << "없는 학생입니다.\n";
			continue;
		}

		cout << "학생 " << id << "의 점수:\n";
		for (const auto& it : student[id])
		{
			cout << it.first << ": " << it.second << "점\n";
		}
		cout << "\n";
	}

	cout << "\n\n전체 평균 점수 출력:\n";
	for (auto& [key, value] : scores) //과목명, map
	{
		float total = 0;
		int cnt = 0;

		auto temp = scores[key];
		for (auto it = temp.begin(); it != temp.end(); ++it) //id, value 순서
		{
			total += it->second;
			cnt++;
		}
		cout << fixed;
		cout.precision(2);
		cout << key << ": " << total / (float)cnt << "점\n";
	}

	cout << "\n\n조회할 강의 수: ";
	cin >> q2;

	while (q2--)
	{
		string name;
		cout << "과목명 입력: ";
		cin >> name;

		if (scores.find(name) == scores.end())
		{
			cout << "없는 과목명입니다.\n";
			continue;
		}
	
		//가장 높은 점수 찾기
		int maxScore = -1;
		for (const auto& it : scores[name])
		{
			maxScore = max(maxScore, it.second);
		}

		//가장 높은 점수 id 찾기
		vector<int> ids;
		for (const auto& it : scores[name])
		{
			if (it.second == maxScore)
			{
				ids.push_back(it.first);
			}
		}
		//id 정렬(오름차순)
		sort(ids.begin(), ids.end());

		cout << name << "최고점수: " << maxScore << "점\n";
	
		for (const auto& it : ids)
		{
			cout << "학생 ID: " << it << "\n";
		}
	}

	//성적 구간 검색
	{
		cout << "\n\n구간 검색을 위한 과목명 입력: ";
		string name;
		cin >> name;

		if (scores.find(name) == scores.end())
			cout << "없는 과목입니다\n";
		else
		{
			int st, en;
			cout << "검색하고 싶은 최소 구간, 최대 구간 입력:";
			cin >> st >> en;

			vector<int> ids;
			for (const auto& it : scores[name])
			{
				if (it.second >= st && it.second <= en)
					ids.push_back(it.first);
			}
			sort(ids.begin(), ids.end());
			cout << st << " 에서 " << en << " 사이 점수를 가진 ";
			cout << "학생 목록: ";
			for (const auto& it : ids)
				cout << it << " ";
		}		
	}

	//과목별 통계
	{
		string name;
		int minScore = INT_MAX;
		int maxScore = INT_MIN;
		int total = 0;
		float size = 0;
		cout << "\n\n성적 통계를 원하는 과목 입력: ";
		cin >> name;

		if (scores.find(name) == scores.end())
			cout << "없는 과목입니다\n";

		for (const auto& it : scores[name])
		{
			minScore = min(minScore, it.second);
			maxScore = max(maxScore, it.second);
		}
		auto temp = scores[name];
		for (auto it = temp.begin(); it != temp.end(); ++it) //id, value 순서
		{
			total += it->second;
			size++;
		}

		cout << fixed;
		cout.precision(2);
		cout << name << " 과목의 최고/최저: " << maxScore << " / " << minScore << " / " << (float)total / size << "\n";
		cout << "평균 점수/수강인원: " << total / size << " / " << (int)size << "\n";
	}
}

 

 

2. 언리얼 공부


오늘은 아이템 스폰과 아이템 획득 (캐릭터와 아이템의 연동) 시스템에 대해 공부해 보았습니다.

https://gbleem.tistory.com/68

 

Unreal Engine - 아이템 스폰 및 캐릭터와 연동

이전에 아이템 생성한 글과 연결되는 글입니다.https://gbleem.tistory.com/66 Unreal Engine - 아이템 만들기 (+충돌 처리)1. 목표게임상에서 캐릭터와 아이템 간의 충돌이 발생하면 특정 이벤트가 발생하도

gbleem.tistory.com

 

'TIL' 카테고리의 다른 글

TIL day 37  (1) 2025.02.11
TIL day 36  (0) 2025.02.10
TIL day 34  (1) 2025.02.06
TIL day 33  (0) 2025.02.05
TIL day 32  (0) 2025.02.04
'TIL' 카테고리의 다른 글
  • TIL day 37
  • TIL day 36
  • TIL day 34
  • TIL day 33
gbleem
gbleem
gbleem 님의 블로그 입니다.
  • gbleem
    gbleem 님의 블로그
    gbleem
  • 전체
    오늘
    어제
    • 분류 전체보기 (184)
      • Unreal Engine (73)
      • C++ (19)
      • 알고리즘(코딩테스트) (27)
      • TIL (60)
      • CS (4)
      • 툴 (1)
  • 블로그 메뉴

    • 홈
    • 카테고리
  • 링크

    • 과제용 깃허브
    • 깃허브
    • velog
  • 공지사항

  • 인기 글

  • 태그

    템플릿
    applydamage
    actor 클래스
    map을 vector로 복사
    DP
    BFS
    Vector
    상속
    싱글턴
    enhanced input system
    cin함수
    motion matching
    매크로 지정자
    const
    blend pose
    addonscreendebugmessage
    character animation
    gamestate
    C++
    additive animation
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
gbleem
TIL day 35
상단으로

티스토리툴바