Advertisement
AI_UBI

Wtf?

Dec 3rd, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>;
  2. using namespace std;
  3. void main()
  4. {
  5. short i, maxInd=0, occurences=1, maxEnd=-1;
  6. int n, *arr;
  7. FILE *f;
  8.  
  9. f=fopen("in.txt","r");
  10. fscanf(f,"%d",&n);
  11. cout«"n="«n«endl;
  12.  
  13. arr= new int[n];
  14. for(i=0; i<n; ++i)
  15. {
  16. fscanf(f,"%d",&arr[i]);
  17. cout«arr[i]«" ";
  18. if(arr[i]>arr[maxInd])
  19. maxInd=i;
  20. }
  21. fclose(f);
  22. cout«endl;
  23.  
  24. for(i=0; i<n; ++i)
  25. if(arr[i]==arr[maxInd]&&i!=maxInd)
  26. {
  27. ++occurences;
  28. maxEnd=i;
  29. }
  30.  
  31. if(occurences<3)
  32. cout«"0";
  33. else
  34. cout«maxEnd-maxInd-1;
  35. cout«endl;
  36.  
  37. delete []arr;
  38. system("pause");
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement