Input
n=6
a[i]=
1 0 1
0 0 1
1 0 0
0 0 0
1 1 1
0 1 1
Output: 3
Другие языки программирования и технологии
Дано n строк по 3 элемента (1 и 0), найти сколько строк имеет больше чем один знак 1. C++
#include <iostream>
#include <vector>
#include <random>
using namespace std;
class Three {
public:
Three() = delete;
explicit Three(const size_t n) : n_(n) {}
void fill_rand() {
const uniform_int_distribution<> uid(0, 1);
random_device rd;
for (size_t i = 0; i < n_; ++i) {
vector<int> row(size);
for (auto &value : row) value = uid(rd);
box_.emplace_back(row);
}
}
void show()const {
for (const auto &row : box_) {
for (size_t i = 0; i < size; ++i) cout << ' ' << row[i];
cout.put('\n');
}
}
size_t count()const {
size_t cnt = 0;
for (const auto &row : box_) if (more(row)) ++cnt;
return cnt;
}
private:
vector<vector<int>> box_;
size_t n_;
static const size_t size = 3;
static bool more(const vector<int>& row) {
size_t n = 0;
for (const auto value : row) if (value != 0) ++n;
return n > 1;
}
};
int main() {
cout << "Input: ";
size_t size;
cin >> size;
Three three(size);
three.fill_rand();
three.show();
const auto count = three.count();
cout << "Output: " << count << endl;
system("pause");
}
#include <vector>
#include <random>
using namespace std;
class Three {
public:
Three() = delete;
explicit Three(const size_t n) : n_(n) {}
void fill_rand() {
const uniform_int_distribution<> uid(0, 1);
random_device rd;
for (size_t i = 0; i < n_; ++i) {
vector<int> row(size);
for (auto &value : row) value = uid(rd);
box_.emplace_back(row);
}
}
void show()const {
for (const auto &row : box_) {
for (size_t i = 0; i < size; ++i) cout << ' ' << row[i];
cout.put('\n');
}
}
size_t count()const {
size_t cnt = 0;
for (const auto &row : box_) if (more(row)) ++cnt;
return cnt;
}
private:
vector<vector<int>> box_;
size_t n_;
static const size_t size = 3;
static bool more(const vector<int>& row) {
size_t n = 0;
for (const auto value : row) if (value != 0) ++n;
return n > 1;
}
};
int main() {
cout << "Input: ";
size_t size;
cin >> size;
Three three(size);
three.fill_rand();
three.show();
const auto count = three.count();
cout << "Output: " << count << endl;
system("pause");
}
#include < iostream >
#include < windows.h >
#include < vector >
#include < tuple >
using namespace std;
void main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
system("color 0A");
cout << "Введите количество строк ";
unsigned n;
cin >> n;
vector < tuple < int, int, int > > v;
for (unsigned u = 0; u < n; ++u)
{
cout << "Строка " << u + 1 << " ";
unsigned t1, t2, t3;
cin >> t1 >> t2 >> t3;
v.push_back(make_tuple(t1, t2, t3));
}
unsigned cnt = 0;
for (auto t : v)
{
int temp = get < 0 > (t) + get < 1 >(t) + get < 2 >(t);
if (temp > 1)
++cnt;
}
cout << "Результат " << cnt << endl;
cin.get(); cin.get();
}
#include < windows.h >
#include < vector >
#include < tuple >
using namespace std;
void main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
system("color 0A");
cout << "Введите количество строк ";
unsigned n;
cin >> n;
vector < tuple < int, int, int > > v;
for (unsigned u = 0; u < n; ++u)
{
cout << "Строка " << u + 1 << " ";
unsigned t1, t2, t3;
cin >> t1 >> t2 >> t3;
v.push_back(make_tuple(t1, t2, t3));
}
unsigned cnt = 0;
for (auto t : v)
{
int temp = get < 0 > (t) + get < 1 >(t) + get < 2 >(t);
if (temp > 1)
++cnt;
}
cout << "Результат " << cnt << endl;
cin.get(); cin.get();
}
Шохрух Mирахмедов
Вы меня спасли! Спасибо огромное!
вопрос непонятен прости
Шохрух Mирахмедов
На английском : You are given n lines, each of which contain only 3 space-separated characters (0 or 1). Your task is to count how many of those lines have more than one character '1'.
Похожие вопросы
- Объясните пожалуйста, что означает эта строка WRITE('ВВЕДИTE ЭЛЕМЕНТ МАССИВА '); READLN(MAS[1])?
- Вычислить произведение n>=2 (n четное) сомножителей y=(2/1)*(2/3)*(4/3)*(4/5)*(6/5)*(6/7)*..
- Помогите решить задачу C++. Найти номер строки, для которой среднее арифметическое значение ее элементов максимальна
- Дано натуральное число n. Найти и вывести все числа в интервале от 1 до n -1, у которых произведение всех цифр совпадает
- Вам даны все целые числа от 1 до N + 1, кроме одного. Найдите отсутствующее число.
- Помогите Задан массив Р(N).Переписать все его элементы,за исключением максимального и минимального в массив D.(язык C++)
- Пользователь вводит строку. Найти и вывести из строки римские цифры от 1 до 5, введенные прописными символами.
- найти сколько слагаемых необходимо, чтобы сумма 2+4+6+...оказалась больше 100. на c++
- Как научиться программировать на C++ с нуля, имея под рукой среду разработки Borland C++ Builder 6.0
- Дано n число, как узнать простое оно или нет в c++ ?