fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n; // declare n to be a number
  6. cin>>n; // read n from the input
  7. // declare "books" to be a sequence of numbers of length n:
  8. vector<int> books(n);
  9. for(int i=0;i<n;i=i+1)
  10. cin>>books[i]; // read books from the input
  11. int result=0; // declare result to be a number which is initially 0
  12. for(int i=0;i<n-1;i=i+1){ // for each i from 0 to n-2 in turn
  13. // if the number of the book at position i+1 is smaller
  14. // than the number of the book at position i:
  15. if(books[i+1]<books[i]){
  16. result=result+1; // increase the result by one
  17. }else{ // otherwise
  18. result=0; // reset the result to 0
  19. }
  20. }
  21. cout<<n-result<<'\n'; // write n-result to the output
  22. }
  23.  
Success #stdin #stdout 0s 3460KB
stdin
7
6 2 3 1 4 5 7
stdout
7