1. 1-A. The New Year: Meeting Friends(from: www.codeforces.com)
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5. int main() {
  6. int d1,d2,d3,n1,n2,n3;
  7. cin>>n1>>n2>>n3;
  8. d1=abs(n2-n1)+abs(n3-n1);
  9. d2=abs(n1-n2)+abs(n3-n2);
  10. d3=abs(n2-n3)+abs(n1-n3);
  11. cout<<min(min(d1,d2),d3);
  12. return 0;
  13. }
  14. 2-A. Expression (from: www.codeforces.com)
  15. #include <iostream>
  16. #include <algorithm>
  17. using namespace std;
  18. int main() {
  19. int n1,n2,n3;
  20. cin>>n1>>n2>>n3;
  21. int e1,e2,e3,e4,e5,e6;
  22. e1=n1+(n2*n3);
  23. e2=n1*(n2+n3);
  24. e3=n1*n2*n3;
  25. e4=(n1+n2)*n3;
  26. e5=n1+n2+n3;
  27. e6=n1*n2+n3;
  28. cout<<max(max(max(max(max(e1,e2),e3),e4),e5),e6);
  29. return 0;
  30. }
  31. 3-Functions
  32. #include <iostream>
  33. #include <cmath>
  34. using namespace std;
  35. int max_of_four(int a, int b, int c, int d){
  36. return max(max(max(a,b),c),d);
  37. }
  38. int main() {
  39. int n1,n2,n3,n4;
  40. cin>>n1>>n2>>n3>>n4;
  41. cout<< max_of_four(n1,n2,n3,n4);
  42. return 0;
  43. }
Comments powered by Disqus