Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #define size 100
  5. using namespace std;
  6.  
  7. template <class T>
  8. T FindX (T a, T b)
  9. {
  10. T x;
  11. if (a>b) x=a/b-1;
  12. if (a==b) x=a+25;
  13. if (a<b) x=(a*b-2)/a;
  14. return x;
  15. }
  16.  
  17. int MasSol(int* A, int n)
  18. {
  19. int* MinusA = new int[size];
  20. int cnt=0;
  21. for (int i=0; i<n; i++)
  22. {
  23. if (A[i]<0)
  24. {
  25. MinusA[cnt]=A[i];
  26. cnt++;
  27. }
  28. }
  29. int P=1;
  30. for (int i=0; i<cnt; i++)
  31. P=P*MinusA[i]*MinusA[i]*MinusA[i];
  32. delete [] MinusA;
  33. return P;
  34. }
  35.  
  36. int _tmain(int argc, _TCHAR* argv[])
  37. {
  38. // часть 1
  39. ifstream IN;
  40. IN.open("C:\\1\\in.txt");
  41. int a,b,ans1;
  42. float c,d,ans2;
  43. IN >> a >> b >> c >> d;
  44. ans1=FindX(a,b);
  45. ans2=FindX(c,d);
  46. ofstream ANS1;
  47. ANS1.open("C:\\1\\in.txt", ios::app);
  48. ANS1 << "\n" << ans1 << "\n" << ans2;
  49.  
  50. // часть 2
  51. ifstream MAS;
  52. MAS.open("C:\\1\\mas.txt");
  53. int* A = new int[size];
  54. int cnt=0;
  55. while (!MAS.eof())
  56. {
  57. MAS >> A[cnt];
  58. cnt++;
  59. }
  60. int P=MasSol(A,cnt);
  61. delete [] A;
  62. ofstream ANS2;
  63. ANS2.open("c:\\1\\mas.txt", ios::app);
  64. ANS2 << "\n" << P;
  65. system("pause");
  66. return 0;
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement