점수 찾기 (100 점)
Praveen은 학교에서 컴퓨터 과학 교사로 일자리를 찾고 있습니다. 그는 여러 학교에서 여러 번 거절 당했지만 이번에는 일자리를 구하기로 결심했습니다. 그는 학교 St. Mary의 교장에게갑니다.
교장은 자신의 학교에 채점 및 학점 시스템이 있다고 말합니다. N 개의 과목이 있고 각 과목은 그것에 첨부 된 학점 Ci가 있습니다 (1 <= i <= N). 각 학생은 각 과목에서 특정 성적을 받고 각 성적에는 다음과 같은 점수가 있습니다.
A = 10,
A(minus) = 9,
B = 8,
B(minus) = 7,
C = 6,
C(minus) = 5
이제 각각 4 학점, 3 학점, 2 학점의 3 개 과목이 있고이 3 개 과목에서 각각 특정 학생의 점수가 A (마이너스), B 및 C 인 경우 그의 점수는 다음과 같이 계산됩니다. 총점 = Grade point의 곱의 합계 각 과목에 대한 해당 학점.
= ( (9*4) + (3*8) + (2*6) ) = 72.
그는 Praveen이 각 과목에 다른 등급을 할당하여 N 과목의 학점을받은 학생에게 부여 할 수있는 총 개별 점수를 알려주기를 원합니다.
입력 형식 함수에는 단일 인수 (각각 해당 주제의 학점을 나타내는 N 요소의 1 차원 정수 배열 A)가 포함됩니다. 입력의 첫 번째 줄에는 배열의 크기를 나타내는 정수 N이 포함됩니다. i 번째 주제의 신용 Ci를 나타내는 정수를 포함하는 다음 N 줄의 입력
Constraints
1 <= N <= 100
1 <= Ci <= 5
출력 형식 제공 할 수있는 총 점수 수를 나타내는 단일 정수를 반환해야합니다.
Sample TestCase 1
Input
2
1
2
Output
16
이제 다음과 같은 코드를 작성하고 있습니다.
package javaapplication1;
import java.util.Scanner;
public class CandidateCode {
private static void possibleCombination(int input) {
int i=0;
int[] a=new int[Grades.length];
a[i]=input;
System.out.println("the a is "+a[i]);
}
private static final int[] Grades = new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
public static void main(String[] args) {
int i=0,j,totalSummation=0;
Scanner uInput = new Scanner(System.in);
System.out.println("Enter length of Array:");
int index = uInput.nextInt();
int[] Credit = new int[index];
for (i = 0; i <= Credit.length-1; i++) {
Credit[i] = uInput.nextInt();
System.out.println("credit is" + Credit[i]);
for ( j = 0; j <= Grades.length - 1; j++) {
totalSummation = +(Grades[j] * Credit[i]);
possibleCombination(totalSummation);
// System.out.println("total sum is " + totalSummation);
}
}
}
}
이제 각 반복에서 계산 된 값을 저장하고 싶습니다 ... 반복에 대한 의미는 먼저 값이 10,9,8,7,6,5,4,3,2,1 반복입니다. 두 번째 값은 20,18,16입니다. , 14,10,8,6,4,2
첫 번째 반복의 각 값을 두 번째 반복의 모든 값과 합하고 싶습니다. 즉, 10 + 20, 10 + 18, 10 + 16, 10 + 14, 10 + 10, 10 + 8, 10 + 6, 10 + 4, 10 + 2는 9,8,7,6,5에 대해서도 비슷합니다. 4,3,2,1
이를 달성하기 위해 반복 당 값을 저장해야하지만 여기에 갇혀 있습니다.이 문제를 제거하도록 도와주세요. 미리 감사합니다.
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
public class Sample {
public static void main(String args[] ) throws Exception {
Scanner scan = new Scanner(System.in);
int nValue = scan.nextInt();
if(nValue<1 || nValue>100){
System.out.println("Array Value cannot be less than 1 or greater than 100");
}
int[] inputCredits = new int[nValue];
for( int i=0 ; i < nValue ; i++){
inputCredits[i]=scan.nextInt();
if(inputCredits[i]<1 || inputCredits[i]>5){
System.out.println("Credit Value cannot be less than 1 or greater than 5");
}
}
List<Integer> list1 = Arrays.stream(inputCredits).boxed().collect(Collectors.toList());
List<Integer> list2 = Arrays.asList(5,6,7,8,9,10);
//checked for basic constraints up till this point
//Next what we multiply all the inputted Credits with the possible grades and
// store in the list where x input Credits will produce a list of x*6 entries
// where first six entries are the possibilities for the first Credit, next 6
// entries for the 2nd credit and so on, having this knowledge we loop through // the list to get all the possible scores
List<Integer> permutedList = list1.stream().flatMap(i -> list2.stream().map(j -> i*j)).collect(Collectors.toList());
List<Integer> listForDistinctSet= new ArrayList<Integer>();
for(int i=0; i<6 ; i++){
listForDistinctSet.add(permutedList.get(i));
}
Set<Integer> distinctSet = new HashSet<Integer>();
for(int j=6,k=j+6;k<=permutedList.size();j=k,k=k+6){
Set<Integer> newSet = new HashSet<Integer>();
for(int i=0; i<listForDistinctSet.size(); i++){
for(; j<k ; j++){
int sum = listForDistinctSet.get(i) + permutedList.get(j);
newSet.add(sum);
}
j=k-6;
}
distinctSet=newSet;
listForDistinctSet = new ArrayList<>(distinctSet);
}
System.out.println(distinctSet.size());
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다