fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. int n ;
  6. struct sort2
  7. {
  8. int data;
  9. int index;
  10. }a[6];
  11.  
  12. int fun(const struct sort2 &p1,const struct sort2 &p2)
  13. {
  14. if((p1.data)<(p2.data))
  15. return 1;
  16. else
  17. return 0;
  18. }
  19.  
  20.  
  21.  
  22. int main()
  23. {
  24. int tc,i;
  25. cin>>tc;
  26. while(tc--)
  27. {
  28. cin>>n;
  29. for(i=1;i<=n;i++)
  30. {
  31. cin>>a[i].data;
  32. a[i].index=i;
  33. }
  34.  
  35.  
  36.  
  37.  
  38. sort(a,a+n,fun);
  39.  
  40. int max=0;
  41. for(i=1;i<=n;i++)
  42. {
  43. if((a[i].index)<(a[i+1].index))
  44. max++;
  45.  
  46. else if((a[i].index)>(a[i+1].index))
  47. max=1;
  48. }
  49.  
  50. cout<<max<<endl;
  51. }
  52.  
  53. // getch();
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0.02s 2728KB
stdin
3
7
2 3 1 7 4 5 6
5
1 2 3 4 5
6
6 5 4 3 2 1
stdout
1
1
3