1

(0 відповідей, залишених у Java)

Доброї години дня, шановні. При використанні графіків JavaFX, а саме LineChart - зіткнувся з проблемою. При додаванні двох серій на граф - серії не накладаються, а робляться так, як показано на скріні. Графіки - це розв'язки диференційних рівнянь різними методами, які повертають не цілі значення. Перевіряв, вводячи цілочисельні дані до серій - графіки накладались.

https://replace.org.ua/extensions/om_images/img/58c08b7c295ad/89355290_5246e2ba5bec48cce2adafe96f0d2cb6_800.png

обробник події, яким я виводжу передаю графіки на граф

 public void ok(){
        EulerMethod EM = new EulerMethod();
        RungeKuttaMethod RM = new RungeKuttaMethod();

        graf.getData().clear();
        graf.setTitle("Порівняння методів");
        graf.getData().addAll(EM.calc(), RM.calc());
        graf.setCreateSymbols(false);
    }

частина коду першого методу

public XYChart.Series calc(){
        XYChart.Series series = new XYChart.Series();
        series.setName("Метод Ейлера");
        while (x <= 3) {
            y = y + f(x, y) * h;
            x = x + h;
            String X = Double.toString(x);
            series.getData().addAll(new XYChart.Data<>(X, y));
        }
        return series;
    }

частина коду другого методу

public XYChart.Series calc() {
        XYChart.Series series1 = new XYChart.Series();
        series1.setName("Метод Рунге - Кутта");

        for (x = x0; x <= x1; ) {
            dy1_dx = f(x, y);
            k1 = dx * dy1_dx;
            x = x + dx / 2;
            y1d = y + k1 / 2;
            dy2_dx = f(x, y1d);
            k2 = dx * dy2_dx;
            y2d = y + k2 / 2;
            dy3_dx = f(x, y2d);
            k3 = dx * dy3_dx;
            y3d = y + k3;
            x = x + dx / 2;
            dy4_dx = f(x, y3d);
            k4 = dx * dy4_dx;
            y = y + (1.0 / 6) * (k1 + 2 * k2 + 2 * k3 + k4);
            String X = Double.toString(x);
            series1.getData().addAll(new XYChart.Data<>(X, y));
        }
        return series1;
    }

2

(1 відповідей, залишених у C++)

вирішив сам

3

(1 відповідей, залишених у C++)

Доброго вечора, маю таку проблему... В програмі необхідно ініціалізувати таблицю. так от, ініціалізую так:

private: void show(int size, int **mass) {
                 for (int i = 0; i < size; i++) {
                     for (int j = 0; j < size; j++) {
                         dataGridView1->TopLeftHeaderCell->Value = "Матриця відстаней";
                         dataGridView1->Columns[j]->HeaderCell->Value = Convert::ToString(j+1);
                         dataGridView1->Rows[i]->HeaderCell->Value = Convert::ToString(i+1);
                         dataGridView1->Rows[i]->Cells[j]->Value = mass[i][j];
                     }
                 }
             }

і при натисканні на кнопку таблиця заповнюється від'ємним значенням, хоча повинна заповнитись нулями. Що не вірно роблю?

4

(4 відповідей, залишених у C++)

truesupport написав:

Ідея в тому щоб витягнути кусок логіки яка відповідає за розрахунок результату в консольній програмі в якусь окрему сутність метод клас або ще щось такого роду наприклад

namespace Algorythm
{
    struct WAY_TYPE {
        int itabu;
        double length;
        int *tabu;
    };

    public class AntColonyAlgorythm
    {
    public:
        static WAY_TYPE CalculateResult(int vertex, double **distance0, int start, int finish)
        {
            // do something here
            WAY_TYPE type;
            return type;
        }
    };
}

і перевірити чи той кусок коду правильно працює, якщо працює ви з легкістю цей клас зможете перенети і в вашу вінформс аплікацію. Ви вже будете точно знати що у вас алгоритм працює бо ви перевірили його на консольній програмі і вже будете шукати свою помилку в обробленні користувацьких даних.

Тобто у вас в аплікаціях (консольній і формс) буде така логіка.
1. Отримати дані від користувача
2. Передати дані у метод Algorythm::AntColonyAlgorythm::CalculateResult
3 Отримати результат і показати його користувачу

Але ж я це вже робив, без форм - виведення працює як слід. Створивши форму, я перевірив правильність ініціалізації введених даних. Я по черзі виводив дані без виконання обчислень. Все ініціалізується і передається між textBoх - ами нормально. Значить - я не правильно передаю введені значення в алгоритм обчислення - тобто отут:

    WAY_TYPE way = AntColonyOptimization (D, N, --A, --B);

я не вірно передаю введені значення.

5

(4 відповідей, залишених у C++)

truesupport написав:

Дуже багато коду, я в тому тексбокс1 лейбл 2 не можу розібратись. Я можу вам порадити якомога більше відділити бізнес логіку (ваш алгоритм) від юаю, точніше навіть від 2вох (від консольного і від вінформс) Тобто щоб у вас був клас по типу.

AntColonyAlgorythm.GetResult(int input1, double input2, array input3)

А уже в юаях збираєте всі необхідні дані і передаєте в той метод. Так вам буде простіше знайти помилку я думаю.

тобто винести в окремий .h файл?

6

(4 відповідей, залишених у C++)

Ще раз доброго вечора. Є код вирішення задачі комівояджера мурашиним алгоритмом. Підключивши його до засобів Windows Forms я зіткнувся з тим - що виводить не вірне рішення.
Порівнявши виведення в консолі і у формі - відразу зрозуміло що саме не так.
Можливо я десь не вірно оголошую передачу введених даних?

#pragma once
#include"inf.h"
#include <stdlib.h>
#include <iostream>
#include <malloc.h>
namespace AntColonyAlgorythm {        
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

#define ALPHA    1
#define BETTA    3
#define T_MAX    100
#define M        20
#define Q        100
#define RHO        0.5

    /// <summary>
    /// </summary>
        struct WAY_TYPE {
    int itabu;
    double length;
    int *tabu;
};

    public ref class data : public System::Windows::Forms::Form
    {
        inf ^ F2;
    public:
        data(void)
        {
            InitializeComponent();
        }
    protected:
        /// <summary>
        /// </summary>
        ~data()
        {
            if (components)
            {
                delete components;
            }
        }
    protected: 
    private: System::Windows::Forms::Label^  label5;
    private: System::Windows::Forms::Button^  button4;
    private: System::Windows::Forms::Button^  button3;
    private: System::Windows::Forms::TextBox^  textBox6;
    private: System::Windows::Forms::Label^  label6;
    private: System::Windows::Forms::TextBox^  textBox5;
    private: System::Windows::Forms::Label^  label2;
    private: System::Windows::Forms::TextBox^  b;
    private: System::Windows::Forms::TextBox^  array;
    private: System::Windows::Forms::Label^  label4;
    private: System::Windows::Forms::Label^  label3;
    private: System::Windows::Forms::TextBox^  a;
    private: System::Windows::Forms::TextBox^  n;
    private: System::Windows::Forms::Button^  button2;
    private: System::Windows::Forms::Label^  label1;
    private:
        /// <summary>
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// </summary>
        void InitializeComponent(void)
        {
            System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(data::typeid));
            this->button4 = (gcnew System::Windows::Forms::Button());
            this->button3 = (gcnew System::Windows::Forms::Button());
            this->textBox6 = (gcnew System::Windows::Forms::TextBox());
            this->label6 = (gcnew System::Windows::Forms::Label());
            this->textBox5 = (gcnew System::Windows::Forms::TextBox());
            this->label5 = (gcnew System::Windows::Forms::Label());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->b = (gcnew System::Windows::Forms::TextBox());
            this->array = (gcnew System::Windows::Forms::TextBox());
            this->label4 = (gcnew System::Windows::Forms::Label());
            this->label3 = (gcnew System::Windows::Forms::Label());
            this->a = (gcnew System::Windows::Forms::TextBox());
            this->n = (gcnew System::Windows::Forms::TextBox());
            this->button2 = (gcnew System::Windows::Forms::Button());
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->SuspendLayout();
            // 
            // button4
            // 
            this->button4->Location = System::Drawing::Point(12, 396);
            this->button4->Name = L"button4";
            this->button4->Size = System::Drawing::Size(827, 40);
            this->button4->TabIndex = 5;
            this->button4->Text = L"Вихід";
            this->button4->UseVisualStyleBackColor = true;
            this->button4->Click += gcnew System::EventHandler(this, &data::button4_Click);
            // 
            // button3
            // 
            this->button3->Location = System::Drawing::Point(418, 350);
            this->button3->Name = L"button3";
            this->button3->Size = System::Drawing::Size(421, 40);
            this->button3->TabIndex = 4;
            this->button3->Text = L"Про програму";
            this->button3->UseVisualStyleBackColor = true;
            this->button3->Click += gcnew System::EventHandler(this, &data::button3_Click);
            // 
            // textBox6
            // 
            this->textBox6->Location = System::Drawing::Point(584, 52);
            this->textBox6->Multiline = true;
            this->textBox6->Name = L"textBox6";
            this->textBox6->Size = System::Drawing::Size(255, 193);
            this->textBox6->TabIndex = 3;
            // 
            // label6
            // 
            this->label6->AutoSize = true;
            this->label6->Location = System::Drawing::Point(469, 59);
            this->label6->Name = L"label6";
            this->label6->Size = System::Drawing::Size(90, 13);
            this->label6->TabIndex = 2;
            this->label6->Text = L"Довжина шляху:";
            // 
            // textBox5
            // 
            this->textBox5->Location = System::Drawing::Point(584, 12);
            this->textBox5->Name = L"textBox5";
            this->textBox5->Size = System::Drawing::Size(255, 20);
            this->textBox5->TabIndex = 1;
            // 
            // label5
            // 
            this->label5->AutoSize = true;
            this->label5->Location = System::Drawing::Point(469, 15);
            this->label5->Name = L"label5";
            this->label5->Size = System::Drawing::Size(36, 13);
            this->label5->TabIndex = 0;
            this->label5->Text = L"Шлях:";
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(9, 228);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(177, 13);
            this->label2->TabIndex = 10;
            this->label2->Text = L"Введіть початкову вершину від 1 :";
            this->label2->TextAlign = System::Drawing::ContentAlignment::TopCenter;
            // 
            // b
            // 
            this->b->Location = System::Drawing::Point(232, 225);
            this->b->Name = L"b";
            this->b->Size = System::Drawing::Size(166, 20);
            this->b->TabIndex = 11;
            // 
            // array
            // 
            this->array->Location = System::Drawing::Point(15, 75);
            this->array->Multiline = true;
            this->array->Name = L"array";
            this->array->Size = System::Drawing::Size(383, 134);
            this->array->TabIndex = 9;
            // 
            // label4
            // 
            this->label4->AutoSize = true;
            this->label4->Location = System::Drawing::Point(109, 59);
            this->label4->Name = L"label4";
            this->label4->Size = System::Drawing::Size(145, 13);
            this->label4->TabIndex = 8;
            this->label4->Text = L"Введіть матрицю відстаней";
            this->label4->TextAlign = System::Drawing::ContentAlignment::TopCenter;
            // 
            // label3
            // 
            this->label3->AutoSize = true;
            this->label3->Location = System::Drawing::Point(9, 254);
            this->label3->Name = L"label3";
            this->label3->Size = System::Drawing::Size(137, 13);
            this->label3->TabIndex = 12;
            this->label3->Text = L"Введіть кінцеву вершину :";
            // 
            // a
            // 
            this->a->Location = System::Drawing::Point(232, 251);
            this->a->Name = L"a";
            this->a->Size = System::Drawing::Size(166, 20);
            this->a->TabIndex = 13;
            // 
            // n
            // 
            this->n->Location = System::Drawing::Point(235, 12);
            this->n->Name = L"n";
            this->n->Size = System::Drawing::Size(166, 20);
            this->n->TabIndex = 3;
            // 
            // button2
            // 
            this->button2->Location = System::Drawing::Point(12, 350);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(391, 40);
            this->button2->TabIndex = 1;
            this->button2->Text = L"Підтвердити";
            this->button2->UseVisualStyleBackColor = true;
            this->button2->Click += gcnew System::EventHandler(this, &data::button2_Click);
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(12, 15);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(217, 13);
            this->label1->TabIndex = 2;
            this->label1->Text = L"Введіть кількість вершин від [ 3 ] до [ 30 ]:";
            this->label1->TextAlign = System::Drawing::ContentAlignment::TopCenter;
            // 
            // data
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->AutoScroll = true;
            this->AutoSize = true;
            this->BackColor = System::Drawing::SystemColors::ButtonFace;
            this->ClientSize = System::Drawing::Size(851, 448);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->button4);
            this->Controls->Add(this->a);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->label3);
            this->Controls->Add(this->textBox6);
            this->Controls->Add(this->n);
            this->Controls->Add(this->button3);
            this->Controls->Add(this->textBox5);
            this->Controls->Add(this->label6);
            this->Controls->Add(this->label4);
            this->Controls->Add(this->label5);
            this->Controls->Add(this->array);
            this->Controls->Add(this->b);
            this->Controls->Add(this->label2);
            this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
            this->MaximizeBox = false;
            this->Name = L"data";
            this->Text = L"data";
            this->Load += gcnew System::EventHandler(this, &data::data_Load);
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: void typing(int N, double **D) {
                 for (int i = 0; i < N; i++) {
                     for (int j = 0; j < N; j++){
                         double k = System::Convert::ToDouble(array->Text);
                         D[i][j] = k;}
                 }
             }

private: double probability (int to, WAY_TYPE ant, double **pheromone, double **distance, int vertex) {
    for (int i=0; i<ant.itabu; ++i) if (to == ant.tabu[i]) return 0;

    double sum = 0.0;
    int from = ant.tabu[ant.itabu-1];
    for (int j=0; j<vertex; ++j) {
        int flag = 1;
        for (int i=0; i<ant.itabu; ++i) if (j == ant.tabu[i]) flag = 0;
        if (flag) sum += pow (pheromone[from][j], ALPHA) * pow (distance[from][j], BETTA);
    }
    return pow (pheromone[from][to], ALPHA) * pow (distance[from][to], BETTA) / sum;
}

private: WAY_TYPE AntColonyOptimization (int vertex, double **distance0, int start, int finish) {
    WAY_TYPE way;
    way.itabu = 0;
    way.length = -1;
    way.tabu = (int *) malloc (sizeof (int) * vertex);
    double **distance = NULL, **pheromone = NULL;
    distance = (double **) malloc (sizeof (double *) * vertex);
    pheromone = (double **) malloc (sizeof (double *) * vertex);
    for (int i=0; i<vertex; ++i) {
        distance[i] = (double *) malloc (sizeof (double) * vertex);
        pheromone[i] = (double *) malloc (sizeof (double) * vertex);
        for (int j=0; j<vertex; ++j) {
            pheromone[i][j] = 1.0 / vertex;
            if (i != j) distance[i][j] = 1.0 / distance0[i][j];
        }
    }
    WAY_TYPE ants[M];
    for (int k=0; k<M; ++k) {
        ants[k].itabu = 0;
        ants[k].length = 0.0;
        ants[k].tabu = (int *) malloc (sizeof (int) * vertex);
        ants[k].tabu[ants[k].itabu++] = start;
    }

    for (int t=0; t<T_MAX; ++t) {
        for (int k=0; k<M; ++k) {
            do {
                int j_max = -1;
                double p_max = 0.0;
                for (int j=0; j<vertex; ++j) {
                    if (ants[k].tabu[ants[k].itabu-1] != j) {
                        double p = probability (j, ants[k], pheromone, distance, vertex);
                        if (p && p >= p_max) {
                            p_max = p;
                            j_max = j;
                        }
                    }
                }
                ants[k].length += distance0[ants[k].tabu[ants[k].itabu-1]][j_max];
                ants[k].tabu[ants[k].itabu++] = j_max;
            } while (ants[k].tabu[ants[k].itabu-1] != finish);
            for (int i=0; i<ants[k].itabu-1; ++i) {
                int from = ants[k].tabu[i % ants[k].itabu];
                int to = ants[k].tabu[(i+1) % ants[k].itabu];
                pheromone[from][to] += Q / ants[k].length;
                pheromone[to][from] = pheromone[from][to];
            }
            if (ants[k].length < way.length || way.length < 0) {
                way.itabu = ants[k].itabu;
                way.length = ants[k].length;
                for (int i = 0; i < way.itabu; ++i) way.tabu[i] = ants[k].tabu[i];
            }
            ants[k].itabu = 1;
            ants[k].length = 0.0;
        }
        for (int i=0; i<vertex; ++i)
            for (int j=0; j<vertex; ++j)
                if (i != j) pheromone[i][j] *= (1 - RHO);
    }
    return way;
}

private: System::Void data_Load(System::Object^  sender, System::EventArgs^  e) {
         }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
                int N = System::Convert::ToInt32(n->Text);
                double **D = new double *[N];
                for (int i = 0; i < N; i++) {
                    D[i] = new double[N];
                }
                int A = System::Convert::ToInt32(a->Text);
                int B = System::Convert::ToInt32(b->Text);
                WAY_TYPE way = AntColonyOptimization (N, D, --A, --B);
                textBox5->Text = System::Convert::ToString(way.length);
         }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
                    F2 = gcnew inf();
                F2->Show();
         }
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
                Application::Exit();                
         }
};
}

7

(6 відповідей, залишених у C++)

truesupport написав:

А, зрозумів, у вас там має бути N велике тоді все буде правильно, ви просто з назвами напутали.

так, все вірно, тільки що зрозумів

8

(6 відповідей, залишених у C++)

truesupport написав:

Я нічого не зрозумів, що у вас виводиться і що ви очікуєте щоб у вас відображалось. І взагалі що ви хочете зробити.

Вводиш 5 - повинно вивести 5, але виводить System.Windows.Forms.TextBox, Text:5

9

(6 відповідей, залишених у C++)

FakiNyan написав:

а шо оте

n

таке?

n - перейменований textBox1

10

(6 відповідей, залишених у C++)

Доброго дня, допоможіть з'ясувати в чому помилка. Виводиться System.Windows.Forms.TextBox, Text: і число яке я вводив

int N = System::Convert::ToInt32(n->Text);
textBox6->Text = System::Convert::ToString(n);

Доброго вечора. Намагався переписати код з С++ в джаву. В силу своїх поки, що малих знань, я не впевнений що все зробив правильно. Прошу вашої допомоги вказати на допущені помилки. На момент написання видимою є помилка java.lang.NullPointerException яку я ще не виправив. Лог помилки:
Exception in thread "main" java.lang.NullPointerException
    at ACO.AntColonyOptimization(ACO.java:21)
    at ALG.main(ALG.java:30)

Буду щиро вдячний за допомогу.
Програма складається з чотирьох класів:

клас №1 - константи

/* @author kotaine*/
public class Constanta {
    int N_MIN = 3;
    int N_MAX = 30;
    int ALPHA = 1;
    int BETTA = 3;
    int T_MAX = 100;
    int M = 20;
    int Q = 100;
    double RHO = 0.5;
}

клас №2 - визначає ймовірність переходу мурахи ant до вершини to

/*@author kotaine*/
public class Way_type {
    int itabu;
    int length;
    int tabu;
    double probability ( int to, Way_type W, double pheromone[][], double distance[][], int vertex) {
        Constanta CT = new Constanta();
        int T = W.tabu;
        int arr [] = new int [vertex];
        arr [vertex] = T;
        
        for (int m = 0; m < W.itabu; m++) { 
            if (to == arr[m]) {
                return 0;
            }
        }
                     double sum = 0.0;
    int from = arr [W.itabu - 1];
    for (int j = 0; j < vertex; j++) {
        boolean flag = true;
        for (int c = 0; c < W.itabu; ++c) 
                                        if (j ==arr [c]) 
                                         flag = false;
        if (flag) sum += Math.pow (pheromone[from][j], CT.ALPHA) * Math.pow (distance[from][j], CT.BETTA);
    }
    return Math.pow (pheromone[from][to], CT.ALPHA) * Math.pow (distance[from][to], CT.BETTA) / sum;
    }
}

клас №3 - алгоритм обчислення

/*@author kotaine*/
public class ACO {
    Way_type AntColonyOptimization (double distance0[][], int vertex, int start, int finish) {
    Way_type Way = new Way_type();
    Way.itabu = 0;
    Way.length = -1;
                  double distance[][] = new double [vertex][vertex];
                  double pheromone[][] = new double [vertex][vertex];
                  //double distance0 [][] = new double [vertex][vertex];
                           for (int z = 0; z < vertex; ++z) {
                                    for (int j=0; j<vertex; ++j) {
                                                      distance[z][j] = vertex;
            pheromone[z][j] = 1.0 / vertex;
            if (z != j) 
                            distance[z][j] = 1.0 / distance0[z][j];
        }
    }
                  Constanta CT = new Constanta();
                  Way_type ants[] = new  Way_type [CT.M];
                      for (int k = 0; k < CT.M; k++) {
        ants[k].itabu = 0;
        ants[k].length = 0;
                                    int AR = ants[k].tabu;
                                    int ar[] = new int [vertex];
                                    AR = ar[vertex];
                                    ar[ants[k].itabu++] = start;
    }
                  Way_type way = new Way_type();
                      for (int m = 0; m < CT.T_MAX; m ++) {
        for (int k = 0; k < CT.M; k++) {
                                        int AR = ants[k].tabu;
                                        int ar[] = new int [vertex];
                                        AR = ar[vertex];
            do {
                int j_max = -1;
                double p_max = 0.0;
                for (int j = 0; j < vertex; ++j) {
                    if (ar[ants[k].itabu - 1] != j) {
                        double p = Way.probability(j, way, pheromone, distance, vertex);
                        if (p  >= p_max) {
                            p_max = p;
                            j_max = j;
                        }
                    }
                }
                ants[k].length += distance0[ar[ants[k].itabu-1]][j_max];
                ar[ants[k].itabu++] = j_max;
            } while (ar[ants[k].itabu-1] != finish);
            for (int y = 0; y < ants[k].itabu - 1; y++) {
                int from = ar[y % ants[k].itabu];
                int to = ar[(y + 1) % ants[k].itabu];
                pheromone[from][to] += CT.Q / ants[k].length;
                pheromone[to][from] = pheromone[from][to];
            }
            if (ants[k].length < way.length || way.length < 0) {
                way.itabu = ants[k].itabu;
                way.length = ants[k].length;
                for (int v = 0; v < way.itabu; v++) {
                                                                        int W = way.tabu;
                                                                        int w [] = new int [v];
                                                                        W = w [v];
                                                                                            w[v] = ar[v];
                                }
            }
            ants[k].itabu = 1;
            ants[k].length =0;
        }
        for (int p = 0; p < vertex; ++p)
            for (int j = 0; j < vertex; j++)
                if (p != j) pheromone[p][j] *= (1 - CT.RHO);
    }
                        return way;
    }
}

клас №4 - запуск програми і введення/виведення даних

/* @author kotaine*/
import java.util.Scanner;

public class ALG {
        public static void main (String[] args) throws java.lang.Exception
    {
                  Constanta CT = new Constanta();
                  int N = 0, A = 0, B = 0;
    while ( N < CT.N_MIN || N  > CT.N_MAX) {
                                    Scanner sc = new Scanner (System.in);
                                    System.out.println ("Введіть кількість вершин: ");
                                    N = sc.nextInt();
                                    System.out.println("Введіть матрицю відстаней: ");
                                    double D [][] = new double [N][N];
                                            for (int i = 0; i < N; i++) {
                                            for (int j = 0; j < N; j++) {
                            D [i][j] = sc.nextInt();
    }
         }
    while (A < 1 || A > N) {
        System.out.println("Введіть початкову вершину від 1 до " + N + ": ");
                                    A = sc.nextInt();
    }
    while (B < 1 || B > N || B == A) {
        System.out.println("Введіть кінцеву вершину від 1 до " + N + " виключаючи " + A + ": ");
                                    B = sc.nextInt();
                                    }
                        ACO aco = new ACO();
                        aco.AntColonyOptimization(D, N, A, B);
                        Way_type WAY= new Way_type();
                        
                        System.out.println ("Довжина шляху: " + WAY.length );
                        int T = WAY.tabu;
                        int t [] = new int [0];
                        t [0] = T;
                        System.out.println ("Шлях: " + ++t [0]);
    for (int i = 1; i < WAY.itabu; i++) {
                        int R = WAY.tabu;
                        int ar [] = new int [i];
                        ar [i] = R;
                        System.out.println (" -> " + ++ar [i]);    
                             }
    }
        }
}

12

(4 відповідей, залишених у C++)

і що ви пропонуєте?

13

(4 відповідей, залишених у C++)

Дорий день, шановні. Допоможіть будь-ласка. Є код програми (С++) який рахує кількість елементів, що більші за попередній елемент. Як переробити даний код для того, щоб він рахував кількість ділянок, які утворюють неперервні послідовності чисел з значеннями які не зменшуються. (проблема полягає в тому, що через свою "неграмотність" я не можу дійти висновку, як саме написати цикл з пошуком ділянки з неперервною послідовністю)

using namespace std;
#include <iostream>
#include <stdio.h>
#include <ctime>
#include <malloc.h>
#include <conio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <malloc.h>
#include <locale.h>
int main(){
    setlocale(LC_ALL,"ukrainian");
;
srand(time(NULL));
const int n=200;
int a=0, b=100;
int A[n];
int counter(1);
for(int i(0); i<n; i++)
{
A[i]=rand()%(b-a+1)+a;
if(i!=0 && A[i]<A[i-1])
{counter++;}
if(i!=0 && A[i]>=A[i-1]);
cout <<A[i]<< ' ';
}
cout <<endl;
cout <<"кількість = "<< counter << endl;
putchar('\n');
return 0;
}

14

(1 відповідей, залишених у C++)

до задачі
//Даний символ C. Вивести два символи, перший з яких передує символу C в кодовій таблиці, а другий наступний за символом C. \\
створив код:
********
#include <iostream.h>
#include <stdio.h>
int main(void) {
char sdf[10];
int i=10;
string df = "C";
int sdf = df[0];
string d3f = "";
d3f+= (char)(sdf +1);
string df22 = "" ;
df22+= (char)(sdf -1);
return 0;
}
*********
код реалізував не повністю, вкажіть на суттєві помилки, і чого не вистачає до закінчення коду

15

(11 відповідей, залишених у C#, .NET)

Добридень, дано таке завдання
"Дано рядки S і S0. Видалити з рядка S перший підрядок, співпадаючий з S0. Якщо співпадаючих підрядків немає, то вивести рядок S без змін. "
хто може роз'яснити, як описати код, або хто зможе написати код джо даної задачі