Advertisement
fabioiuri

482 - Permutation Arrays

Nov 30th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. /*Fabio Colaco
  2. fabiocolaco.net63.net
  3. https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=423*/
  4. #include <bits/stdc++.h>
  5.  
  6. using namespace std;
  7. #define MAX 100010
  8.  
  9. struct data{
  10.     int n;
  11.     string num;
  12. } arr[MAX];
  13.  
  14. bool cmp (data x, data y)
  15. {
  16.     if ( x.n < y.n ) return true;
  17.     return false;
  18. }
  19.  
  20. int main()
  21. {
  22.     int t;
  23.     scanf("%d", &t);
  24.     getchar ();
  25.     while(t--){
  26.         char buffer[MAX];
  27.         gets(buffer); //blank line
  28.         gets(buffer); //first line of the actual input
  29.  
  30.         char *pnt = strtok(buffer, " "); //parse
  31.         int i = 0;
  32.         while (pnt != NULL){
  33.             arr[i].n = atoi(pnt);
  34.             i++;
  35.             pnt = strtok(NULL, " "); //goto next
  36.         }
  37.  
  38.         gets(buffer); //second line of the actual input
  39.         pnt = strtok(buffer, " ");
  40.         i = 0;
  41.         while(pnt != NULL){
  42.             arr[i].num = pnt;
  43.             i++;
  44.             pnt = strtok(NULL, " ");
  45.         }
  46.  
  47.         sort(arr, arr + i, cmp);
  48.  
  49.         for(int k = 0; k < i; k++)
  50.            cout << arr[k].num << endl;
  51.  
  52.         if(t) printf("\n");
  53.     }
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement