Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
1,468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.78 KB | None | 0 0
  1.  
  2. /*
  3. //4.6 Автоматный распознаватель
  4.  
  5.  
  6. #include <iostream>
  7. #include <cmath>
  8.  
  9. using namespace std;
  10.  
  11. void converter() {
  12. //переменные
  13. char buff[100];
  14. char err[100];
  15. for (int i = 0; i < 100; i++) {
  16. buff[i] = NULL;
  17. }
  18. int chetdef = 0;
  19.  
  20. int chetchik = 0;
  21.  
  22. cout << "Введите ваше римское число\n";
  23. cin.getline(buff, 100);
  24.  
  25. for (int i = 0; i < 100; i++)
  26. {
  27. if (buff[i] == NULL) continue;
  28.  
  29. switch (buff[i]) {
  30. case 'I':
  31. if (i + 1 < strlen(buff) && (buff[i + 1] == 'V' || buff[i + 1] == 'X' || buff[i + 1] == 'C')) {
  32. chetchik = chetchik - 1;
  33. }
  34. else chetchik = chetchik + 1;
  35. break;
  36. case 'V':
  37. chetchik = chetchik + 5;
  38.  
  39. break;
  40. case 'X':
  41. if (i + 1 < strlen(buff) && (buff[i + 1] == 'L' || buff[i + 1] == 'C' || buff[i + 1] == 'M')) {
  42. chetchik = chetchik - 10;
  43. }
  44. else chetchik = chetchik + 10;
  45. break;
  46. case 'L':
  47. chetchik = chetchik + 50;
  48.  
  49. break;
  50. case 'C':
  51. if (i + 1 < strlen(buff) && (buff[i + 1] == 'D' || buff[i + 1] == 'M')) {
  52. chetchik = chetchik - 100;
  53. }
  54. else chetchik = chetchik + 100;
  55. break;
  56. case 'D':
  57. chetchik = chetchik + 500;
  58.  
  59. break;
  60. case 'M':
  61. chetchik = chetchik + 1000;
  62.  
  63.  
  64. break;
  65. default: err[chetdef] = buff[i]; chetdef++;
  66. break;
  67.  
  68. }
  69.  
  70. }
  71. cout << "Числа не прошедшие обработку:\n ";
  72.  
  73. for (int i = 0; i < chetdef; i++) {
  74. if (chetdef > 0) {
  75. cout << err[i] << " ";
  76. }
  77. else cout << "Все числа прошли обработку";
  78.  
  79. }
  80. cout << endl;
  81. if (chetchik == 0) {
  82. cout << "Вы не ввели число для перевода" << endl;
  83. }
  84. else {
  85. cout << "Ваше арабское число\n " << chetchik << endl;
  86. }
  87.  
  88. }
  89. int main() {
  90. while (true) {
  91. setlocale(0, "rus");
  92. converter();
  93. }
  94. system("pause");
  95.  
  96. return 0;
  97. }
  98. */
  99.  
  100.  
  101.  
  102.  
  103.  
  104. //4.9 Системы счисления
  105.  
  106.  
  107. #include <iostream>
  108. #include <cmath>
  109.  
  110. using namespace std;
  111.  
  112. 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' };
  113.  
  114. string toSis(int num, int Sis)
  115. {
  116. string resStr = "";
  117. if (num < Sis)
  118. {
  119. resStr += simvols[num];
  120. }
  121. else
  122. {
  123. resStr = toSis(num / Sis, Sis) + simvols[num % Sis];
  124. }
  125. return resStr;
  126. }
  127.  
  128. void translatoorCC()
  129. {
  130. string num;
  131. string result;
  132. int num10 = 0;
  133. int numSis = 0;
  134. int resSis;
  135. cout << "число: ";
  136. cin >> num;
  137. cout << "система счисления: ";
  138. cin >> numSis;
  139. cout << "новая СС: ";
  140. cin >> resSis;
  141.  
  142. for (int i = num.size() - 1; i >= 0; i--)
  143. {
  144. for (int numSim = 0; numSim < numSis; numSim++)
  145. {
  146.  
  147. if (num[i] == simvols[numSim])
  148. {
  149. num10 += numSim * pow(numSis, (num.size() - i) - 1);
  150. }
  151. }
  152. }
  153.  
  154. result = toSis(num10, resSis);
  155. cout << "результат: " << result;
  156. }
  157.  
  158.  
  159. int main()
  160. {
  161. setlocale(0, "");
  162. translatoorCC();
  163. }
  164.  
  165.  
  166.  
  167.  
  168. //Алгоритм Евклида
  169. /*
  170.  
  171. #include<iostream>
  172. using namespace std;
  173.  
  174.  
  175. int NOD(int x, int y)
  176. {
  177. int i;
  178. while (x && y)
  179. if (x >= y) x %= y;
  180. else y %= x;
  181. return x | y;
  182. }
  183.  
  184. int main()
  185. {
  186. setlocale(0, "");
  187. int x, y;
  188. cout << "Первое число: ";
  189. cin >> x;
  190. cout << "Второе число: ";
  191. cin >> y;
  192. cout << "NOD -> " << NOD(x, y) << endl;
  193.  
  194.  
  195. system("pause");
  196. return 0;
  197. }
  198. */
  199.  
  200. //Ханойская башня
  201. /*
  202.  
  203. #include <iostream>
  204.  
  205. using namespace std;
  206.  
  207. void hanoi_towers(int quantity, int from, int to, int buf_peg) //quantity-число колец, from-начальное положение колец(1-3),to-конечное положение колец(1-3)
  208. { //buf_peg - промежуточный колышек(1-3)
  209. if (quantity != 0)
  210. {
  211. hanoi_towers(quantity-1, from, buf_peg, to);
  212.  
  213. cout << from << " -> " << to << endl;
  214.  
  215. hanoi_towers(quantity-1, buf_peg, to, from);
  216. }
  217. }
  218.  
  219. int main()
  220. {
  221. setlocale(LC_ALL,"rus");
  222. int start_peg, destination_peg, buffer_peg, plate_quantity;
  223.  
  224. start_peg = 1;
  225.  
  226. destination_peg = 3;
  227.  
  228. buffer_peg = 2;
  229.  
  230. cout << "Количество дисков:" << endl;
  231. cin >> plate_quantity;
  232.  
  233. hanoi_towers(plate_quantity, start_peg, destination_peg, buffer_peg);
  234. system("pause");
  235. return 0;
  236. }
  237. */
  238.  
  239. // Решето
  240.  
  241. /*
  242. #include <iostream>
  243. using namespace std;
  244.  
  245. int main()
  246. {
  247. setlocale(LC_ALL, "RU");
  248. int n;
  249. cout << "Введите число" << endl;
  250. cin >> n;
  251. cout << endl;
  252. int* a = new int[n + 1];
  253. for (int i = 0; i < n + 1; i++)
  254. a[i] = i;
  255. for (int p = 2; p < n + 1; p++)
  256. {
  257. if (a[p] != 0)
  258. {
  259. cout << a[p] << endl;
  260. for (int j = p * p; j < n + 1; j += p)
  261. a[j] = 0;
  262. }
  263. }
  264. cin.get();
  265. }
  266. */
  267.  
  268.  
  269.  
  270. //Сортировка
  271.  
  272. /*
  273. #include <iostream>
  274.  
  275. using namespace std;
  276.  
  277. int main() {
  278. setlocale(LC_ALL, "rus");
  279.  
  280. int a[10]; // объявили массив на 10 ячеек
  281.  
  282. cout << "Введите 10 чисел для заполнения массива: " << endl;
  283.  
  284. for (int i = 0; i < 10; i++) {
  285. cin >> a[i]; // "читаем" элементы в массив
  286. }
  287.  
  288.  
  289.  
  290.  
  291. for (int i = 0; i < 10; ++i)
  292. for (int j = (i & 1) ? 1 : 2; j < 10; j += 2)
  293. if (a[j - 1] > a[j])
  294. swap(a[j - 1], a[j]);
  295.  
  296. cout << "Массив в отсортированном виде: ";
  297.  
  298. for (int i = 0; i < 10; i++) {
  299. cout << a[i] << " "; // выводим элементы массива
  300. }
  301. system("pause");
  302. return 0;
  303. }
  304. */
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312. //5
  313. /*
  314. #include <iostream>
  315. #include <vector>
  316. using namespace std;
  317. int main()
  318. {
  319. setlocale(LC_ALL, "Russian");
  320. int n, k;
  321. cout << "Введите количество свободных мест: ";
  322. cin >> n;
  323. cout << "Введите количество школьников: ";
  324. cin >> k;
  325. while (k != 1) {
  326. n = (n - k % 2) / 2;
  327. k /= 2;
  328. }
  329. cout << "Остаток мест слева/справа \n -> " << (n - 1) / 2 << " \n -> " << n / 2 << endl;
  330. }
  331. */
  332.  
  333.  
  334.  
  335. /*
  336.  
  337.  
  338.  
  339. #include <iostream>
  340. #include <algorithm>
  341. #include <vector>
  342. using namespace std;
  343.  
  344. bool proverka(vector<int> ball)
  345. {
  346. for (int i = 0; i < ball.size(); i++)
  347. {
  348. if (i + 1 == ball[i])
  349. {
  350. return true;
  351. }
  352. }
  353. }
  354.  
  355. int main()
  356. {
  357. setlocale(0, "");
  358. cout << "Введите количество шаров -> ";
  359. int n;
  360. cin >> n;
  361. vector< int > vector;
  362. int count = 0;
  363.  
  364. for (int i = 1; i <= n; i++)
  365. {
  366. vector.push_back(i);
  367. }
  368. do
  369. {
  370. if (proverka(vector) == true)
  371. {
  372. count += 1;
  373. }
  374. }
  375. while (next_permutation(vector.begin(), vector.end()));
  376. cout << "Количество подходящих вариаций ->" << count << endl;
  377. system("pause");
  378. return 0;
  379. }
  380.  
  381.  
  382. */
  383.  
  384.  
  385.  
  386. /*#include <iostream>
  387. using namespace std;
  388.  
  389. int main()
  390. {
  391. setlocale(0, "");
  392. int P = 0, M, N;
  393.  
  394. cout << "Размеры листа:" << endl;
  395. cin >> M >> N;
  396.  
  397. for (int i = 0; i < M; i++)
  398. {
  399. for (int j = 0; j < N; j++)
  400. P += (M - i) * (N - j);
  401. }
  402. cout << "Кол-во возможных вырезанных прямоугольников: " << P;
  403. }
  404. */
  405.  
  406. /*
  407. #include <iostream>
  408. #include <ctime>
  409. #include <algorithm>
  410. #include <list>
  411. using namespace std;
  412. int podr(int mas[9])
  413. {
  414. int max = 0, maxl = 0;
  415. if (mas[0] == 6)
  416. max++;
  417. max = maxl;
  418. for (int i = 1; i < 9; i++)
  419. if (mas[i] == 6)
  420. {
  421. if (mas[i] == 6)
  422. maxl++;
  423. if (maxl > max)
  424. max = maxl;
  425. }
  426. else maxl = 0;
  427. return(max);
  428. }
  429.  
  430. void sp4()
  431. {
  432. setlocale(0, "");
  433. int t, n;
  434. cout << "Введите кол-во свободных мест: ";
  435. cin >> n;
  436. int kupe[9];
  437. for (int i = 0; i < 9; i++)
  438. kupe[i] = 0;
  439. cout << "Введите номера свободных мест: \n";
  440. for (int i = 0; i < n; i++)
  441. {
  442. cin >> t;
  443. if (t <= 36) kupe[(t - 1) / 4] ++;
  444. if (t >= 37) kupe[8 - (t - 37) / 2] ++;
  445. }
  446. cout << podr(kupe);
  447. }
  448. void main()
  449. {
  450. sp4();
  451. }
  452.  
  453. */
  454.  
  455.  
  456. /*
  457.  
  458. #include <iostream>
  459. #include <string>
  460. #include <fstream>
  461. using namespace std;
  462.  
  463. int main()
  464. {
  465.  
  466. // Объявляем массив с гласными буквами
  467. char glas[6];
  468. glas[0] = 'a';
  469. glas[1] = 'e';
  470. glas[2] = 'i';
  471. glas[3] = 'o';
  472. glas[4] = 'y';
  473. glas[5] = 'u';
  474.  
  475.  
  476. //считываем предложение.
  477. string predl;
  478. string buff;
  479. ifstream fin("slova.txt", ios::in);
  480. while (!fin.eof())
  481. {
  482. getline(fin, buff);
  483. predl += buff;
  484. }
  485. fin.close();
  486. //считываем слово посимвольно
  487.  
  488. char slovo[21];
  489. int nletter = 0;
  490. char probel = ' ';
  491. ofstream fout("slovatt.txt", ios::out);
  492. do
  493. {
  494. int count = 0;
  495. for (int j = 0; j <= 20; j++)
  496. slovo[j] = ' '; //избавляемся от мусора в массиве
  497.  
  498. while (probel != predl[nletter] && nletter < predl.size() - 1)// считывание слова
  499. {
  500. slovo[count] = predl[nletter];
  501. count = count + 1;
  502. nletter = nletter + 1;
  503. }
  504. //ищем гласные и выводим в файл через дефисы слоги
  505. int pois = 0;
  506. int i;
  507. int flag = 300;
  508.  
  509. for (i = 0;; i++)
  510. {
  511. fout << slovo[i];
  512. if (slovo[i] == probel) break;
  513. else
  514. {
  515. for (pois = 0; pois <= 10; pois++)
  516. {
  517. if (slovo[i] == glas[pois])
  518. if (slovo[i + 1] == probel) break;
  519. else
  520. {
  521. fout << "-";
  522. pois = 10;
  523. }
  524. }
  525. }
  526.  
  527. }
  528. ++nletter;
  529. } while (nletter < predl.size());
  530.  
  531. fout.close();
  532.  
  533. return 0;
  534. }
  535. */
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601. //3.4 «Фильтр»
  602.  
  603.  
  604. /*#include <iostream>
  605. #include <fstream>
  606. using namespace std;
  607.  
  608. int main()
  609. {
  610. ifstream file("data.txt");
  611. int b;
  612. do
  613. {
  614. if (file >> b)
  615. cout << b << endl;
  616. else
  617. {
  618. file.clear();
  619. file.ignore(1, ' ');
  620. }
  621. } while (!file.eof());
  622. file.close();
  623. return 0;
  624. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement