회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
반례를 부탁드립니다 ㅠㅜㅜ
2108번 - 통계학
sangjin256
4년 전
0
질문검색게시판의 6페이지정도까지의 반례는 넣어봤는데 다 맞았다고 뜹니다 ㅠㅜ 어디서 틀린지 모르겠습니다 부탁드립니다!!
using System; class Statistic{ static int[] arr; static int sum = 0; public static void Main(string[] args){ int n = int.Parse(Console.ReadLine()); arr = new int[n]; for(int i = 0; i < n; i++){ arr[i] = int.Parse(Console.ReadLine()); sum += arr[i]; } Array.Sort(arr); Console.WriteLine(Arith()); Console.WriteLine(Mid()); Console.WriteLine(Mode()); Console.WriteLine(Range()); } public static int Arith(){ return (int)Math.Round(sum/(double)arr.Length, MidpointRounding.AwayFromZero); } public static int Mid(){ return arr[arr.Length/2]; } //최빈값이 영어로 mode public static int Mode(){ if(arr.Length == 1) return arr[0]; //0번째 자리값으로 전부 초기화해준다. int maxCount = 1; int maxIndex = 0; int count = 0; //최다 빈도 횟수가 중복되는지 체크 int sameMax = 0; for(int i = 1; i < arr.Length; i++){ if(arr[maxIndex] != arr[i]){ count++; } else{ maxCount++; } if(maxCount <= count){ if(maxCount == count){ sameMax++; if((i+1) < arr.Length && arr[i+1] != arr[i]) count = 0; } else{ sameMax = 0; maxCount = count; maxIndex = i; count = 0; } } } if(sameMax != 0){ int j = maxIndex; while(true){ if(arr[maxIndex] != arr[j]) break; j++; } return arr[j]; } else return arr[maxIndex]; } public static int Range(){ if(arr.Length == 1) return 0; return arr[arr.Length-1] - arr[0]; } }
댓글을 작성하려면
로그인
해야 합니다.
sangjin256 4년 전
질문검색게시판의 6페이지정도까지의 반례는 넣어봤는데 다 맞았다고 뜹니다 ㅠㅜ 어디서 틀린지 모르겠습니다 부탁드립니다!!