Advertisement
ySiriuS17

19 alg

Nov 10th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. //19 алгоритм
  2. /*
  3. 8
  4. 1 -3 5.3 3.8 -2.8 8 0 4
  5. 7
  6. -3.6 1 -500 8 2 -.7 8
  7. */
  8. #include <iostream>
  9. #include <vector>
  10. #include <algorithm>
  11. #include <cmath>
  12. #include <numeric>
  13. using namespace std;
  14.  
  15. bool prost(int a){
  16. if (a==1) return 0;
  17. else {
  18. if (a!=2)
  19. for (int i=2; i<sqrt(a)+1; i++){
  20. if (!(a%i)) return 0;
  21. }
  22. return 1;}
  23. }
  24.  
  25. int main()
  26. {
  27. double c;
  28. int n;
  29. cin>>n;
  30. vector <double> x;
  31. for (int i=0; i<n; i++){
  32. cin>>c;
  33. x.push_back(c);
  34. }
  35. int m;
  36. cin>>m;
  37. vector <double> y;
  38. for (int i=0; i<m; i++){
  39. cin>>c;
  40. y.push_back(c);
  41. }
  42. vector <double> z(n+m);
  43. int
  44. it = (copy_if (x.begin(), x.end(), z.begin(),
  45. [](double a){return !(a<0);}) - z.begin());
  46. it = (copy_if (y.begin(), y.end(), z.begin()+it,
  47. [](double a){return !(a<0);}) - z.begin());
  48. z.resize(it);
  49. int it1 = (find_if(z.begin(),z.end(),prost) - z.begin());
  50. int it2 = (find_if(z.rbegin(),z.rend(),prost) - z.rbegin());
  51. it2 = z.size()-(it2+1);
  52. for (int i=0; i<z.size(); i++){
  53. if (i==it1||i==it2){
  54. cout<<"["<<z[i]<<"]"<<' ';
  55. }
  56. else cout<<z[i]<<' ';
  57.  
  58. }
  59. cout<<endl<<"Index first : "<<it1<<endl;
  60. cout<<"Index last : "<<it2<<endl;
  61. if (fabs(it1-it2)<2||it1==z.size()) cout<<"NO";
  62. else {
  63. double sum = accumulate(z.begin()+(it1+1), z.begin()+it2, 0.0);
  64. cout<<"Chisel summiruem : "<<it2-(it1+1)<<endl;
  65. cout<<"Summa = "<<sum<<endl;
  66. sum/=(it2-(it1+1));
  67. cout<<"Srednee arifmeticheskoe = "<<sum;
  68. }
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement