Question

C programming question

please meet all of the following conditions don't just output the same answer

Given a sequence a. The elements of a has the following infomations: index The index is followed by the input order, starts fInput The first line contains an integer n, indicates the number of elements in a There are n lines below. Start from the firSample Input Download 5 6 60 20 999 1000000000 1 40 0 20 Sample Output Download 5 2 413​​​​​​​

Given a sequence a. The elements of a has the following infomations: index The index is followed by the input order, starts from 1. The input won't contain index , you have to record it yourself. Smaller input index has higher priority. admin level : Level starts from 0 to 999. level 0 has the highest priority, while level 999 has the lowest. president Heng f of differe Heeheng level school affairs level 1 level 2 junior sister( ) level 3senior sister() level 4 senior brother( ) level 5 campus stray dogs/cats level 6squirrel level 7 pigeon level 999 junior brother() license number An integer. Smaller number has higher priority. You are going to sort a. Element with higher priority brings to the front. Compare admin level first, then license number, then index Output index (the old one) of every element the new a .
Input The first line contains an integer n, indicates the number of elements in a There are n lines below. Start from the first line of the n lines, the i-th line contains the i-th information. Each line contains 2 integers admin level and license number. n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the required program

I've used insertion sort for sorting

#include<stdio.h>
struct sequence{ //structure for storing a sequence together
   int index;
   int admin_level;
   int license_no;
};
int main()
{
   int a;
   scanf("%d",&a); //input of no. of lines
   struct sequence ar[a+1];
   struct sequence temp;
   for(int i=1;i<=a;i++)
   {
       ar[i].index=i; //generate index no.
       scanf("%d%d",&ar[i].admin_level,&ar[i].license_no);
   }
   for(int i=2;i<=a;i++) //use insertion sort
   {
       for(int j=i;j>1;j--)
       {
           if(ar[j].admin_level<ar[j-1].admin_level)
           {
               temp=ar[j];
               ar[j]=ar[j-1];
               ar[j-1]=temp;
           }
           else if(ar[j].admin_level==ar[j-1].admin_level )
           {
               if(ar[j].license_no<ar[j-1].license_no){
               temp=ar[j];
               ar[j]=ar[j-1];
               ar[j-1]=temp;
           }

           else if(ar[j].license_no==ar[j-1].license_no)
           {
               if(ar[j].index<ar[j].index)
               {
                   temp=ar[j];
               ar[j]=ar[j-1];
               ar[j-1]=temp;
               }
               else
               {
                   break;
               }
           }
           else
           {
               break;
           }
           }
           else
               break;
       }
   }

   printf("%d", ar[1]);;
   for(int i=2;i<=a;i++) //loop for printing out the result
       printf(" %d",ar[i].index);
   printf("\n");
}

here is the ss of the output

PS D:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin> ./a.ex 5 6 60 1 20 999 100000000 1 40 0 20 5 2 4 1 3 PS D:\min

I hope this will help you so please give positive ratings :)))

Add a comment
Know the answer?
Add Answer to:
C programming question please meet all of the following conditions don't just output the same answer ​​​​​​​ Given a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Plz i want answer these question using list in python programme. You are given two sequences...

    Plz i want answer these question using list in python programme. You are given two sequences of n integers: 21, 22, ...,an and b1,b2, ..., bn Print a sequence of 2n integers created by alternating elements from the given sequences: a1, 61, 42, 62, a3, 63, ..., an, bn. Input The first line contains a positive integer n (1 <n<1000) - the length of the sequences The second line contains n space-separated integers 01, 02, ..., an (-1000 <a; <...

  • I want this using while loop This using stringin python Use list or some thing in...

    I want this using while loop This using stringin python Use list or some thing in python Using list in python I want answer as soon as posdible E. Last Number time limit per test: 1 second memory limit per test: 256 megabytes input standard input output standard output You are given a sequence of positive integers aj, , 03, ... Print the last element of the sequence. Input The input consists of multiple lines. The i-th line contains a...

  • Please don't use a void fuction and this is a c++ question. Thanks Write a program...

    Please don't use a void fuction and this is a c++ question. Thanks Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name, merge the information as shown below Using...

  • Description An array in C++ is a collection of items stored at contiguous memory locations and...

    Description An array in C++ is a collection of items stored at contiguous memory locations and elements can be accessed randomly using indices of an array. They are used to store similar type of elements as in the data type must be the same for all elements. One advantage of arrays is easy data manipulation and accessibility of elements stored in consecutive locations. The Problem: One teaching assistant of a computer science department in Engineering University got a simple question...

  • Topic:Data structures and algorithms programming Compiler:C++ 11, flag: -static -std=c++0x Boring job One day, Rick got...

    Topic:Data structures and algorithms programming Compiler:C++ 11, flag: -static -std=c++0x Boring job One day, Rick got a sequence of N magic numbers. In order to find the latent code in the sequence, he decides to do the following operations with a magic parameter K: Step (1) Take out the first k numbers from current sequences into a temporary sequence ni namn, and pick the largest element Vmax out of these k numbers, then subtract 1 from the remaining K-1 elements....

  • C++ You're given the pointer to the head nodes of two linked lists. Compare the data...

    C++ You're given the pointer to the head nodes of two linked lists. Compare the data in the nodes of the linked lists to check if they are equal. The lists are equal only if they have the same number of nodes and corresponding nodes contain the same data. Either head pointer given may be null meaning that the corresponding list is empty. Input Format You have to complete the int CompareLists (Node headA, Node* head B) method which takes...

  • Java Program Create a class to store an array of with enough space to store 10 integer values. Us...

    Java Program Create a class to store an array of with enough space to store 10 integer values. Using the principle of recursion, implement the following: *getSize : returns the size of the array. *get (i): returns the i-th element of the array. If the element does not exist, it throws a "NoSuchElementException” which is a subclass of Java class RunTimeException. *add (val): inserts value as the last element of the array. If necessary, double the size of the current...

  • the question from the course COMP 4040 that Analysis of Algorithms if you want to answer it by code please use C or C++...

    the question from the course COMP 4040 that Analysis of Algorithms if you want to answer it by code please use C or C++ 5. Algorithm Design (20 points) Input: array A contains n distinct numbers from 1 to n, in arbitrary order. Output: number of inversions (defined as the number of pair(i, j) of array indices with i < j and A[i] > Aj]) (a) (5 points) What array with elements from the set {1, 2, ..., n) has...

  • Java 8 Braces You are designing a compiler for a C++ program and need to check...

    Java 8 Braces You are designing a compiler for a C++ program and need to check that braces in any given file are balanced Braces in a string are considered to be balanced if the following criteria are met: All braces must be closed. Braces come in pairs of the form 0.0andl1. The left brace opens the pair, and the right one closes it In any set of nested braces, the braces between any pair must be closed For example,...

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT