Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <string>
  4. using namespace std;
  5.  
  6. void age(int user_age) {
  7. cout << "Ваш возраст в секундах: " << user_age * 365 * 24 * 60 * 60 << endl;
  8. }
  9.  
  10. void equals(int num) {
  11. if (num % 10 == (num/10) % 10 || num % 10 == (num/100) % 10 || num % 10 == (num/1000) % 10
  12. || (num/10) % 10 == (num/100) % 10 || (num/10) % 10 == (num/1000) % 10
  13. || (num/100) % 10 == (num/1000) % 10) {
  14. cout << "Есть" << endl;
  15. }
  16. else {
  17. cout << "Нет" << endl;
  18. }
  19. }
  20.  
  21. void change(int num) {
  22. int massive[4];
  23. int num_min = 1, num_max = 1, k;
  24. if (num > 10000 || num < 1000) {
  25. cout << "Неверный ввод\n";
  26. }
  27. for (int i = 3; i >= 0; i--) {
  28. massive[i] = num % 10;
  29. num = num / 10;
  30. }
  31. for (int i = 0; i < 4; i++) {
  32. if (massive[i] > massive[num_max]) {
  33. num_max = i;
  34. }
  35. if (massive[i] < massive[num_min]) {
  36. num_min = i;
  37. }
  38. }
  39. k = massive[num_min];
  40. massive[num_min] = massive[num_max];
  41. massive[num_max] = k;
  42. int new_num = 0;
  43. new_num = (massive[0] * 1000) + (massive[1] * 100) + (massive[2] * 10) + (massive[3]);
  44. cout << "Новое число: " << new_num << endl;
  45. }
  46.  
  47. void days(int num) {
  48. cout << "Полных недель прошло: " << num / 7 << endl;
  49. }
  50.  
  51. void authentication() {
  52. string real_password = "pavEL";
  53. string user_password;
  54. for (int i = 0; i < 3; i++) {
  55. cout << "Введите пароль: ";
  56. cin >> user_password;
  57. if (real_password == user_password) {
  58. cout << "Пароль введен вернo\n";
  59. break;
  60. }
  61. else {
  62. cout << "Пароль введен неверно\n";
  63. }
  64. if (i == 2) {
  65. cout << "Попыток больше нет\n";
  66. }
  67. }
  68. }
  69.  
  70. void exist(int k) {
  71. int sum = 0;
  72. for (int i = 1;; i++) {
  73. sum += i;
  74. if (sum > k) {
  75. cout << "Не существует\n";
  76. break;
  77. }
  78. if (sum == k) {
  79. cout << "Существует: n = " << i << endl;
  80. break;
  81. }
  82. }
  83. }
  84.  
  85. void randomize() {
  86. srand(3);
  87. int massive[10];
  88. for (int i = 0; i < 10; i++) {
  89. massive[i] = rand() % 101;
  90. }
  91. for (int i = 0; i < 9; i++) {
  92. for (int j = 0; j < 9 - i; j++) {
  93. if (massive[j] == massive[j + 1]) {
  94. massive[j] = rand() % 101;
  95. }
  96. }
  97. }
  98. for (int i = 0; i < 9; i++) {
  99. cout << massive[i] << " ";
  100. }
  101. cout << endl;
  102. }
  103. void division(int num) {
  104. for (int i = 10; i < 100; i++) {
  105. if ((i%num == 0) || ((i % 10 == num) || (i / 10) % 10 == num)) {
  106. cout << i << " ";
  107. }
  108. }
  109. cout << endl;
  110. }
  111. void zero_or_one() {
  112. int massive[10];
  113. massive[0] = 0;
  114. for (int i = 1; i < 10; i++) {
  115. if (massive[i - 1] == 0) {
  116. massive[i] = 1;
  117. }
  118. else {
  119. massive[i] = 0;
  120. }
  121. }
  122. for (int i = 0; i < 10; i++) {
  123. cout << massive[i] << " ";
  124. }
  125. cout << endl;
  126. }
  127.  
  128. void sqr() {
  129. int squares[10];
  130. for (int i = 1; i<11; i++) {
  131. squares[i - 1] = i * i;
  132. }
  133. for (int i = 0; i<10; i++) {
  134. cout << squares[i] << " ";
  135. }
  136. cout << endl;
  137. }
  138.  
  139. void randomize2(int n) {
  140. int* massive = new int[n];
  141. bool flag = false;
  142. for (int i = 0; i < n; i++) {
  143. cin >> massive[i];
  144. massive[i] = (int)massive[i];
  145. }
  146. for (int i = 0; i < n; i++) {
  147. for (int j = 0; j < n; j++) {
  148. if (massive[j] == i+1) {
  149. flag = true;
  150. break;
  151. cout << "true" << endl;
  152. }
  153. else {
  154. flag = false;
  155. }
  156. }
  157. if (flag == false) {
  158. cout << "Не содержит\n";
  159. break;
  160. }
  161. else {
  162. cout << "Содержит\n";
  163. break;
  164. }
  165. }
  166. cout << endl;
  167. }
  168.  
  169. void equals2() {
  170. int massive[6];
  171. int k=0, max=0;
  172. for (int i = 0; i < 6; i++) {
  173. cin >> massive[i];
  174. }
  175. for (int i = 0; i < 5; i++) {
  176. for (int j = 0; j < 6; j++) {
  177. if (massive[i] == massive[j+1] && (i!=j+1)) {
  178. k += 1;
  179. }
  180. }
  181. if (max < k) {
  182. max = k+1;
  183. }
  184. k = 0;
  185. }
  186. cout << "Максимальное количество повторений: " << max << endl;
  187. }
  188.  
  189. char chat_to_upper1(char elem) {
  190. int code = elem - 32;
  191. char result_elem = code;
  192. return result_elem;
  193. }
  194.  
  195. int fact(int n) {
  196. if (n == 0) {
  197. return 1;
  198. }
  199. if (n == 1) {
  200. return 1;
  201. }
  202. if (n > 1) {
  203. return n * fact(n - 1);
  204. }
  205. }
  206. void more(int num1, int num2) {
  207. int k = 0, n = 0;
  208. while (num1 > 0 || num2 > 0) {
  209. num1 = num1 / 10;
  210. num2 = num2 / 10;
  211. if (num1 > 0) {
  212. k += 1;
  213. }
  214. if (num2 > 0) {
  215. n += 1;
  216. }
  217. }
  218. if (k < n) {
  219. cout << "Во второй";
  220. }
  221. if (k > n) {
  222. cout << "В первой";
  223. }
  224. if (k == n) {
  225. cout << "Одинаково";
  226. }
  227. }
  228. int transformation(char a) {
  229. int b = a - '0';
  230. if (b < 0 || b>9) {
  231. return NAN;
  232. }
  233. else {
  234. return b;
  235. }
  236. }
  237. struct Chem {
  238. string fio = "Каёшкина Ю.Н.";
  239. string date = "19.06.2018";
  240. int mark;
  241. };
  242. struct Phys {
  243. string fio = "Стерлядкин В.В.";
  244. string date = "27.06.2018";
  245. int mark;
  246. };
  247. struct Math {
  248. string fio = "Святова Е.Н.";
  249. string date = "07.06.2018";
  250. int mark;
  251. };
  252. struct RecordBook {
  253. Math math;
  254. Phys phys;
  255. Chem chem;
  256. };
  257. struct Student {
  258. string name;
  259. string surname;
  260. int day;
  261. int month;
  262. int year;
  263. RecordBook record_book;
  264. void filling();
  265. void show();
  266. int julian();
  267. };
  268. void Student::filling() {
  269. cout << "Введите имя студента: ";
  270. cin >> name;
  271. cout << "Введите фамилию студента: ";
  272. cin >> surname;
  273. cout << "Введите день рождения: ";
  274. cin >> day;
  275. cout << "Введите месяц рождения: ";
  276. cin >> month;
  277. cout << "Введите год рождения: ";
  278. cin >> year;
  279. }
  280.  
  281. void Student::show() {
  282. cout << name << " " << surname << "|" << day << "." << month << "." << year << endl;
  283. }
  284. int Student::julian() {
  285. int a = (14 - month) / 12;
  286. int y = year + 4800 - a;
  287. int m = month + 12 * a - 3;
  288. int JDN = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;
  289. return JDN;
  290. }
  291. void swap(Student &x, Student &y) {
  292. Student temp = x;
  293. x = y;
  294. y = temp;
  295. }
  296.  
  297. int main() {
  298. system("chcp 1251>nul");
  299. age(18);
  300. equals(1357);
  301. change(4231);
  302. days(256);
  303. //authentication();
  304. exist(7);
  305. randomize();
  306. division(5);
  307. zero_or_one();
  308. sqr();
  309. //randomize2(6);
  310. //equals2();
  311. //char a;
  312. //cin >> a;
  313. //cout<<chat_to_upper1(a);
  314. cout << fact(5) << endl;
  315. more(120, 5000);
  316. //char b;
  317. //cin >> b;
  318. //cout << transformation(b) << endl;
  319. cout << "\nВведите количество студентов: ";
  320. int n;
  321. cin >> n;
  322. Student* students = new Student[n];
  323. for (int i = 0; i < n; i++) {
  324. students[i].filling();
  325. }
  326. for (int i = 0; i < n - 1; i++) {
  327. for (int j = 0; j < n - 1 - i; j++) {
  328. if (students[j].julian() > students[j + 1].julian()) {
  329. swap(students[j], students[j + 1]);
  330. }
  331. }
  332. }
  333. for (int i = 0; i < n; i++) {
  334. students[i].show();
  335. cout << "-----------------------\n";
  336. }
  337. system("pause>nul");
  338. return 0;
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement