Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## 1
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- system("chcp 1251");
- ofstream fileout("input.txt");
- // Установить начальную точку генерирования последовательности
- srand(31);
- for (int i = 0; i < 10; i++) {
- fileout << rand()<<"\n";
- }
- int s=0;
- fileout.close();
- ifstream filein ("input.txt");
- int number;
- if (filein) {
- for (int i = 0; i < 10; i++) {
- filein >> number;
- s += number;
- }
- cout << "Сумма чисел: " << s;
- }
- else {
- cout << "Нету такого файла(";
- }
- filein.close();
- }
- ## 2
- #include <iostream>
- using namespace std;
- int sign(float x) {
- if (x > 0)
- return 1;
- else if (x == 0)
- return 0;
- else
- return -1;
- }
- int main()
- {
- system("chcp 1251");
- cout << "Задача «Знак числа»\n";
- cout << "x = ";
- float x;
- cin >> x;
- cout << "sign(x) = " << sign(x);
- }
- ## 3
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include <iostream>
- using namespace std;
- double area_rectangle() {
- cout << "Площадь прямоугольника\n";
- double a,b;
- cout << "a = ";
- cin >> a;
- cout << "b = ";
- cin >> b;
- return a * b;
- }
- double area_triangle() {
- cout << "Площадь треугольника\n";
- double a, h;
- cout << "a = ";
- cin >> a;
- cout << "h = ";
- cin >> h;
- return 0.5*a*h;
- }
- double area_circle() {
- cout << "Площадь круга\n";
- double r;
- cout << "r = ";
- cin >> r;
- return M_PI*r*r;
- }
- int main()
- {
- system("chcp 1251");
- cout << "Задача «Геометрические фигуры»\n";
- cout << "Укажите, площадь какой фигуры нужно вычислить\n\t1 - прямоугольник\n\t2 - треугольник\n\t3 - круг\n";
- int n;
- cin >> n;
- switch (n)
- {
- case 1:
- cout<<area_rectangle();
- break;
- case 2:
- cout << area_triangle();
- break;
- case 3:
- cout << area_circle();
- break;
- }
- }
- ## 4
- #include <iostream>
- using namespace std;
- #include <windows.h>
- string symb_k_times(string symb, int k) {
- string result = "";
- for (int i = 0; i < k; i++)
- result += symb;
- return result;
- }
- int main()
- {
- HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
- system("chcp 1251");
- cout << "Задача «Былая слава»\n";
- SetConsoleTextAttribute(h, 0);
- int fl = 1;
- cout << symb_k_times(" ", 44)+"\n";
- for (int i = 0; i < 6; i++) {
- fl = (fl + 1) % 2;
- SetConsoleTextAttribute(h, 63);
- cout << " "+symb_k_times("* ", 8);
- SetConsoleTextAttribute(h, 200+fl*55);
- cout<<symb_k_times("_", 27) + "\n";
- }
- SetConsoleTextAttribute(h, 255);
- for (int i = 0; i < 7; i++) {
- fl = (fl + 1) % 2;
- SetConsoleTextAttribute(h, 200 + fl * 55);
- cout <<symb_k_times("_", 44)+"\n";
- }
- SetConsoleTextAttribute(h, 0);
- return 0;
- }
- ## 5
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main() {
- int height = 40;
- int width = 120;
- char A[100][200];
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- A[i][j]='O';
- }
- }
- int y;
- for (int i = -width/2+2; i < width/2-2; i++) {
- y = sin((float) i/10)*10;
- A[y+height/2][i+width/2] = ' ';
- }
- for (int i = 0; i < width; i++)
- A[height/2][i] = '-';
- for (int i = 0; i < height; i++)
- A[i][width/2] = '|';
- A[height / 2][width - 1] = '>';
- A[0][width/2] = '^';
- A[height / 2][width / 2] = '+';
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- cout<<A[i][j];
- }
- cout << "\n";
- }
- //a = sin(b)
- return 0;
- }
- ## 6
- #include <iostream>
- #include <map>
- #include <string>
- #include <fstream>
- #include <vector>
- using namespace std;
- int main()
- {
- system("chcp 1251");
- map<string, int> m = {
- {"I", 1}, {"II", 2},{"III", 3},{"IV", 4},{"V", 5},{"VI", 6},{"VII", 7},{"VIII", 8},{"IX", 9},
- {"X", 10}, {"XX", 20}, {"XXX", 30}, {"XL", 40}, {"L", 50}, {"LX", 60}, {"LXX", 70}, {"LXXX", 80}, {"XC", 90},
- { "C", 100 }, { "CC", 200 }, { "CCC", 300 }, { "CD", 400 }, { "D", 500 }, { "DC", 600 }, { "DCC", 700 }, { "DCCC", 800 }, { "CM", 900 },
- { "M", 1000 } , { "MM", 2000 }, { "MMM", 3000 }
- };
- //['I', 'V', 'X', 'L', "C", 'D', 'M']
- string inp;
- cout << "roman_number = ";
- cin >> inp;
- int n = inp.length();
- int i = 0;
- string buff="";
- bool was_error = false;
- vector<int> v;
- while (i < inp.length()) {
- if (m.count(buff + inp[i])) {
- buff += inp[i];
- }
- else if (!(inp[i] == 'I' || inp[i] == 'V' || inp[i] == 'X' || inp[i] == 'L' || inp[i] == 'C' || inp[i] == 'D' || inp[i] == 'M'))
- was_error = true;
- else {
- v.push_back(m.find(buff)->second);
- buff = inp[i];
- }
- i++;
- }
- if (m.count(buff))
- v.push_back(m.find(buff)->second);
- int s = 0;
- int prev_number = 10000;
- for (int i : v) {
- if (to_string(i).length() < to_string(prev_number).length()) {
- s += i;
- prev_number = i;
- }
- else {
- was_error = true;
- }
- }
- if (was_error)
- cout << "Ошибка";
- else
- cout << s;
- }
- ## 7
- // hw4_task7.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #include <iostream>
- using namespace std;
- int main()
- {
- long m, b, c, s0=0, s, idx;
- system("chcp 1251");
- cout << "m = ";
- cin >> m;
- cout << "b = ";
- cin >> b;
- cout << "c = ";
- cin >> c;
- cout << "i = ";
- cin >> idx;
- for (int i = 1; i < idx; i++) {
- s = (m * s0 + b) % c;
- s0 = s;
- cout << i << ") " << s << "\n";
- }
- }
- ## 8
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- system("chcp 1251");
- ifstream fin("input.txt");
- int A[10][10];
- //cout << "Hello World!\n";
- int n, m;
- //cout << "Введите матрицу A"<<"\n";
- //cout << "m = ";
- fin >> m;
- //cout << "n = ";
- fin >> n;
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- fin >> A[i][j];
- }
- }
- float B[10][10];
- int w, t;
- //cout << "Введите матрицу B" << "\n";
- //cout << "w = ";
- fin >> w;
- //cout << "t = ";
- fin >> t;
- for (int i = 0; i < w; i++) {
- for (int j = 0; j < t; j++) {
- fin >> B[i][j];
- }
- }
- float C[10][10];
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < t; j++) {
- C[i][j] = 0;
- for (int q=0; q < n; q++) {
- C[i][j] += A[i][q] * B[q][j];
- }
- }
- }
- cout << "Матрица С\n";
- float s = 0;
- float s_com = 0;
- int mini_s = 0, mini_s_com = 0;
- int max_s = 0, max_s_com = 0;
- for (int i = 0; i < m; i++) {
- if (C[i][0] < C[mini_s][0])
- mini_s = i;
- if (C[i][0] > C[max_s][0])
- max_s = i;
- s += C[i][0];
- }
- cout << "1) " <<max_s+1<< " и " <<mini_s+1<<"\n";
- for (int i = 0; i < m; i++) {
- if (C[i][1] < C[mini_s_com][1])
- mini_s_com = i;
- if (C[i][1] > C[max_s_com][1])
- max_s_com = i;
- s_com += C[i][1];
- }
- cout << "1) " << max_s_com+1 << " и " << mini_s_com+1<<"\n";
- cout << "3) " << s<<"\n";
- cout << "4) " << s_com<<"\n";
- cout << "5) " << s_com+s<<"\n";
- }
- ## 9
- #include <iostream>
- #include <string>
- using namespace std;
- string n_to_q(long n, long q) {
- string result="";
- if (n < q) {
- if (n < 10 && n >= 0)
- result += to_string(n);
- else
- result.push_back((char)(n + 55));
- }
- else {
- result = n_to_q(n / q, q);
- if (n%q < 10 && n%q >= 0)
- result += to_string(n%q);
- else
- result.push_back((char)(n%q + 55));
- }
- return result;
- }
- int main()
- {
- long n, new_q, old_q;
- string input;
- system("chcp 1251");
- cout << "Задача «Системы счисления»\n";
- cout << "old_q = ";
- cin >> old_q;
- cout << "number = ";
- cin >> input;
- n = 0;
- for (char i: input) {
- n *= old_q;
- if (isdigit(i))
- n += ((int)(i - 48));
- else
- n += ((int)(toupper(i) - 55));
- }
- //cout << "n = "<<n<<"\n";
- cout << "new_q = ";
- cin >> new_q;
- cout << n_to_q(n, new_q)<<"\n";
- }
Advertisement
Comments
-
- Кириллица - зло
- Не усложняй чтение (да и написание) себе и коллегам.
Add Comment
Please, Sign In to add comment
Advertisement