Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*The Department faculty prepared multiple-choice questions for a class surprise test. The
- surprise test consists of “Q” questions with each question having certain number of marks
- assigned to it. However, the faculty has been told by the Examination Head that each question
- in the paper should carry a different weightage of marks, which means no two questions can
- have the same marks.
- So the Department faculty wants to do this by adjusting minimal changes in the original
- assigned marks; assigning every question at least as much marks as it originally had.
- Find the minimum total marks that the faculty can set the paper for.
- Input
- 1) First-line contains “Q”, the total number of questions in the paper.
- 2) Second-line contains “N” space-separated integers A1, A2 ... An representing the original
- marks assigned to every question.
- Output
- Minimum total marks the faculty can set the paper for*/
- /*input
- 10
- 3
- 4
- 4
- 4
- 5
- 5
- 6
- 10
- 10
- 10
- output
- 75 */
- #include<stdio.h>
- #include<stdlib.h>
- /*fun for sorting array in ascending order*/
- void sortarray(int item[], int n)
- {
- int i,j,temp,flag = 0;
- for(i=0;i<n-1;i++)
- {
- for(j=i+1;j<n;j++)
- {
- if(item[i]>item[j])
- {
- temp = item[i];
- item[i] = item[j];
- item[j]= temp;
- flag++;
- }
- }
- if(flag == 0)//it mean no swapping happened means array is sorted
- break;
- }
- }//sortarray
- int main()
- {
- int marks[30],num,i,j,sum=0;
- printf("Enter number of questions: ");
- scanf("%d",&num);
- printf("\nPlease enter marks of %d questions:\n ",num);
- for(i=0;i<num;i++)
- { printf("Question %d: ",i+1);
- scanf("%d",&marks[i]);
- }
- /*sorting array in ascending order*/
- sortarray(marks, num);
- for(i=0;i<num;i++)
- {
- for(j=i+1;j<num;j++)
- {
- if(marks[i]<marks[j])
- break;
- else if(marks[i]>=marks[j])
- {
- marks[j]=marks[i]+(j-i);
- }
- }
- }
- printf("\nupdated marks:\n");
- for(i=0;i<num;i++)
- { printf("%d ",marks[i]);
- sum = sum + marks[i];
- }
- printf("\n");
- printf("\nMinimum total marks = %d",sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement