Технический форум

Технический форум (http://www.tehnari.ru/)
-   Помощь студентам (http://www.tehnari.ru/f41/)
-   -   Множества С++ (http://www.tehnari.ru/f41/t73336/)

pavlovpro 16.05.2012 19:36

Множества С++
 
Организовать ввод элементов двух числовых множеств А и В. Ввести число N>0. Из множества А удалить все числа, кратные N, с добавлением их в множество В. Полученные множества напечатать.(с использованием битовых полей)
Не могу удалить числа кратные N.
Спасибо!
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <bitset>
#include "conio.h"
#include <windows.h>
#include "math.h"

using namespace std;

//вывод множества
void print(bitset<200> a) {
for (int x = 0; x < 199; x++) {
if (a[x])
cout<<x<<" ";
}
cout<<endl;
}

// ввод множества
void input(bitset<200> &a) {

char *str = new char(100);
cin.getline (str, 100);

char* token;
int num;

token = strtok (str," ");
while (token !=NULL) {
num = atoi(token);
if (num > 0 && num < 200)
a[num] = true;
token = strtok (NULL, " ");
}
}
int _tmain(int argc, _TCHAR* argv[]) {

setlocale (LC_ALL,".1251");

bitset<200> a,b;

cout<<"Введите множество a"<<endl;
input(a);

cout<<"Введите множество b"<<endl;
input(b);

int N;

do {
cout<<"Введите число N"<<endl;
cin>>N;
if (N < 0){
cout<<endl<<"N должно быть больше нуля!"<<endl;
continue;
}
break;
} while (true);

int i,n;
for (int x = 0; x < 199; x++) {
if x%n !== 0
cout<<x, " ";
a = a | [x];
}

//for (int x = 0; x < 199; x++) {
// cout<<x, " ";
//for (int x = 0; x < 199; x++) {
//if (%x/n) == 0
// cout<<x, " ";
//b = b | [x];
//}
//}
getch();
return 0;
}


Часовой пояс GMT +4, время: 04:54.

Powered by vBulletin® Version 4.5.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.