master
Сommit
b616275308
@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
g++ -o general_program general_program.cpp
|
||||
general_program.exe < input.txt > output_general.txt
|
@ -0,0 +1,9 @@
|
||||
@echo off
|
||||
|
||||
g++ individual_program.cpp -o individual_program.exe
|
||||
|
||||
|
||||
individual_program.exe < input.txt > output_individual.txt
|
||||
|
||||
fc output_individual.txt expected_output.txt
|
||||
pause
|
@ -0,0 +1,2 @@
|
||||
Number of columns: 2
|
||||
Formula used: Square root formula (sqrt(N))
|
@ -0,0 +1,48 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
size_t number_count;
|
||||
cout << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
|
||||
vector<double> numbers(number_count);
|
||||
cout << "Enter numbers:\n";
|
||||
for (size_t i = 0; i < number_count; ++i) {
|
||||
cin >> numbers[i];
|
||||
}
|
||||
|
||||
size_t bin_count;
|
||||
cout << "Enter number of bins: ";
|
||||
cin >> bin_count;
|
||||
|
||||
double min = *min_element(numbers.begin(), numbers.end());
|
||||
double max = *max_element(numbers.begin(), numbers.end());
|
||||
double bin_size = (max - min) / bin_count;
|
||||
|
||||
vector<size_t> bins(bin_count, 0);
|
||||
for (double number : numbers) {
|
||||
size_t bin_index = static_cast<size_t>((number - min) / bin_size);
|
||||
if (bin_index >= bin_count) bin_index = bin_count - 1;
|
||||
bins[bin_index]++;
|
||||
}
|
||||
|
||||
size_t max_bin_count = *max_element(bins.begin(), bins.end());
|
||||
const size_t max_width = 80;
|
||||
double scaling_factor = max_bin_count > max_width ? static_cast<double>(max_width) / max_bin_count : 1.0;
|
||||
|
||||
for (size_t i = 0; i < bin_count; ++i) {
|
||||
cout << bins[i] << "|";
|
||||
size_t scaled_height = static_cast<size_t>(bins[i] * scaling_factor);
|
||||
for (size_t j = 0; j < scaled_height; ++j) {
|
||||
cout << '*';
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int N;
|
||||
cout << "Enter the total number of elements (N): ";
|
||||
cin >> N;
|
||||
|
||||
int columns;
|
||||
string formula_used;
|
||||
|
||||
if (N == 0) {
|
||||
columns = 0;
|
||||
formula_used = "None (N is 0)";
|
||||
} else {
|
||||
double sqrt_value = sqrt(N);
|
||||
|
||||
if (sqrt_value > 25) {
|
||||
columns = 1 + static_cast<int>(log2(N));
|
||||
formula_used = "Sturges' formula (1 + floor(log2(N)))";
|
||||
} else {
|
||||
columns = static_cast<int>(sqrt_value);
|
||||
formula_used = "Square root formula (sqrt(N))";
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Number of columns: " << columns << endl;
|
||||
cout << "Formula used: " << formula_used << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
7
|
||||
1 2 2 3 3 3 4
|
||||
4
|
@ -0,0 +1,5 @@
|
||||
Enter number count: Enter numbers:
|
||||
Enter number of bins: 1|*
|
||||
2|**
|
||||
3|***
|
||||
1|*
|
@ -0,0 +1,2 @@
|
||||
Enter the total number of elements (N): Number of columns: 2
|
||||
Formula used: Square root formula (sqrt(N))
|
@ -0,0 +1,45 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstdint>
|
||||
using namespace std;
|
||||
|
||||
void print_in_hex(uint8_t byte) {
|
||||
cout << hex << setw(2) << setfill('0') << static_cast<int>(byte) << " ";
|
||||
}
|
||||
|
||||
void print_in_hex(const void* data, size_t size) {
|
||||
const uint8_t* bytes = static_cast<const uint8_t*>(data);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
print_in_hex(bytes[i]);
|
||||
if ((i + 1) % 16 == 0) cout << endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void print_in_binary(uint8_t byte) {
|
||||
for (int i = 7; i >= 0; --i) cout << ((byte >> i) & 1);
|
||||
cout << " ";
|
||||
}
|
||||
|
||||
void print_in_binary(const void* data, size_t size) {
|
||||
const uint8_t* bytes = static_cast<const uint8_t*>(data);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
print_in_binary(bytes[i]);
|
||||
if ((i + 1) % 4 == 0) cout << endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
uint8_t data[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x12, 0x34, 0x56, 0x78};
|
||||
size_t size = sizeof(data);
|
||||
|
||||
cout << "Hexadecimal representation:" << endl;
|
||||
print_in_hex(data, size);
|
||||
|
||||
cout << "Binary representation:" << endl;
|
||||
print_in_binary(data, size);
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <bitset>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
uint16_t operand1, operand2;
|
||||
char operation;
|
||||
|
||||
cout << "Enter first operand: ";
|
||||
cin >> operand1;
|
||||
cout << "Enter operation (&, |, ^): ";
|
||||
cin >> operation;
|
||||
cout << "Enter second operand: ";
|
||||
cin >> operand2;
|
||||
|
||||
uint16_t result = 0;
|
||||
if (operation == '&') result = operand1 & operand2;
|
||||
else if (operation == '|') result = operand1 | operand2;
|
||||
else if (operation == '^') result = operand1 ^ operand2;
|
||||
else {
|
||||
cout << "Invalid operation" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << "Hexadecimal: " << hex << setw(4) << setfill('0') << result << endl;
|
||||
cout << "Binary: " << bitset<16>(result) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
using namespace std;
|
||||
|
||||
struct Student {
|
||||
char name[17];
|
||||
uint16_t enrollment_year;
|
||||
float gpa;
|
||||
uint8_t gender : 1; // 0 = female, 1 = male
|
||||
uint8_t courses_completed;
|
||||
Student* group_leader;
|
||||
};
|
||||
|
||||
void print_memory_info(const Student& student) {
|
||||
cout << "Name address: " << &student.name << ", size: " << sizeof(student.name) << endl;
|
||||
cout << "Year address: " << &student.enrollment_year << ", size: " << sizeof(student.enrollment_year) << endl;
|
||||
cout << "GPA address: " << &student.gpa << ", size: " << sizeof(student.gpa) << endl;
|
||||
cout << "Gender address: " << &student.gender << ", size: 1 bit" << endl;
|
||||
cout << "Courses address: " << &student.courses_completed << ", size: " << sizeof(student.courses_completed) << endl;
|
||||
cout << "Leader address: " << &student.group_leader << ", size: " << sizeof(student.group_leader) << endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
Student students[3] = {
|
||||
{"Alice", 2021, 3.8, 0, 5, nullptr},
|
||||
{"Bob", 2021, 3.5, 1, 4, nullptr},
|
||||
{"Charlie", 2020, 3.9, 1, 6, &students[0]}
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
cout << "Student " << i + 1 << " memory info:" << endl;
|
||||
print_memory_info(students[i]);
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
bool is_valid_filename(const char* filename) {
|
||||
const char* invalid_chars = "*<>?|";
|
||||
if (strpbrk(filename, invalid_chars)) return false;
|
||||
|
||||
const char* colon = strchr(filename, ':');
|
||||
if (colon && (colon != filename + 1 || !isalpha(filename[0]) || colon[1] != '\n')) return false;
|
||||
|
||||
const char* ext = strrchr(filename, '.');
|
||||
if (ext && strcasecmp(ext, ".txt") != 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void add_txt_extension(char* filename) {
|
||||
strcat(filename, ".txt");
|
||||
}
|
||||
|
||||
int main() {
|
||||
char filename[256];
|
||||
cout << "Enter filename: ";
|
||||
cin >> filename;
|
||||
|
||||
if (!is_valid_filename(filename)) {
|
||||
cout << "Invalid filename." << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!strrchr(filename, '.')) add_txt_extension(filename);
|
||||
|
||||
ifstream file(filename, ios::binary | ios::ate);
|
||||
if (!file.is_open()) {
|
||||
cout << "Failed to open file." << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
streamsize size = file.tellg();
|
||||
file.seekg(0, ios::beg);
|
||||
|
||||
char* buffer = new char[size];
|
||||
file.read(buffer, size);
|
||||
|
||||
char search[256];
|
||||
cout << "Enter string to search: ";
|
||||
cin >> search;
|
||||
|
||||
size_t count = 0;
|
||||
char* pos = buffer;
|
||||
while ((pos = strstr(pos, search))) {
|
||||
++count;
|
||||
pos += strlen(search);
|
||||
}
|
||||
|
||||
cout << "Occurrences: " << count << endl;
|
||||
|
||||
delete[] buffer;
|
||||
return 0;
|
||||
}
|
Загрузка…
Ссылка в новой задаче