Untitled
unknown
plain_text
4 years ago
8.7 kB
6
Indexable
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
// #include <windows.h>
// #include <conio.h>
#include <time.h>
#include <stdio.h>
#include <fstream>
#include <string>
using namespace std;
int Decoder(string a) {
int j = a.length();
a += "000";
int NUMBER = 0;
int x = 0, y = 0, z = 0, t = 0,
kv = 0, kl = 0, kd = 0, // критерий неповторяемости 5,50,500
k2 = 0, // критерий для вылета
k3 = 1001; // критерий следования цифр по убыванию, изначально ставлю максимум, чтобы считалось первое число
for (int i = 0; i < j; i++) {
switch (a[i]) {
case 73: x = 1; break; // I
case 86: x = 5; kv = kv + 1; break; // V
case 88: x = 10; break; // X
case 76: x = 50; kl = kl + 1; break; // L
case 67: x = 100; break; // C
case 68: x = 500; kd = kd + 1; break; // D
case 77: x = 1000; break; // M
}
switch (a[i + 1]) {
case 48: y = 0; break; // 0
case 73: y = 1; break; // I
case 86: y = 5; break; // V
case 88: y = 10; break; // X
case 76: y = 50; break; // L
case 67: y = 100; break; // C
case 68: y = 500; break; // D
case 77: y = 1000; break; // M
}
switch (a[i + 2]) {
case 48: z = 0; break; // 0
case 73: z = 1; break; // I
case 86: z = 5; break; // V
case 88: z = 10; break; // X
case 76: z = 50; break; // L
case 67: z = 100; break; // C
case 68: z = 500; break; // D
case 77: z = 1000; break; // M
}
switch (a[i + 3]) {
case 48: t = 0; break; // 0
case 73: t = 1; break; // I
case 86: t = 5; break; // V
case 88: t = 10; break; // X
case 76: t = 50; break; // L
case 67: t = 100; break; // C
case 68: t = 500; break; // D
case 77: t = 1000; break; // M
}
if (x < y) {
NUMBER = NUMBER - x;
k3 = x;
}
else if (y < k3) { NUMBER = NUMBER + x; //следующее за тем, из которого вычли
}
else { k2 = k2 + 1; } // если число не по убыванию, то делаю ошибку (IXI, LCC - нельзя)
if (y - x == x) { k2 = k2 + 1; } //проблема VX, LC
if ((x < z && y < z)
or (kl > 1) or (kd > 1) or (kv >1)
or ((x == y) && (y == z) && (z == t) && (t == x)) // критерий не повторения 4 цифр подряд
or (k2>0)) {
cout << "Некорректная запись числа" << endl;
return (0);
}
}
return (NUMBER);
}
int underline(int i) {
for (int j = 0; j < i; j++) {
cout << " ";
}
cout << endl;
return 0;
}
int star() {
for (int j = 0; j < 8; j++) {
cout << "*";
}
return 0;
}
using namespace std;
float length(float a1, float a2, float b1, float b2) {
float len;
len = sqrt(pow((a1 - b1), 2) + pow((a2 - b2), 2));
return (len);
}
float circle() {
float r1 = 0, r2 = 0, O1 = 0, O2 = 0, R = 0;
double S = 0;
cout << "Enter the center`s coordinates (x, y)" << endl;
cin >> O1 >> O2;
cout << "Enter the coordinates of any point on the circle (x, y)" << endl;
cin >> r1 >> r2;
R = length(O1, O2, r1, r2);
if (R > 0) {
S = 3.14 * R * R;
cout << "S = pi * r^2" << endl << "S = " << "3.14" << "*" << R << "*" << R << " = " << S;
}
else { cout << "Such circle does not exist"; }
return 0;
}
float rectangle() {
float S, a1, a2, b1, b2, c1, c2, R1, R2, R3;
cout << "Enter the coordinates of the first apex of your rectangle (x, y)" << endl;
cin >> a1 >> a2;
cout << "Enter the coordinates of the second apex of your rectangle (x, y)" << endl;
cin >> b1 >> b2;
cout << "Enter the coordinates of the third apex of your rectangle (x, y)" << endl;
cin >> c1 >> c2;
R1 = length(a1, a2, b1, b2);
R2 = length(a1, a2, c1, c2);
R3 = length(b1, b2, c1, c2);
if (R1 > 0 && R2 > 0 && R3 > 0) {
float minimum = min(min(R1, R2), R3);
float maximum = max(max(R1, R2), R3);
float L = R1 + R2 + R3 - (minimum + maximum);
S = minimum * L;
cout << "S = a * b" << endl << "S = " << minimum << "*" << L << " = " << S;
}
else { cout << "Such rectangle does not exist"; }
return 0;
}
float triangle() {
float S, a1, a2, b1, b2, c1, c2, L1, L2, L3, p;
cout << "Enter the coordinates of the first apex of your triangle (x, y)" << endl;
cin >> a1 >> a2;
cout << "Enter the coordinates of the second apex of your triangle (x, y)" << endl;
cin >> b1 >> b2;
cout << "Enter the coordinates of the third apex of your triangle (x, y)" << endl;
cin >> c1 >> c2;
L1 = length(a1, a1, b1, b2);
L2 = length(a1, a2, c1, c2);
L3 = length(b1, b2, c1, c2);
if ((L1 + L2 > L3) and (L1 + L3 > L2) and (L2 + L3 > L1)) {
p = (L1 + L2 + L3) * 0.5;
S = sqrt(p * (p - L1) * (p - L2) * (p - L3));
cout << "S = sqrt(p * (p - a) * (p - b) * (p - c))" << endl;
cout << "p = " << p << endl;
cout << "S = sqrt(" << p << " * (" << p << "-" << L1 << ")" << " * (" << p << "-" << L2 << ")" << " * (" << p << "-" << L3 << "))" << " = " << S;
}
else { cout << "Such triangle does not exist"; }
return 0;
}
int sign(float a) {
if (a > 0) { cout << 1; }
if (a < 0) { cout << -1; }
if (a == 0) { cout << 0; }
return 0;
}
int main()
{
// string b;
string abc = "file_4.txt";
ofstream fout;
ifstream fin;
int number_task=0;
int out = 1, Y, SH, L;
float a, b, c, d, e, f, x, D;
while(out){
switch (number_task)
{
case 0:
cout<< "\n\nInput number task:\n\n";
cout<<"[1] Задание.\n[2] Задание.\n[3] Задание.\n[4] Задание.\n[5] Задание.\n";
cin>> number_task;
break;
case 1:
fout.open(abc);
cout << "Введите 10 вещественных чисел в строчку через пробел" << endl;
fout.getline (cin, b);
fout << b;
fout.close();
fin.open(a);
if (!fin.is_open()) {
cout << "Ошибка" << endl;
}
else {
float S1, S2 = 0;
while (fin >> S1)
{
S2 = S2 + S1;
}
fin.close();
cout << S2;
}
number_task = 0;
break;
// case 2:
// ;
// float x;
// cout << "Введите число:" << endl;
// cin >> x;
// sign(x);
// number_task = 0;
// break;
// case 3:
// char x;
// cout << "Введите первую букву вашей фигуры:" << "\n" "О - окружность" << "\n" "П - прямоугольник" << "\n" "Т - треугольник" << endl;
// cin >> x;
// switch (x) {
// case -114: circle(); break;
// case -113: rectangle(); break;
// case -110: triangle(); break;
// }
// number_task = 0;
// break;
// case 4:
// HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //
// setlocale(0, "");
// int k = 0;
// for (int j = 0; j < 6; j++) {
// SetConsoleTextAttribute(hConsole, (WORD)((3 << 4) | 15)); // цвет звездочек
// star();
// if (k % 2 == 0) {
// SetConsoleTextAttribute(hConsole, 64);
// underline(42);
// }
// else {
// SetConsoleTextAttribute(hConsole, 112);
// underline(42);
// }
// k += 1;
// }
// for (int j = 0; j < 7; j++) {
// if (k % 2 == 0) {
// SetConsoleTextAttribute(hConsole, 64);
// underline(50);
// }
// else {
// SetConsoleTextAttribute(hConsole, 112);
// underline(50);
// }
// k += 1;
// }
// SetConsoleTextAttribute(hConsole, 7);
// number_task = 0;
// break;
// case 5:
// HDC hdc = GetDC(GetConsoleWindow());
// COLORREF penColor = RGB(255, 255, 255);
// double y;
// HPEN pen = CreatePen(PS_SOLID, 4, penColor);
// SelectObject(hdc, pen);
// MoveToEx(hdc, 0, 250, NULL);
// LineTo(hdc, 1500, 250);
// MoveToEx(hdc, 500, 0, NULL);
// LineTo(hdc, 500, 1000);
// for (int i = -1000; i < 1000; ++i) {
// y = sin(pi * i / 100);
// LineTo(hdc, 100 + i, 250 + int(50 * y));
// MoveToEx(hdc, 100 + i, 250 + int(50 * y), NULL);
// }
// while (!_kbhit());
// }
// number_task = 0;
// break;
// case 6:
// string b;
// cout << "Введите римское число:" << endl;
// getline(cin, b);
// cout << Decoder(b);
// number_task = 0;
// break;
// case 7:
// int m, i, c, S0, S1;
// cout << "Введите m, i, c" << endl;
// cin >> m >> i >> c;
// S0 = time(0);
// for (int j = 0; j < i; j++) {
// S1 = (m * S0 + j) % c;
// cout << S1 << " ";
// S0 = S1;
// }
// number_task = 0;
// break;
default:
number_task = 0;
break;
}
}
}
Editor is loading...