Форум » C/C++ для начинающих (C/C++ for beginners) » vector element split based on percentage of preview value » Ответить

vector element split based on percentage of preview value

ramees: i like to group adjacent element based on percentage of first value eg --> if first value = 0.5254 , next value = 0.4578 MAX_P = first value + first value 10 % added MIN_P = first value - first value 10 % minuses and i have const two value C_MIN and C_ MAX first i check (MAX_P < C_ MAX && MIN_P <C_MIN) then i check next value is less than (MAX_P >next value && MIN_P < Next value ) group until its not matching i try to write the please see below show me what i missed #include <iostream> #include <vector> #include <cmath> using namespace std; const float * find_matching( const float a[], size_t n ,const float Rm[]) { if(n!=0) { for ( const float *prev = a, *next = a; ++next != a + n; ++prev ) { float MXp = (((((*prev * 100000)*10)/100)/100000)+*prev)*100000; float MAX_P =(ceil(MXp))/100000; float MN = (((*prev * 100000)* 10)/100); float Mp = (ceil(MN))/100000; float MIN_P = *prev - Mp; if(MAX_P < Rm[0] && MIN_P < Rm[1] ) { if(MAX_P < *next || MIN_P > *next ) { return prev; } }else { if(Rm[0] > *next || Rm[0] < *next ) { return prev; } } } } return ( a + n ); } const int s =6; int main() { // const array min max // first value of the array is constend MAX and secound value is MIN float RM[]={0.98,0.06}; float r={0.95,0.93,0.58,0.54,0.01,0.02}; vector<float> vr(r,r+s); std::vector<float>::size_type nr = vr.size(); const float *first_R = vr.data(); const float *rm = RM; std::vector<std::vector<float> > v; while (first_R != vr.data() + nr ) { const float *last_R = find_matching( first_R, nr - ( first_R - vr.data() ),rm ); v.push_back( std::vector<float>( first_R, last_R ) ); first_R = last_R; } for each ( const std::vector<float> &v1 in v ) { for each ( float x in v1 ) std::cout << x << ' '; std::cout << std::endl; } return 0; }

Ответов - 1

Сыроежка: I do not understand the sense of these calculations. [pre2] float MXp = (((((*prev * 100000)*10)/100)/100000)+*prev)*100000; float MAX_P =(ceil(MXp))/100000; float MN = (((*prev * 100000)* 10)/100); float Mp = (ceil(MN))/100000; float MIN_P = *prev - Mp; [/pre2]



полная версия страницы