Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- //4.6 Автоматный распознаватель
- #include <iostream>
- #include <cmath>
- using namespace std;
- void converter() {
- //переменные
- char buff[100];
- char err[100];
- for (int i = 0; i < 100; i++) {
- buff[i] = NULL;
- }
- int chetdef = 0;
- int chetchik = 0;
- cout << "Введите ваше римское число\n";
- cin.getline(buff, 100);
- for (int i = 0; i < 100; i++)
- {
- if (buff[i] == NULL) continue;
- switch (buff[i]) {
- case 'I':
- if (i + 1 < strlen(buff) && (buff[i + 1] == 'V' || buff[i + 1] == 'X' || buff[i + 1] == 'C')) {
- chetchik = chetchik - 1;
- }
- else chetchik = chetchik + 1;
- break;
- case 'V':
- chetchik = chetchik + 5;
- break;
- case 'X':
- if (i + 1 < strlen(buff) && (buff[i + 1] == 'L' || buff[i + 1] == 'C' || buff[i + 1] == 'M')) {
- chetchik = chetchik - 10;
- }
- else chetchik = chetchik + 10;
- break;
- case 'L':
- chetchik = chetchik + 50;
- break;
- case 'C':
- if (i + 1 < strlen(buff) && (buff[i + 1] == 'D' || buff[i + 1] == 'M')) {
- chetchik = chetchik - 100;
- }
- else chetchik = chetchik + 100;
- break;
- case 'D':
- chetchik = chetchik + 500;
- break;
- case 'M':
- chetchik = chetchik + 1000;
- break;
- default: err[chetdef] = buff[i]; chetdef++;
- break;
- }
- }
- cout << "Числа не прошедшие обработку:\n ";
- for (int i = 0; i < chetdef; i++) {
- if (chetdef > 0) {
- cout << err[i] << " ";
- }
- else cout << "Все числа прошли обработку";
- }
- cout << endl;
- if (chetchik == 0) {
- cout << "Вы не ввели число для перевода" << endl;
- }
- else {
- cout << "Ваше арабское число\n " << chetchik << endl;
- }
- }
- int main() {
- while (true) {
- setlocale(0, "rus");
- converter();
- }
- system("pause");
- return 0;
- }
- */
- //4.9 Системы счисления
- #include <iostream>
- #include <cmath>
- using namespace std;
- char simvols[32] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v' };
- string toSis(int num, int Sis)
- {
- string resStr = "";
- if (num < Sis)
- {
- resStr += simvols[num];
- }
- else
- {
- resStr = toSis(num / Sis, Sis) + simvols[num % Sis];
- }
- return resStr;
- }
- void translatoorCC()
- {
- string num;
- string result;
- int num10 = 0;
- int numSis = 0;
- int resSis;
- cout << "число: ";
- cin >> num;
- cout << "система счисления: ";
- cin >> numSis;
- cout << "новая СС: ";
- cin >> resSis;
- for (int i = num.size() - 1; i >= 0; i--)
- {
- for (int numSim = 0; numSim < numSis; numSim++)
- {
- if (num[i] == simvols[numSim])
- {
- num10 += numSim * pow(numSis, (num.size() - i) - 1);
- }
- }
- }
- result = toSis(num10, resSis);
- cout << "результат: " << result;
- }
- int main()
- {
- setlocale(0, "");
- translatoorCC();
- }
- //Алгоритм Евклида
- /*
- #include<iostream>
- using namespace std;
- int NOD(int x, int y)
- {
- int i;
- while (x && y)
- if (x >= y) x %= y;
- else y %= x;
- return x | y;
- }
- int main()
- {
- setlocale(0, "");
- int x, y;
- cout << "Первое число: ";
- cin >> x;
- cout << "Второе число: ";
- cin >> y;
- cout << "NOD -> " << NOD(x, y) << endl;
- system("pause");
- return 0;
- }
- */
- //Ханойская башня
- /*
- #include <iostream>
- using namespace std;
- void hanoi_towers(int quantity, int from, int to, int buf_peg) //quantity-число колец, from-начальное положение колец(1-3),to-конечное положение колец(1-3)
- { //buf_peg - промежуточный колышек(1-3)
- if (quantity != 0)
- {
- hanoi_towers(quantity-1, from, buf_peg, to);
- cout << from << " -> " << to << endl;
- hanoi_towers(quantity-1, buf_peg, to, from);
- }
- }
- int main()
- {
- setlocale(LC_ALL,"rus");
- int start_peg, destination_peg, buffer_peg, plate_quantity;
- start_peg = 1;
- destination_peg = 3;
- buffer_peg = 2;
- cout << "Количество дисков:" << endl;
- cin >> plate_quantity;
- hanoi_towers(plate_quantity, start_peg, destination_peg, buffer_peg);
- system("pause");
- return 0;
- }
- */
- // Решето
- /*
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RU");
- int n;
- cout << "Введите число" << endl;
- cin >> n;
- cout << endl;
- int* a = new int[n + 1];
- for (int i = 0; i < n + 1; i++)
- a[i] = i;
- for (int p = 2; p < n + 1; p++)
- {
- if (a[p] != 0)
- {
- cout << a[p] << endl;
- for (int j = p * p; j < n + 1; j += p)
- a[j] = 0;
- }
- }
- cin.get();
- }
- */
- //Сортировка
- /*
- #include <iostream>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "rus");
- int a[10]; // объявили массив на 10 ячеек
- cout << "Введите 10 чисел для заполнения массива: " << endl;
- for (int i = 0; i < 10; i++) {
- cin >> a[i]; // "читаем" элементы в массив
- }
- for (int i = 0; i < 10; ++i)
- for (int j = (i & 1) ? 1 : 2; j < 10; j += 2)
- if (a[j - 1] > a[j])
- swap(a[j - 1], a[j]);
- cout << "Массив в отсортированном виде: ";
- for (int i = 0; i < 10; i++) {
- cout << a[i] << " "; // выводим элементы массива
- }
- system("pause");
- return 0;
- }
- */
- //5
- /*
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int n, k;
- cout << "Введите количество свободных мест: ";
- cin >> n;
- cout << "Введите количество школьников: ";
- cin >> k;
- while (k != 1) {
- n = (n - k % 2) / 2;
- k /= 2;
- }
- cout << "Остаток мест слева/справа \n -> " << (n - 1) / 2 << " \n -> " << n / 2 << endl;
- }
- */
- /*
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- bool proverka(vector<int> ball)
- {
- for (int i = 0; i < ball.size(); i++)
- {
- if (i + 1 == ball[i])
- {
- return true;
- }
- }
- }
- int main()
- {
- setlocale(0, "");
- cout << "Введите количество шаров -> ";
- int n;
- cin >> n;
- vector< int > vector;
- int count = 0;
- for (int i = 1; i <= n; i++)
- {
- vector.push_back(i);
- }
- do
- {
- if (proverka(vector) == true)
- {
- count += 1;
- }
- }
- while (next_permutation(vector.begin(), vector.end()));
- cout << "Количество подходящих вариаций ->" << count << endl;
- system("pause");
- return 0;
- }
- */
- /*#include <iostream>
- using namespace std;
- int main()
- {
- setlocale(0, "");
- int P = 0, M, N;
- cout << "Размеры листа:" << endl;
- cin >> M >> N;
- for (int i = 0; i < M; i++)
- {
- for (int j = 0; j < N; j++)
- P += (M - i) * (N - j);
- }
- cout << "Кол-во возможных вырезанных прямоугольников: " << P;
- }
- */
- /*
- #include <iostream>
- #include <ctime>
- #include <algorithm>
- #include <list>
- using namespace std;
- int podr(int mas[9])
- {
- int max = 0, maxl = 0;
- if (mas[0] == 6)
- max++;
- max = maxl;
- for (int i = 1; i < 9; i++)
- if (mas[i] == 6)
- {
- if (mas[i] == 6)
- maxl++;
- if (maxl > max)
- max = maxl;
- }
- else maxl = 0;
- return(max);
- }
- void sp4()
- {
- setlocale(0, "");
- int t, n;
- cout << "Введите кол-во свободных мест: ";
- cin >> n;
- int kupe[9];
- for (int i = 0; i < 9; i++)
- kupe[i] = 0;
- cout << "Введите номера свободных мест: \n";
- for (int i = 0; i < n; i++)
- {
- cin >> t;
- if (t <= 36) kupe[(t - 1) / 4] ++;
- if (t >= 37) kupe[8 - (t - 37) / 2] ++;
- }
- cout << podr(kupe);
- }
- void main()
- {
- sp4();
- }
- */
- /*
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- int main()
- {
- // Объявляем массив с гласными буквами
- char glas[6];
- glas[0] = 'a';
- glas[1] = 'e';
- glas[2] = 'i';
- glas[3] = 'o';
- glas[4] = 'y';
- glas[5] = 'u';
- //считываем предложение.
- string predl;
- string buff;
- ifstream fin("slova.txt", ios::in);
- while (!fin.eof())
- {
- getline(fin, buff);
- predl += buff;
- }
- fin.close();
- //считываем слово посимвольно
- char slovo[21];
- int nletter = 0;
- char probel = ' ';
- ofstream fout("slovatt.txt", ios::out);
- do
- {
- int count = 0;
- for (int j = 0; j <= 20; j++)
- slovo[j] = ' '; //избавляемся от мусора в массиве
- while (probel != predl[nletter] && nletter < predl.size() - 1)// считывание слова
- {
- slovo[count] = predl[nletter];
- count = count + 1;
- nletter = nletter + 1;
- }
- //ищем гласные и выводим в файл через дефисы слоги
- int pois = 0;
- int i;
- int flag = 300;
- for (i = 0;; i++)
- {
- fout << slovo[i];
- if (slovo[i] == probel) break;
- else
- {
- for (pois = 0; pois <= 10; pois++)
- {
- if (slovo[i] == glas[pois])
- if (slovo[i + 1] == probel) break;
- else
- {
- fout << "-";
- pois = 10;
- }
- }
- }
- }
- ++nletter;
- } while (nletter < predl.size());
- fout.close();
- return 0;
- }
- */
- //3.4 «Фильтр»
- /*#include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- ifstream file("data.txt");
- int b;
- do
- {
- if (file >> b)
- cout << b << endl;
- else
- {
- file.clear();
- file.ignore(1, ' ');
- }
- } while (!file.eof());
- file.close();
- return 0;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement