본문 바로가기

Algorithm/Code Fights (Code Signal)

CodeSignal Intro Databases #9 GradeDistribution. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면..

CodeSignal Intro Databases #9 GradeDistribution. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접, 데이터베이스, sql, query, 쿼리

 

 

CodeSignal Intro Databases #8

Q.

 At the end of every semester your professor for "Introduction to Databases" saves the exam results of every student in a simple database system. In the database table Grades, there are five columns:

  • Name: the name of the student;
  • ID: the student's ID number (a 5 byte positive integer);
  • Midterm1: the result of the first midterm out of 100 points;
  • Midterm2: the result of the second midterm out of 100 points;
  • Final: the result of the final exam, this time out of a possible 200 points.

 

 매 학기 말마다, 데이터베이스 입문 과목의 교수는 모든 학생들의 시험 결과를 데이터베이스에 저장한다. 테이블은 Grades 이고 5개의 컬럼이 있는데 다음과 같다.

  • Name: 학생의 이름
  • ID: 학생번호 (5바이트 양의정수)
  • Midterm1: 100점 만점의 첫 중간고사 점수
  • Midterm2: 100점 만점의 두번째 중간고사 점수
  • Final: 200점 만점의 기말고사 점수

 

 

According to school policy, there are three possible ways to evaluate a grade:

  • Option 1:
    • Midterm 1: 25% of the grade
    • Midterm 2: 25% of the grade
    • Final exam: 50% of the grade
  • Option 2:
    • Midterm 1: 50% of the grade
    • Midterm 2: 50% of the grade
  • Option 3:
    • Final exam: 100% of the grade.

 학교 정책에 따르면, 학점을 내는 3가지 방법이 있다.

옵션 1 : 중간고사1(25%) + 중간고사2(25%) + 기말고사(50%)

옵션 2 : 중간고사1(50%) + 중간고사2(50%)

옵션 3 : 기말고사(100%)

 

 

 

 Each student's final grade comes from the option that works the best for that student.

As a Teaching Assistant (TA), you need to query the name and id of all the students whose best grade comes from Option 3, sorted based on the first 3 characters of their name. If the first 3 characters of two names are the same, then the student with the lower ID value comes first.

 

 각 학생들의 마지막 학점은 각 학생들에게 가장 좋은 옵션의 점수로 정해진다. 조교로서, name 과 id 를 조회하는데, 옵션3 이 가장 좋은 학생들을 조회하고, 학생들 이름 앞자의 3글자를 오름차순으로 정렬한다.

 

 

 

Example

 

For the following table 

Grades

Name ID Midterm1 Midterm2 Final
David 42334 34 54 124
Anthony 54528 100 10 50
Jonathan 58754 49 58 121
Jonty 11000 25 30 180

 

Output should be

Name ID
David 42334
Jonty 11000
Jonathan 58754

 

For David, Jonty and Jonathan, the best option is number 3. But Anthony's best option is the second one, because Option1 = 25% of 100 + 25% of 10 +50% of 50 = 52.5, Option2 = 50% of 100 + 50% of 10 = 55, Option3 = 100% of 50 = 50.

 

  • [execution time limit] 10 seconds (mysql)

 

 

 

Process

// Process 
//1. Select name and id

//2. From Grades table

//3. In the students who have the best grade in Option 3.

//4. Order by comparing the first 3 char in their names.

 

 

 

// 처리과정

//1. Name 과 ID 를 검색하는데

//2. Grades 테이블에서

//3. 옵션 3 의 결과가 가장 좋은 학생들 중에서

//4. 이름 앞자 3자를 비교해서 오름차순 정렬한다.

 

 

Code.. lemme see example code!!!

코드.. 예제코드를 보자!!!

 

 

/*Please add ; after each select statement*/
CREATE PROCEDURE gradeDistribution()
BEGIN
    SELECT Name, ID FROM Grades 
    WHERE (Final > Midterm1 * 0.25 + Midterm2 * 0.25 + Final * 0.5)
        AND (Final > Midterm1 * 0.5 + Midterm2 * 0.5)
    ORDER BY LEFT(Name, 3) Asc;
END

 

 

Something else you might like...?

 

 

 

2019/10/20 - [Algorithm/Leet Code] - LeetCode #181 EmployeesEarningMoreTheirManagers. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면..

 

 

2019/09/04 - [Programming/C++] - How to sort vector in C++, 벡터 정렬하는 방법,sorting,배열,stl,씨쁠쁠,example code,예제코드,표준라이브러리

 

 

2019/10/09 - [Computer/General] - 정보처리기사 실기/필기 - IT신기술동향_전산영어 요점 정리

2019/10/07 - [Computer/General] - 정보처리기사 실기/필기 - 업무 프로세스 요점 정리

 

 

2019/08/14 - [Life/Item review] - Mi Band 4 review, 미밴드4 후기, 장점, 단점, 리뷰, 한글, global review, 미밴드4 글로벌 후기, 리뷰, 구매, 사용방법, setting, 세팅, ProsNCons

 

 

2019/04/14 - [Programming/C++] - C++ Math - sqrt (square root, 제곱근, 루트). stl, math.h, 씨쁠쁠, example code, 예제코드

 

 

2018/10/19 - [Programming/Design Pattern ] - Design pattern - Prototype (디자인패턴 - 프로토타입) / Java C++ C#

 

 

2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #60 sudoku. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #59 spiralNumbers. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/08 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #58 messageFromBinaryCode. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

 

 

2019/09/17 - [Algorithm/Leet Code] - LeetCode #841 KeysAndRooms. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/08/28 - [Algorithm/Leet Code] - LeetCode #821 ShortestDistanceToACharacter. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접..

 

 

2018/12/28 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 - (#9, Tell, Don't Ask)

2018/12/26 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 (1)

 

 

2019/01/14 - [Programming/Java] - 자바 메모리 누수 체크/확인/고치는 방법, Memory leak check/fix in Java application, cleanCode/좋은코드/oop/객체지향

 

 

2019/02/19 - [Life/Health care] - Lysine 라이신 usage/side effects/dosage 효과/효능/부작용/성인,소아 용법, 복용법

2019/02/16 - [Life/Health care] - Finasteride 피나스테라이드,탈모약 usage/side effects/dosage 효능/부작용/효과/sexual effect/두타스테라이드/프로페시아/propecia/finpecia/카피약/copy drug/hair loss

2019/02/25 - [Life/Health care] - Folic Acid 엽산 vitaminB9,비타민M usage/side effects/dosage 효과/효능/부작용/성인,소아 용법, 복용법

2019/02/28 - [Life/Health care] - Vitamin K, 비타민 K usage/side effects/dosage 효능/부작용/성인,소아 용법

2019/03/03 - [Life/Health care] - Vitamin B1, Thiamine, 비타민 B1, 티아민 usage/side effects/dosage 효능/부작용/성인,소아 용법