Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. int S(int *A,int *B,int n){
  9.  
  10. int i,j,counter;
  11. for(i=0;i<n;i++){
  12. for(j=0;j<n;j++){
  13. if(i>j)
  14. break;
  15. else if(A[i]<B[j])
  16. counter++;
  17. }
  18. }
  19. return counter;
  20. }
  21.  
  22. int main() {
  23. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  24. long int t;
  25. long int n;
  26. scanf("%li",&t);
  27.  
  28. if(!(t<=5)&&!(t>=1))
  29. return 0;
  30.  
  31. long int tcounter = 1;
  32. while(tcounter<=t){
  33. int i;
  34. tcounter++;
  35. scanf("%li",&n);
  36.  
  37. if(!(n>=1)&&!(n<=pow(10,5)))
  38. return 0;
  39.  
  40. int *A = (int*)malloc(sizeof(int)*n);
  41. for(i=0;i<n;i++){
  42. scanf("%d",(A+i));
  43. if(!(A[i]>0)&&!(A[i]<=pow(10,9)))
  44. return 0;
  45. }
  46.  
  47. int *B = (int*)malloc(sizeof(int)*n);
  48. for(i=0;i<n;i++){
  49. scanf("%d",(B+i));
  50. if(!(B[i]>0)&&!(B[i]<=pow(10,9)))
  51. return 0;
  52. }
  53.  
  54. if(S(A,B,n)>S(B,A,n))
  55. printf("1");
  56.  
  57. else if(S(A,B,n)<S(B,A,n))
  58. printf("2");
  59.  
  60. else if(S(A,B,n)==S(B,A,n))
  61. printf("0");
  62.  
  63. cout<<endl;
  64. }
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement