// Version_1_33.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include #include using namespace std; //-------------------------------------------------------------------------------------------- //Возвращает количество не равных разрядов int Moment(const char *s1,const char *s2){ //char *s1, *s2; //s1=str1; //s2=str2; int count=0; while ((*s1)&&(*s2)){ if (*s1!=*s2) count++; s1++; s2++; }; if (*s1==0) // Если первая комбинация короче то добавляем к ней ноли while (*s2){ if(*s2!='0') count++; s2++; } else while(*s1){ // Если вторая короче if (*s1!='0') count++; s1++; } return count; } //-------------------------------------------------------------------------------------------- // Перевод в двоичное. Результат типа указатель на строковый массив (второй параметр) void code(int c, char* str){ int i; i= (int)floor(log10(double(c))/log10(double(2))); // кол-бит // char* str= new char [i]; // кодовая комбинация int buf=c, j=0; while (i>=0){ // вычисляем значение каждого разряда if (buf>= pow(double(2),i)) { buf-=(int)pow(double(2),i); str[i]='1'; // разряд равен единице } else str[i]='0'; // разряд равен нулю i--; j++; } str[j]='\0'; // комбинация заканчивается нулевым символом return ; }; //-------------------------------------------------------------------------------------------- /*Подсчитывает количество разрядов отличных от "0"*/ int count(const char* l){ int t=0; // счетчик const char* b=l; while (*b) { if (*b!='0') t++; b++; } return t; } //-------------------------------------------------------------------------------------------- // Структура, описывающая одну комбинацию struct Nabor{ char codes[32]; bool flag; bool operator <(const Nabor &b)const { return count(codes) Nabor1, vector Nabor2){ vector::iterator k,j; k=Nabor1.begin(); // Итератор "к" - не верно получает указатель начала вектора int level=count(k->codes); // level - также не получает значения cout<codes; while (k!= Nabor1.end()){ j=k+1; // cout<>'<codes; если убрать коментарий то виснет визуал студия while ((j!=Nabor1.end())&&(count(j->codes)<=(level+1))){ if (count(j->codes)==(level+1)){ int t=Moment(k->codes, j->codes); if (t==1) cout< mas; cout<<"In combine from file: "< Nabor2; Kley(mas, Nabor2); vector::iterator j; // vector::iterator j; sort(mas.begin(), mas.end()); // Групирование по весу наборов cout<<"From vector:\n"; // vector::iterator j; for(j=mas.begin(); j!= mas.end(); ++j){ // Вывод упорядоченого массива cout<codes<<" "; } j=mas.begin(); int y; y=Moment((j+1)->codes, (j+6)->codes); cout<>h; return 0; }