RusSimona

Varianta90 Sub3 Ex4

Mar 26th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<cmath>
  4. using namespace std;
  5. ifstream fin("bac.txt");
  6.  
  7. int main()
  8.  
  9. {
  10. int n, i, anterior, curent, Smax=0, S=0, Dmax=0,a,b;
  11. fin>>anterior;
  12. while(fin>>curent)
  13. {
  14. S=curent+anterior;
  15. if(anterior>0 && curent >0)
  16. {
  17. if(S>Smax)
  18. {
  19. Smax=S;
  20. a=anterior;
  21. b=curent;
  22. }
  23. else if(S==Smax)
  24. {
  25. if(abs(curent-anterior)>abs(a-b))
  26. {
  27. a=anterior;
  28. b=curent;
  29. }
  30. }
  31.  
  32. }
  33. anterior=curent;
  34. }
  35. cout<<a<<" "<<b;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment