bool ok1(int a, int b, int c){
return (a+b > c && a+c > b && b+c > a) && min(a,min(b,c)) > 0;
}
bool ok2(int a, int b, int c){
return ok1(a,b,c) && (a == b || a == c || b == c);
}
signed main(){
const int n = 3, m = 7;
int arr[n][m];
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cin >> arr[i][j];
vector<int> ans;
for(int j = 0; j < m; j++)
if(ok2(arr[0][j],arr[1][j],arr[2][j]))
ans.push_back(j+1);
cout << ans.size() << "\n";
for(auto i: ans)
cout << i << " ";
}
Подробнее - на -
Объяснение:
#include <iostream>
using std::cout;
using std::endl;
using std::fixed;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
#include <iomanip>
using std::setprecision;
int main()
{
float a[16];
float counter = 0;
srand(time(0));
for(int i = 0; i < 16; i++)
{
a[i] = float(rand()) / RAND_MAX * (3.0 + 2.0) - 2.0;
if(a[i] < 0.0)
{
counter += a[i];
}
cout << setprecision(2) << fixed << a[i] << endl;
}
cout << endl;
cout << "Sum = " << counter << endl;
return 0;
}
Типовая задача на разбор случаев. Разбирать случаи будем не простым последовательным перечислением, а более сложной конструкцией из вложенных условных операторов.
Решение задачи.
Var a1, b1, c1, {коэффициенты уравнения первой прямой}
a2,b2,c2, {коэффициенты уравнения второй прямой}
x, y : Real; {координаты точки пересечения }
BEGIN
ReadLn( a1, b1, c1);
ReadLn( a2, b2, c2);
If ( (a1=0) and (b1=0) ) or ( (a2=0) and (b2=0) )
then WriteLn( 'это не прямая (прямые). ' )
else
if (a1*b2=a2*b1) and (a1*c2=a2*c1) {условие совпадения}
then WriteLn( 'прямые совпадают.' )
else
if a1*b2 = a2*b1 {условие параллельности}
then WriteLn('прямые параллельны.')
else begin x:=(c1*b2-c2*b1)/(b1*a2-b2*a1);
y:=(c2*a1-c1*a2)/(b1*a2-b2*a1);
WriteLn('координаты точки пересечения :',
' x = ', x : 5 : 2 , ', y = ', y : 5 : 2);
end;
END.