Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

idea for programming in c language (data structure)

+19 votes
asked Jul 13, 2021 by paulo magalhaes (1,480 points)
It has a lot of text in the statement for little problem.

 

The condition you want to count is the number of guys who are already in the right place in the queue.

 

There are two things then:

    determine the right place in the queue, as the place they are is well known :)
    tell

Example 1 (yours):
 

100 80 90

In order it would be 100 90 80

looking at the two side by side
 

100 80 90 (original)
100 90 80 (in descending order)

 

And only one matches: 2 will change places

 

Example 2 (yours):
 

100 120 30 50

similarly

100 120 30 50
120 100 50 30

 

And none is in place: 4 will change

 

Example 3 (yours):
 

100 90 30 25
100 90 30 25

 

And these are in the right order

 

 

So just sort the notes in descending order, obviously on another vector, and count how many are equal in position.

 

Of course, equal grades will cause confusion: in general, guys with the same grade should be seen in order of arrival, but there's no way to do that with these data....

2 Answers

0 votes
answered Aug 29, 2022 by Aakash Reddy (180 points)
#include <stdio.h>
 
void main ()
{
 //variable declaration
 int number[30];
 int i, j, a, n;

 //asking user to enter size of array 
 printf("Enter the value of N\n");
 scanf("%d", &n); //reading array size
 
 //asking user to enter array elements
 printf("Enter the numbers \n"); 
 for (i = 0; i < n; ++i)
  scanf("%d", &number[i]); //reading array elements

 /* Logic for sorting and checking */

 for (i = 0; i < n; ++i)
 {
   for (j = i + 1; j < n; ++j)
   {
    if (number[i] < number[j])
    {
     a = number[i];
     number[i] = number[j];
     number[j] = a;
   }
  }
 }
 
 printf("The numbers arranged in descending order are given below\n");
 for (i = 0; i < n; ++i)
 {
   printf("%d\n", number[i]); //printing numbers in descending order
 }
}
/*I THINK THIS CODE WOULD BE HELPFUL TO ARRANGE THEM IN A DESCENDING ORDER*/
0 votes
answered Oct 6, 2022 by Jayaraj kanda (150 points)
import java.lang.*;

import java.util.*;

public class Main

{

public static void main(String[] args) {

    int count=0;

List<Integer> l1=new ArrayList<Integer>();

Scanner s=new Scanner(System.in);

System.out.println("Enter size");

int n=s.nextInt();

for(int i=0;i<n;i++)

{

    l1.add(s.nextInt());

}

List<Integer> l2=new ArrayList<Integer>(l1);

Collections.sort(l2, Collections.reverseOrder());

for(int i=0;i<n;i++)

{

if(l1.get(i)!=l2.get(i))

{

     count++;

}

}

System.out.println("positions exchanged are"+count);

}

}

Solution in JAVA
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...