<file_sep>#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <sstream>
#include <windows.h>
#include <cstdlib>
//#include <system>

using namespace std;

int board[8][8];
int mStep[5];
int sheep[2];

void clearBoard(int board[8][8]){
   for(int j = 7; j > -1; j--){
        for(int i = 0; i < 8; i++){
                board[i][j] = 0;
        }
    }
}

void outputBoardTest(int board[8][8]){
   cout << endl;
    for(int j = 7; j > -1; j--){
        for(int i = 0; i < 8; i++){
            cout << board[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
}

void outputChessBoard(int board[8][8]){
   //cout << endl;
   cout << "___________________________________" << endl;


    for(int j = 7; j > -1; j--){
        cout << "|";
        for(int i = 0; i < 8; i++){

                if (board[i][j] == 1){
                    cout << " " << "O" << " ";
                }
                if (board[i][j] == 2){
                    cout << " " << "B" << " ";
                }
                if (board[i][j] == 0){
                    cout << "   ";
                }
                cout << "|";


        }

    cout << " " << j + 1;

    if (j == 7) {
        cout<< "\t\t\t" << "Волки и Овца";
    }
    if (j == 6) {
        cout<< "\t" << "Правила игры:";
    }
    if (j == 5) {
        cout<< "\t" << "2)Волки ходят на одну 1 клетку по диагонали, но только вперёд";
    }
    if (j == 4) {
        cout<< "\t" << "4)Волки побеждаю, когда овца не может никуда ходить";
    }
    if (j == 3) {
        cout<< "\t" << "куда она должна сходить";
    }

    if (j == 2) {
        cout<< "\t" << "откуда волк должен сделать ход и через '-' куда он должен сходить";
    }

    if (j == 1) {
        cout<< "\t\t\t " << "Пример ввода:";
    }
    if (j == 0) {
        cout<< "\t" << "Ob8-c7                               Bh1-g2  ";
    }

    cout << endl;
    cout << "|___|___|___|___|___|___|___|___|__";


    if (j == 6) {
        cout<< "\t" << "1)Овца ходит только на 1 клетку по диагонали";
    }
    if (j == 5) {
        cout<< "\t" << "3)Овца побеждает, когда доходит до 1 линии";
    }
    if (j == 4) {
        cout<< "\t" << "5)Чтобы сделать ход за овцу, необходимо ввести клетку,";
    }

    if (j == 3) {
        cout<< "\t" << "6)Чтобы сделать ход за волка, необходимо ввести клетку,";
    }
    if (j == 1) {
        cout<< "\t" << "Ходит овца:                          Ходит волк:  ";
    }

    cout << endl;
    }
    cout << "  a   b   c   d   e   f   g   h";
    cout << endl;
}

void inputStart(int Ostart){
    if(Ostart == 1){
        board[1][7] = 1;
        sheep[0] = 1;
        sheep[1] = 7;
    }
    if(Ostart == 2){
        board[3][7] = 1;
        sheep[0] = 3;
        sheep[1] = 7;
    }
    if(Ostart == 3){
        board[5][7] = 1;
        sheep[0] = 5;
        sheep[1] = 7;
    }
    if(Ostart == 4){
        board[7][7] = 1;
        sheep[0] = 7;
        sheep[1] = 7;
    }
    for(int i = 0; i < 8; i += 2){
        board[i][0] = 2;
    }

}

int locate(){

    int start = -1;
    char input[3];

    char symbol = getchar();
    int number = 0;
    while(symbol != '\n'){
        for(int i = 0; i < 3; i++){
            if (number == i){
                input[i] = symbol;
            }

        }
        number++;
        symbol = getchar();
    }

    if((input[0] == 'b') && (input[1] == '8')  && (number == 2)){
       start = 1;
    }
    if((input[0] == 'd') && (input[1] == '8')  && (number == 2)){
       start = 2;
    }
    if((input[0] == 'f') && (input[1] == '8')  && (number == 2)){
       start = 3;
    }
    if((input[0] == 'h') && (input[1] == '8')  && (number == 2)){
       start = 4;
    }

	return start;
}

int numb(char number){
    int output = -1;
    if((number >= '1') && (number <= '8')){
        output = number - '1';
    }
    return output;
}

int let(char letter){
    int output = -1;
    if((letter >= 'a') && (letter <= 'h')){
        output = letter - 'a';
    }
    return output;
}

void step(int animal){

    for (int i = 0; i < 5; i++){
        mStep[i] = -1;
    }

    //cout << "O";



    char input[6];//количество введёных символов

    if (animal == 1){
        cout << 'O';
        cout << (char)(sheep[0] + 'a');
        cout << (char)(sheep[1] + '1');
        cout << '-';
        char symbol = getchar();

        int number = 4;
        while(symbol != '\n'){
            for(int i = 4; i < 6; i++){
                if (number == i){
                    input[i] = symbol;
                }

            }
            number++;
            symbol = getchar();
        }
        input[0] = 'O';
        input[1] = (char)(sheep[0] + 'a');
        input[2] = (char)(sheep[1] + '1');
        input[3] = '-';
    }

    if (animal == 2){
        cout << 'B';
        char symbol = getchar();

        int number = 1;
        while(symbol != '\n'){
            for(int i = 1; i < 6; i++){
                if (number == i){
                    input[i] = symbol;
                }

            }
            number++;
            symbol = getchar();
        }
        input[0] = 'B';
    }

    //cout << input[0] << input[1] << input[2] << input[3] << input[4] << input[5] <<endl;

    if((input[0] == 'O') && (animal == 1) && (input[3] == '-')){//проверка для овцы
        mStep[0] = animal;
        mStep[1] = let(input[1]);
        mStep[2] = numb(input[2]);
        mStep[3] = let(input[4]);
        mStep[4] = numb(input[5]);
    }
    if((input[0] == 'B') && (animal == 2) && (input[3] == '-')){//проверка для волка
        mStep[0] = animal;
        mStep[1] = let(input[1]);
        mStep[2] = numb(input[2]);
        mStep[3] = let(input[4]);
        mStep[4] = numb(input[5]);
    }

    //cout << mStep[0] << mStep[1] << mStep[2] << mStep[3] << mStep[4] <<endl;

    int erorr = 0;
    for (int i = 0; i < 5; i++){
        if (mStep[i] == -1){
            erorr = -1;
        }
    }
    if (erorr != 0){
        for (int i = 0; i < 5; i++){
        mStep[i] = -1;
        }
    }
    //cout << erorr << endl;

}

void outputStepTest(){
    for (int i = 0; i < 5; i++){
        cout << mStep[i] << " ";
    }
    cout << endl;
}

int whoWin(){

    for (int i = 0; i < 8; i++){// если овца дошла до конца, то она победила
            if (board[i][0] == 1){
                //cout << "win1";
                return 1;
            }
        }

    if (sheep[1] < 7){
        if (sheep[0] == 0){//если находится слева (не на 8 строке) и зажата, то проигрышь
            if ((board[sheep[0] + 1][sheep[1] - 1] == 2) && (board[sheep[0] + 1][sheep[1] + 1] == 2)){
                //cout << "win2";
                return 2;
            }
        }
    }else{
        if (sheep[0] == 0){//если находится слева (на 8 строке) и зажата, то проигрышь
            if (board[sheep[0] + 1][sheep[1] - 1] == 2){
                //cout << "win3";
                return 2;
            }
        }
    }

    if (sheep[1] < 7){
        if (sheep[0] == 7){//если находится справа (не на 8 строке) и зажата, то проигрышь
            if ((board[sheep[0] - 1][sheep[1] - 1] == 2) && (board[sheep[0] - 1][sheep[1] + 1] == 2)){
                //cout << "win4";
                return 2;
            }
        }
    }else{
        if (sheep[0] == 7){//если находится справа (на 8 строке) и зажата, то проигрышь
            if (board[sheep[0] - 1][sheep[1] - 1] == 2){
                //cout << "win5";
                return 2;
            }
        }
    }

    if (sheep[1] < 7){
        if ((board[sheep[0] + 1][sheep[1] - 1] == 2) && (board[sheep[0] - 1][sheep[1] - 1] == 2) && (board[sheep[0] + 1][sheep[1] + 1] == 2) && (board[sheep[0] - 1][sheep[1] + 1] == 2)){// если зажата по бокам на 8 линии
            //cout << "win6";
            return 2;
        }
    }else{
        if ((board[sheep[0] + 1][sheep[1] - 1] == 2) && (board[sheep[0] - 1][sheep[1] - 1] == 2)){// если зажата по бокам на 8 линии
            //cout << "win7";
            return 2;
        }
    }
    return 0;
}

int PVP(int shOrWolf){


    int winner = -1;
    bool stop = true;
    //shOrWolf = 0;//счетчик ходов


    while (stop){
        system ("cls");
        outputChessBoard(board);
        if (shOrWolf % 2 == 0){//ход Овцы
            cout << "Ходит овца:" << endl;
            bool correct = false;
            step(1);
            int inputError = 0;
            while (!correct){
                if (mStep[0] != -1){
                    if((board[mStep[1]][mStep[2]] == 1) && (board[mStep[3]][mStep[4]] == 0) && ((mStep[2] == mStep[4] + 1) || (mStep[2] == mStep[4] - 1)) && ((mStep[1] == mStep[3] - 1) || (mStep[1] == mStep[3] + 1))){
                        board[mStep[1]][mStep[2]] = 0;
                        board[mStep[3]][mStep[4]] = 1;
                        sheep[0] = mStep[3];
                        sheep[1] = mStep[4];
                        correct = !correct;
                    }else{
                        inputError++;
                        system ("cls");
                        outputChessBoard(board);
                        cout << "Попыток неправельного ввода: " << inputError << endl;
                        cout << "Повторите ввод" << endl;
                        cout << "Ходит овца:" << endl;
                        step(1);
                        //cout << "erorr1" << endl;
                    }
                }else{
                    //cout << "erorr2" << endl;
                        inputError++;
                        system ("cls");
                        outputChessBoard(board);
                        cout << "Попыток неправельного ввода: " << inputError << endl;
                        cout << "Повторите ввод" << endl;
                        cout << "Ходит овца:" << endl;
                        step(1);
                }
            }
        }else{//ход волка
            cout << "Ходит волк:" << endl;
            bool correct = false;
            step(2);
            int inputError = 0;
            while (!correct){
                if (mStep[0] != -1){
                    if((board[mStep[1]][mStep[2]] == 2) && (board[mStep[3]][mStep[4]] == 0) && (mStep[2] == mStep[4] - 1) && ((mStep[1] == mStep[3] - 1) || (mStep[1] == mStep[3] + 1))){
                        board[mStep[1]][mStep[2]] = 0;
                        board[mStep[3]][mStep[4]] = 2;
                        correct = !correct;
                    }else{
                        inputError++;
                        system ("cls");
                        outputChessBoard(board);
                        cout << "Попыток неправельного ввода: " << inputError << endl;
                        cout << "Повторите ввод" << endl;
                        cout << "Ходит волк:" << endl;
                        step(2);
                    }
                }else{
                    inputError++;
                    system ("cls");
                    outputChessBoard(board);
                    cout << "Попыток неправельного ввода: " << inputError << endl;
                    cout << "Повторите ввод" << endl;
                    cout << "Ходит волк:" << endl;
                    step(2);
                }
            }
        }


        winner = whoWin();// проверяем на победу и в случае чего выходим
        if ((winner == 1) || (winner == 2) || (winner == -1)){
            stop = !stop;
        }

        shOrWolf++;
    }


    return winner;
}

bool repeat(){
    int inputError = 0;
    bool erorr = true;
        while(erorr){
            //system ("cls");
            if (inputError == 0){
                cout << "Чтобы начать игру заново введите: '1'" << endl;
                cout << "Чтобы закрыть игру введите: '0'" << endl;
            }else{
                system ("cls");
                cout << "Попыток неправельного ввода: " << inputError << endl;
                cout << "Повторите попытку" << endl;
                cout << "Чтобы начать игру заново введите: '1'" << endl;
                cout << "Чтобы закрыть игру введите: '0'" << endl;
            }

            char input[1];
            char symbol = getchar();
            int number = 0;
            while(symbol != '\n'){
                for(int i = 0; i < 1; i++){
                    if (number == i){
                        input[i] = symbol;
                    }

                }
                number++;
                symbol = getchar();
            }
            if (input[0] == '0'){
                system ("cls");
                return false;
            }
            if (input[0] == '1'){
                system ("cls");
                return true;
            }

            inputError++;
        }
}

int main(){
    bool rep = true;

    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    setlocale(LC_ALL,"russian");
    //rep = repeat();

    while (rep){
        clearBoard(board);

        //Выбор клетки, с которой начинает ходить овца
        int OStart = -1;
        int inputError = 0;
        //OStart = 1; // b8
        //OStart = 2; // d8
        //OStart = 3; // f8
        //OStart = 4; // h8


        ///*
        while(OStart == -1){
            if (inputError == 0){
                system ("cls");
                cout<< "Волки и Овца"<< endl;
                cout << endl;
                cout << "Введите клетку, с которой овца начнет ходить" << endl;
                cout << "Возможные варианты: 'b8', 'd8', 'f8', 'h8'" << endl;
            }else{
                system ("cls");
                cout << "Попыток неправельного ввода: " << inputError << endl;
                cout << "Повторите попытку" << endl;
                cout << "Введите клетку, с которой овца начнет ходить" << endl;
                cout << "Возможные варианты: 'b8', 'd8', 'f8', 'h8'" << endl;
            }
            OStart = locate();
            inputError++;
        }

        inputError = 0;
        inputStart(OStart);
        //*/


           /*
        board[0][6] = 1;
        board[1][5] = 2;
        board[2][6] = 2;
        sheep[0] = 0;
        sheep[1] = 6;
        //outputBoardTest(board);
        //outputChessBoard(board);
        */


        int endd = PVP(0);

        if (endd == 1){
            system ("cls");
            outputChessBoard(board);
            cout << "Победила овца" << endl;
            cout << endl;
            rep = repeat();
        }
        if (endd == 2){
            system ("cls");
            outputChessBoard(board);
            cout << "Победили волки" << endl;
            cout << endl;
            rep = repeat();
        }
        if (endd == -1){
            system ("cls");
            outputChessBoard(board);
            cout << "Erorr output" << endl;
            cout << endl;
            rep = repeat();
        }

        //step(1);// ход овцы
        //outputStepTest();

        //step(2);// ход волка
        //outputStepTest();
    }



    return 0;
    exit(0);
}
<file_sep>#include <iostream>
#include <math.h>
#include <iomanip>


using namespace std;

struct DataList{
	double Uy, Sy, Ux, Sx, t, a;
	DataList* next;
};

void startList(DataList* root){
	(*root).Uy = 0;
	(*root).Sy = 0;
	(*root).Ux = 0;
	(*root).Sx = 0;
	(*root).t = 0;
	(*root).a = 0;
	(*root).next = NULL;
}

void writeList(DataList* ls, double Ux, double Sx, double Uy, double Sy, double t, double a){
	DataList* lsEnd = ls;
	while ((*lsEnd).next != NULL)
		lsEnd = (*lsEnd).next;

	(*lsEnd).Uy = Uy;
	(*lsEnd).Sy = Sy;
	(*lsEnd).Ux = Ux;
	(*lsEnd).Sx = Sx;
	(*lsEnd).t = t;
	(*lsEnd).a = a;

	(*lsEnd).next = new DataList;
	startList((*lsEnd).next);
}

const double g = 9.80665;

/*
double deltaT = 0.01;
double Uy = 20;
double Sy = 0;
double Ux = 20;
double Sx = 0;
double Sx_max = 0;
double Sx_min = 1000;
*/
double percent = 0.75;
int rebound = 1;

DataList* simulate(double Ux, double Sx, double Uy, double Sy, double deltaT){
    DataList* output = new DataList;
	startList(output);

    double t = 0;
    for (int i = 0; i <= rebound; i++){
        while (Sy >= 0){
            Sx += deltaT*Ux;
            Sy += Uy*deltaT - (g*deltaT*deltaT)/2;
            Uy = Uy - (g*deltaT);
            t += deltaT;

            writeList(output, Ux, Sx, Uy, Sy, t, g);

            //cout << Sx << " " << Ux << endl;
            //cout << Sx << endl;
        }
        Uy = Uy *(-1)*percent;
        Sy = Sy*(-1);
    }

    return output;
}

void print(DataList* ls)
{
	cout << "Printing data" << endl;
	cout << "Time\tSx\tUx\tSy\tUy\t\tG" << endl;

	DataList* outLs = ls;
	while ((*outLs).next != NULL){
		cout << fixed << showpoint;
		cout << setprecision(2);
		cout << (double)(*outLs).t << "\t" << (*outLs).Sx << "\t" << (*outLs).Ux << "\t" << (*outLs).Sy << "\t" << (*outLs).Uy << "\t\t" << (*outLs).a << endl;
		outLs = (*outLs).next;
	}
}

bool testSimulate()
{
    double maxSy = 0;
    double minSy = 100;
    double deltaT = 0.01;
    double Uy = 20;
    double Sy = 0;
    double Ux = 3;
    double Sx = 0;
	DataList* outLs = simulate(Ux, Sx, Uy, Sy, deltaT);
    while ((*outLs).next != NULL){
        if ((*outLs).Sy > maxSy){
            maxSy = (*outLs).Sy;
        }
        if ((*outLs).Sy < minSy){
            minSy = (*outLs).Sy;
        }
        if ((*outLs).Ux != Ux){ // горизонтальная состовляющая постоянна
            return false;
        }
        outLs = (*outLs).next;
    }
    //cout << maxSy << "\t" << Uy*Uy/2/g - 0.02  << "\t" << Uy*Uy/2/g + 0.02<< endl;
    //cout << minSy << endl;
    if ((maxSy < (Uy*Uy/2/g - 0.2)) || (maxSy > (Uy*Uy/2/g + 0.2))){ // долетел до теоретического максимума
        return false;
    }
    if ((minSy > 0.2) || (minSy < -0.2)){ // удар об землю
       return false;
    }
    if ((*outLs).Sx != (*outLs).t*Ux){ // проверка на дальность полёта
       return false;
    }

	return true;
}

void runTest(bool (*testFunction)(), const string& testName)
{
	if (testFunction() == true)
		std::cout << "Test " << testName << " - OK" << std::endl;
	else
		std::cout << "Test " << testName << " - FAIL" << std::endl;
}

int main(){

    runTest(testSimulate, "Simulation");
    //DataList* dl = simulate(3, 0, 20, 0, 0.01);
	//print(dl);

    return 0;
}
<file_sep>#include <iostream>
using namespace std;

struct Node
{
	int val;
	Node* next;
};

void init(Node* node)
{
	node->val = 0;
	node->next = NULL;
}

void show(Node* root)
{
	Node* cur = root;
	while (cur->next != NULL)
	{
		cout << cur->val << " ";
		cur = cur->next;
	}
	cout << endl;
}

void pushNode(Node* root, Node* node)
{
	Node* cur = root;
	while (cur->next != NULL)
		cur = cur->next;

	cur->next = new Node;
	init(cur->next);
	cur->val = node->val;
}

void rShiftList(Node* root,int n)
{
	for (int i = 0; i < n; i++)
	{
		Node* cur = root;
		int num = cur->val;
		int x[2];

        x[0] = cur->next->val;
        cur->next->val = cur->val;
        cur->val = 0;

        int j =0;

		while (cur->next->next != NULL)
		{
            if(j%2 == 0 ){
                cur = cur->next;
                x[1] = cur->next->val;
                cur->next->val = x[0];
            }else{
                cur = cur->next;
                x[0] = cur->next->val;
                cur->next->val = x[1];
            }
            j++;
		}
	}
}

bool testrShiftList()
{
	Node* root = new Node;

	init(root);
	pushNode(root, new Node{ 1 });
	pushNode(root, new Node{ 2 });
	pushNode(root, new Node{ 3 });
	pushNode(root, new Node{ 4 });
	pushNode(root, new Node{ 5 });
	
	//show(root);
	rShiftList(root, 3);
	//show(root);
	return (root->val == 0 && root->next->val == 0 && root->next->next->val == 0 && root->next->next->next->val == 1 && root->next->next->next->next->val == 2);


}

static void runTest(bool (*testFunction)(), const string& testName)
{
	if (testFunction() == 1)
		std::cout << "Test " << testName << " - OK" << std::endl;
	else
		std::cout << "Test " << testName << " - FAIL" << std::endl;
}

int main()
{
	runTest(testrShiftList, "lRoundShiftTest");

}
<file_sep>#include <iostream>

using namespace std;

int mas[1000];

void input(int* source, int size){
    for(int i = 0; i < size; i++){
        cin >> source[i];
    }
}

void output(int* source, int size){
    for(int i = 0; i < size; i++){
        cout << source[i];
    }
}

void rShiftMas(int* source,int n, int size){
    for (int i = size - (n + 1); i != -1; i--)
        source[i+n] = source[i]; 
        
    for (int i = 0; i < n; i++)
        source[i] = 0;
}

bool comprasion(int* a, int* b, int size){
	for (int i = 0; i < size; i++){
		if (a[i] != b[i]){
		   return false; 
		}else{
		   return true; 
		}
	}
}
    
bool test(int* a, int* b, int n, int size)
{
	rShiftMas(a, n, size);
	return comprasion(a, b, size);
}

int main(){
    
    int n, size;
    
    n = 3;
    size = 8;
    
    int test_1_input[size] = {1, 2, 3, 4, 5, 6, 7, 8};
	int test_1_output[size] = {0, 0, 0, 1, 2, 3, 4, 5};
	int test_2_input[size] = {5, -4, 3, -2, 1, 0, 0, 0};
	int test_2_output[size] = {0, 0, 0, 5, -4, 3, -2, 1};
	
	if (test(test_1_input, test_1_output, n, size)){
	    cout << "True" << endl;  
	}else{
	    cout << "False" << endl;
	} 
	if (test(test_2_input, test_2_output, n, size)){
	    cout << "True" << endl;  
    }else{
        cout << "False" << endl;
    }
    
    /*
    cin >> n;
    cin >> size;
    
    input(mas, size);
    rShiftMas(mas, n, size);
    output(mas, size);
    */
    
    
    //rShiftMas(mas, n size);
    return 0;
}<file_sep># Boyarinov_Ivan_Practice_2021_summer
 
<file_sep>#include <iostream>

using namespace std;

int funct(int number, int variants){
    return number % variants + 1;
}

int main(){
    
    int number, variants;
    cin >> number;
    cin >> variants;
    
    cout << funct(number, variants);
    return 0;
}
<file_sep>#include <iostream>
#include <fstream> 
#include <Windows.h> 
#include <limits>

using namespace std;
const double g = 10;

struct flight
{
    int mh = 120;
    int mt = 57;
    int* points;
    double v=0;
    double a=0;
    double h=0;
    double t=0;
    double InputFlight(flight n_flight, double v0, double h0, double t0);
    void createImage(int t, int h);
    void initImage();
    void saveToPnmFile(string fileName);
    flight* next;
};

class List
{
    flight* head;
public:
    List() :head(NULL) {}; 
    ~List();   
    void AddFlight(flight n_flight);
    void ShowFlight(double t0, double t1);
};


List::~List()
{
    while (head != NULL)            
    {
        flight* temp;
        temp = head->next; 
        delete head;                   
        head = temp;                    
    }

}


double flight::InputFlight(flight n_flight, double v0, double h0, double t0)
{
    t = t0;
    h = h0 + v0 * t0 - g * t0 * t0 / 2;
    v = v0 - g * t0;
    a = -g;
    return h;
}


void List::AddFlight(flight n_flight)
{
    flight* temp;
    temp = new flight; 
    temp->next = head;
    temp->t = n_flight.t;
    temp->h = n_flight.h;
    temp->v = n_flight.v;
    temp->a = n_flight.a;
    head = temp;
}

int TestTime(double t1, double t2)
{
    if ((t1 > t2)||(t1<0)||(t2<0))
    {
        cout << "Ошибка в задании диапазона времени" << endl;
        return -1;
    }
    return 0;
}

int TestHight(double h0)
{
    double hMax = 20000;
    if ((h0 < 0) || (h0 > hMax))
    {
        cout << "Ошибка в задании начальной высоты" << endl;
        return -1;
    }
    return 0;
}

void List::ShowFlight(double t1,double t2)
{
    flight* temp;
    temp = head;
    while (temp != NULL)
    {
        if ((temp->t >= t1) && (temp->t <= t2))
        {
            cout << "t= " << temp->t << "\t\t";
            cout << "h= " << temp->h << "\t\t";
            cout << "v= " << temp->v << "\t\t";
            cout << "a= " << temp->a << endl;
            
        }
        temp = temp->next;
    }
    cout << endl;
}

void flight::initImage()
{
    int n = mt * mh;
    points = new int[n];
    for (int i = 0; i < n; i++)
        points[i] = 0;
}

void flight::createImage(int t, int h)
{
    int n;
    n = h * mt + t;
    points[n] = 1;

}

void flight::saveToPnmFile( string fileName)
{
    fstream fout(fileName, ios::out);
    int n;
    fout << "P1" << endl;
    fout << mt << " " << mh << endl;
    for (int i = mh-1; i >=0; i--)
    {
        for (int j = 0; j < mt; j++)
        {
            n = (i * mt + j);
            fout << points[n] << " ";
        }
        fout << endl;
    }
    fout << endl;
    fout.close();
}

int main()
{
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    flight n_flight;
    List lst;
    double v0 = 10;
    double g = 10;
    double m = 1;
    double h0 = 100;
    double t0;
    double h1=100;
    double t1 = 0;
    double t2 = 3;
    double dt = 0.1;
    t0 = t1;
    if ((TestTime(t1, t2) == -1)||(TestHight(h0)==-1))
    {
        return -1;
    }
    n_flight.initImage();
    while (h1 >=0)
    {
        h1 = n_flight.InputFlight(n_flight, v0, h0, t0);
        n_flight.createImage(t0*10, h1);
        lst.AddFlight(n_flight);
        t0 = t0 + dt;
    }
    lst.ShowFlight(t1,t2);
    n_flight.saveToPnmFile("image.pnm");
}
