View Code of Problem 5

#include<iostream>
#include<vector>
using namespace std;
typedef struct{
  int index, a, b;
};
int main(){
  int all;
  cin >> all;
  
  for(int t = 0;t < all;t ++){
    int n, m;
    cin >> n >> m;
    vector<Box> box;
    for(int j = 0;j < n;j ++){
      Box temp;
      temp.index = j + 1;
      cin >> temp.a >> temp.b;
      box.push_back(temp);
    }
    
    for(int j = 0;j < n;j ++){
      for(int k = j;k < n;k ++){
        if(box[k].b < box[k + 1].b){
          Box temp = box[k];
          box[k] = box[k + 1];
          box[k + 1] = temp;
        }
      }
    }
    for(int j = 0;j < n;j ++){
      for(int k = j;k < n;k ++){
        if(box[k].a < box[k + 1].a){
          Box temp = box[k];
          box[k] = box[k + 1];
          box[k + 1] = temp;
        }
      }
    }
     
    for(int j = 0;j < m - 1;j ++){
        cout << box[j].index << " ";
    }
    cout << box[j].index << endl;
  }
}
/*
Main.cc:6:1: error: missing type-name in typedef-declaration
 };
 ^
Main.cc: In function 'int main()':
Main.cc:14:12: error: 'Box' was not declared in this scope
     vector<Box> box;
            ^~~
Main.cc:14:15: error: template argument 1 is invalid
     vector<Box> box;
               ^
Main.cc:14:15: error: template argument 2 is invalid
Main.cc:16:10: error: expected ';' before 'temp'
       Box temp;
          ^~~~~
          ;
Main.cc:17:7: error: 'temp' was not declared in this scope
       temp.index = j + 1;
       ^~~~
Main.cc:17:7: note: suggested alternative: 'mktemp'
       temp.index = j + 1;
       ^~~~
       mktemp
Main.cc:19:11: error: request for member 'push_back' in 'box', which is of non-class type 'int'
       box.push_back(temp);
           ^~~~~~~~~
Main.cc:24:17: error: invalid types 'int[int]' for array subscript
         if(box[k].b < box[k + 1].b){
                 ^
Main.cc:24:32: error: invalid types 'int[int]' for array subscript
         if(box[k].b < box[k + 1].b){
                                ^
Main.cc:25:14: error: expected ';' before 'temp'
           Box temp = box[k];
              ^~~~~
              ;
compilation terminated due to -fmax-errors=10.
*/

Double click to view unformatted code.


Back to problem 5