Другие языки программирования и технологии

Дано n строк по 3 элемента (1 и 0), найти сколько строк имеет больше чем один знак 1. C++

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
#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");
}
Ерлан Садуакасов
Ерлан Садуакасов
54 593
Лучший ответ
#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();
}
Шохрух Mирахмедов Вы меня спасли! Спасибо огромное!
вопрос непонятен прости
57
555 777
22
Шохрух 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'.

Похожие вопросы