===== PascalABC.NET =====
type
Point = (real, real);
Vector = Point;
function GetVector(A, B: Point) :=
(B[0] - A[0], B[1] - A[1]);
function PointInTriangle(A, B, C, P: Point): boolean;
begin
var bV := GetVector(A, B);
var cV := GetVector(A, C);
var pV := GetVector(A, P);
var k1 := (pV[0] * bV[1] - bV[0] * pV[1]) /
(cV[0] * bV[1] - bV[0] * cV[1]);
Result := False;
if (k1 >= 0) and (k1 <= 1) then
begin
var k2 := (pV[0] - k1 * cV[0]) / bV[0];
Result := (k2 >= 0) and (k1 + k2 <= 1)
end
end;
begin
var x, y: real;
var A, B, C, P: Point;
Write('Координаты точки A: '); Read(x, y);
A := (x, y);
Write('Координаты точки B: '); Read(x, y);
B := (x, y);
Write('Координаты точки C: '); Read(x, y);
C := (x, y);
Write('Координаты точки P: '); Read(x, y);
P := (x, y);
Writeln(PointInTriangle(A, B, C, P)); // True - принадлежит
end.
#include <iostream>
#include <string>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int arr_pattern[5] = { 1,3,3,2,2 };
int temp = 0;
string arr_temp[4] = { "(",")-","-","-" };
size_t j = 0;
string arr_str[5];
string str;
cout << "Введите номер телефона: ";
cin >> str;
for (size_t i = 0; i < sizeof(arr_pattern) / sizeof(arr_pattern[0]); i++) {
arr_str[i] = str.substr(0, arr_pattern[i]);
str.erase(0, arr_pattern[i]);
}
cout << str << endl;
for (size_t i = 0; i < 5; i++)
{
if (i == 4) {
cout << arr_str[i];
}
else {
cout << arr_str[i] << arr_temp[j];
j++;
}
}
}
.jpg
Объяснение:
Проверено в Bilim Land
Можно лучший ответ :3