Answer to Question #325865 in C# for Anji

Question #325865

In a university, there is a certain system of credits. Each of student is given a ‘credit limit’ which specifies the maximum credits of a subject they can take. A student can take any number of subjects which are under his/her credit limit.

There are N students and K subjects.Each subject has a specified number of credits .when student choose a subject ,it becomes a (student,subject)pair.

Find the maximum number of possible(subject,student)pairs for the given credit limits and subject credit requirements.

Input1:K denoting the number of subjects

Input2:An array of K elements each denoting the credits to take a subject

Input3:N denoting the number of students

Input4:An array of N elements each denoting the credit limit of a student.

Output:Your should return the maximumnumber of possible required pairs.

Example1:

Inpput1:3

Input2:{44,45,56,39,2,6,17,75}

Input3:1

Input4:{54}

Output:6


1
Expert's answer
2022-04-12T13:28:10-0400
    class Student
    {
        public int CreditLimit { get; set; }
        public Student(int limit)
        {
            CreditLimit = limit;
        }
    }
    class Subject
    {
        public int MaximumCredits { get; set; }
        public Subject(int limit)
        {
            MaximumCredits = limit;
        }
    }
    static void Main()
    {
        Console.Write("Enter the number of subject: ");
        int n =  int.Parse(Console.ReadLine());
        List<Subject> subjects = new List<Subject>();


        for (int i = 0; i < n; i++)
        {
            Console.Write($"Enter the maximum number of credits for {i+1} subject: ");
            subjects.Add(new Subject(int.Parse(Console.ReadLine())));
        }


        Console.Write("Enter the number of student: ");
        n = int.Parse(Console.ReadLine());
        List<Student> students = new List<Student>();


        for (int i = 0; i < n; i++)
        {
            Console.Write($"Enter the credit limit for {i + 1} student: ");
            students.Add(new Student(int.Parse(Console.ReadLine())));
        }


        MaxSubject(students, subjects);




        Console.ReadKey();
    }


    static void MaxSubject(List<Student> students, List<Subject> subjects)
    {
        for (int i = 0; i < students.Count; i++)
        {
            int maxCount = 0;
            for (int j = 0; j < subjects.Count; j++)
            {
                if (students[i].CreditLimit > subjects[j].MaximumCredits)
                    maxCount++;
            }
            Console.WriteLine($"For the {i + 1} student, the maximum number of subjects is {maxCount}");
        }
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS