Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //19 алгоритм
- /*
- 8
- 1 -3 5.3 3.8 -2.8 8 0 4
- 7
- -3.6 1 -500 8 2 -.7 8
- */
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- #include <numeric>
- using namespace std;
- bool prost(int a){
- if (a==1) return 0;
- else {
- if (a!=2)
- for (int i=2; i<sqrt(a)+1; i++){
- if (!(a%i)) return 0;
- }
- return 1;}
- }
- int main()
- {
- double c;
- int n;
- cin>>n;
- vector <double> x;
- for (int i=0; i<n; i++){
- cin>>c;
- x.push_back(c);
- }
- int m;
- cin>>m;
- vector <double> y;
- for (int i=0; i<m; i++){
- cin>>c;
- y.push_back(c);
- }
- vector <double> z(n+m);
- int
- it = (copy_if (x.begin(), x.end(), z.begin(),
- [](double a){return !(a<0);}) - z.begin());
- it = (copy_if (y.begin(), y.end(), z.begin()+it,
- [](double a){return !(a<0);}) - z.begin());
- z.resize(it);
- int it1 = (find_if(z.begin(),z.end(),prost) - z.begin());
- int it2 = (find_if(z.rbegin(),z.rend(),prost) - z.rbegin());
- it2 = z.size()-(it2+1);
- for (int i=0; i<z.size(); i++){
- if (i==it1||i==it2){
- cout<<"["<<z[i]<<"]"<<' ';
- }
- else cout<<z[i]<<' ';
- }
- cout<<endl<<"Index first : "<<it1<<endl;
- cout<<"Index last : "<<it2<<endl;
- if (fabs(it1-it2)<2||it1==z.size()) cout<<"NO";
- else {
- double sum = accumulate(z.begin()+(it1+1), z.begin()+it2, 0.0);
- cout<<"Chisel summiruem : "<<it2-(it1+1)<<endl;
- cout<<"Summa = "<<sum<<endl;
- sum/=(it2-(it1+1));
- cout<<"Srednee arifmeticheskoe = "<<sum;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement