iarik2008
28.02.2020 12:44

Для хранения растрового изображения размером 353×353 пикселей отвели 32 КБ памяти. Каково максимально возможное число цветов в палитре изображения?

Нажмите на рекламу ниже и сразу увидите ответ
Популярные вопросы:
Ответ:
Lizaveta9999
30.01.2023 01:14
У меня есть какие-то наработки, они под линукс, но на винде должно работать все, кроме управления цветом, его выкинешь.

#include <cstdlib>#include <string>#include <iostream>#include "field.h"using namespace std;
int main(int argc, char** argv, char** env){    srand(time(0));    vector< vector< string > > S;    S.resize(2);    S[0].push_back("Vremena_goda");    S[1].push_back("Zima"); S[1].push_back("Vesna"); S[1].push_back("Leto"); S[1].push_back("Osen");
    Field A(S, Field().clGreen, Field().clLightblue);    cout << A << std::endl;    return 0;}
#ifndef FIELD_H_INCLUDED#define FIELD_H_INCLUDED
#include <vector>#include <iterator>#include <algorithm>#include <string>#include <sstream>class Field{public:    enum ConsoleColor { clBlack, clRed, clGreen, clYellow, clBlue, clPurple, clLightblue, clWhite };private:    size_t field_width, field_height;    std::vector< std::vector< std::string > > Data;    std::vector< size_t > column_width;    ConsoleColor color_border, color_font;    std::string get_format_color_string(std::string S, ConsoleColor color)    {        std::stringstream result;        result << "\x1b[1;" << color + 30 << "m" << S << "\x1b[0m";        return result.str();    }    std::string str_mul(std::string s, size_t num)    {        std::string result = "";        for(size_t i = 0; i < num; i++)            result += s;        return result;    }public:    Field() {};    Field(std::vector< std::vector< std::string > > D,          ConsoleColor color_border,          ConsoleColor color_font) :        Data(D), color_border(color_border), color_font(color_font)    {        field_height = Data.size();        field_width = 0;        for(size_t i = 0; i < field_height; i++)            field_width = std::max(field_width, Data[i].size());        for(size_t i = 0; i < field_height; i++)            while(Data[i].size() < field_width)                Data[i].push_back("");        column_width.assign(field_width, 0);        for(size_t i = 0; i < field_height; i++)            for(size_t j = 0; j < field_width; j++)                column_width[j] = std::max(column_width[j], Data[i][j].length());    }    void logs()    {        std::cout << "field_height: " << field_height << std::endl;        std::cout << "field_widht: " << field_width << std::endl;    }    friend std::ostream& operator <<(std::ostream& output_stream, Field & field)    {        /*        std::cout << field.field_width << " " << field.field_height << std::endl;        for(size_t i = 0; i < field.Data.size(); i++)        {            for(size_t j = 0; j < field.Data[i].size(); j++)                std::cout << field.Data[i][j] << " ";            std::cout << std::endl;        }        */
        output_stream << field.get_format_color_string("        ┌", field.color_border);        for(size_t i = 0; i < field.field_width - 1; i++)        {            output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[i] + 2), field.color_border);            output_stream << field.get_format_color_string("┬", field.color_border);        }        output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);        output_stream << field.get_format_color_string("┐\n        ", field.color_border);
        for(size_t i = 0; i < field.field_height; i++)        {            output_stream << field.get_format_color_string("│", field.color_border);            for(size_t j = 0; j < field.field_width; j++)            {                std::stringstream ss;                ss << field.str_mul(" ", field.column_width[j] - field.Data[i][j].size() + 1) << (field.Data[i][j] != "" ? field.Data[i][j] : "");                output_stream << field.get_format_color_string(ss.str(), field.color_font);                output_stream << field.get_format_color_string(" │", field.color_border);            }            output_stream << "\n        ";            if(i != field.field_height - 1)            {                output_stream << field.get_format_color_string("├", field.color_border);                for(size_t j = 0; j < field.field_width - 1; j++)                {                    output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border);                    output_stream << field.get_format_color_string("┼", field.color_border);                }                output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);                output_stream << field.get_format_color_string("┤", field.color_border);            }            else            {                output_stream << field.get_format_color_string("└", field.color_border);                for(size_t j = 0; j < field.field_width - 1; j++)                {                    output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border);                    output_stream << field.get_format_color_string("┴", field.color_border);                }                output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);                output_stream << field.get_format_color_string("┘\n", field.color_border);            }            output_stream << "\n        ";        }        return output_stream;
    }};
#endif // FIELD_H_INCLUDED
0,0(0 оценок)
Ответ:
мротмсс
13.03.2021 23:33
//Java
import java.util.ArrayList;

class Main {
public static void main(String[] args) {
ArrayList<Integer> a = new ArrayList();

/**
 * Заполнение
 */
for (int i = 0; i < 50; i++)
a.add(i, new java.util.Random().nextInt(100));

/**
 * Пузырь
 */
for (int i = 0; i < 50; i++)
for (int j = 0; j < 50-i-1; j++)
if (a.get(j) > a.get(j+1)){
int b = a.get(j);
a.set(j, j+1);
a.set(j+1, b);
}

for (int i = 0; i < 50; i++)
System.out.print(a.get(i) + " ");
System.out.println("\n---");

/**
 * Удаляем
 */
a.remove(0);

for (int i = 0; i < 50-1; i++)
System.out.print(a.get(i) + " ");
}
}

Проверка:
1 2 3 4 5 6 7 8 9 10 12 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 96 98
---
2 3 4 5 6 7 8 9 10 12 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 96 98

Так как использовался, само расширяющийся массив, то при удалении, ничего сдвигать не нужно
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота