Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <string>
- using namespace std;
- void age(int user_age) {
- cout << "Ваш возраст в секундах: " << user_age * 365 * 24 * 60 * 60 << endl;
- }
- void equals(int num) {
- if (num % 10 == (num/10) % 10 || num % 10 == (num/100) % 10 || num % 10 == (num/1000) % 10
- || (num/10) % 10 == (num/100) % 10 || (num/10) % 10 == (num/1000) % 10
- || (num/100) % 10 == (num/1000) % 10) {
- cout << "Есть" << endl;
- }
- else {
- cout << "Нет" << endl;
- }
- }
- void change(int num) {
- int massive[4];
- int num_min = 1, num_max = 1, k;
- if (num > 10000 || num < 1000) {
- cout << "Неверный ввод\n";
- }
- for (int i = 3; i >= 0; i--) {
- massive[i] = num % 10;
- num = num / 10;
- }
- for (int i = 0; i < 4; i++) {
- if (massive[i] > massive[num_max]) {
- num_max = i;
- }
- if (massive[i] < massive[num_min]) {
- num_min = i;
- }
- }
- k = massive[num_min];
- massive[num_min] = massive[num_max];
- massive[num_max] = k;
- int new_num = 0;
- new_num = (massive[0] * 1000) + (massive[1] * 100) + (massive[2] * 10) + (massive[3]);
- cout << "Новое число: " << new_num << endl;
- }
- void days(int num) {
- cout << "Полных недель прошло: " << num / 7 << endl;
- }
- void authentication() {
- string real_password = "pavEL";
- string user_password;
- for (int i = 0; i < 3; i++) {
- cout << "Введите пароль: ";
- cin >> user_password;
- if (real_password == user_password) {
- cout << "Пароль введен вернo\n";
- break;
- }
- else {
- cout << "Пароль введен неверно\n";
- }
- if (i == 2) {
- cout << "Попыток больше нет\n";
- }
- }
- }
- void exist(int k) {
- int sum = 0;
- for (int i = 1;; i++) {
- sum += i;
- if (sum > k) {
- cout << "Не существует\n";
- break;
- }
- if (sum == k) {
- cout << "Существует: n = " << i << endl;
- break;
- }
- }
- }
- void randomize() {
- srand(3);
- int massive[10];
- for (int i = 0; i < 10; i++) {
- massive[i] = rand() % 101;
- }
- for (int i = 0; i < 9; i++) {
- for (int j = 0; j < 9 - i; j++) {
- if (massive[j] == massive[j + 1]) {
- massive[j] = rand() % 101;
- }
- }
- }
- for (int i = 0; i < 9; i++) {
- cout << massive[i] << " ";
- }
- cout << endl;
- }
- void division(int num) {
- for (int i = 10; i < 100; i++) {
- if ((i%num == 0) || ((i % 10 == num) || (i / 10) % 10 == num)) {
- cout << i << " ";
- }
- }
- cout << endl;
- }
- void zero_or_one() {
- int massive[10];
- massive[0] = 0;
- for (int i = 1; i < 10; i++) {
- if (massive[i - 1] == 0) {
- massive[i] = 1;
- }
- else {
- massive[i] = 0;
- }
- }
- for (int i = 0; i < 10; i++) {
- cout << massive[i] << " ";
- }
- cout << endl;
- }
- void sqr() {
- int squares[10];
- for (int i = 1; i<11; i++) {
- squares[i - 1] = i * i;
- }
- for (int i = 0; i<10; i++) {
- cout << squares[i] << " ";
- }
- cout << endl;
- }
- void randomize2(int n) {
- int* massive = new int[n];
- bool flag = false;
- for (int i = 0; i < n; i++) {
- cin >> massive[i];
- massive[i] = (int)massive[i];
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (massive[j] == i+1) {
- flag = true;
- break;
- cout << "true" << endl;
- }
- else {
- flag = false;
- }
- }
- if (flag == false) {
- cout << "Не содержит\n";
- break;
- }
- else {
- cout << "Содержит\n";
- break;
- }
- }
- cout << endl;
- }
- void equals2() {
- int massive[6];
- int k=0, max=0;
- for (int i = 0; i < 6; i++) {
- cin >> massive[i];
- }
- for (int i = 0; i < 5; i++) {
- for (int j = 0; j < 6; j++) {
- if (massive[i] == massive[j+1] && (i!=j+1)) {
- k += 1;
- }
- }
- if (max < k) {
- max = k+1;
- }
- k = 0;
- }
- cout << "Максимальное количество повторений: " << max << endl;
- }
- char chat_to_upper1(char elem) {
- int code = elem - 32;
- char result_elem = code;
- return result_elem;
- }
- int fact(int n) {
- if (n == 0) {
- return 1;
- }
- if (n == 1) {
- return 1;
- }
- if (n > 1) {
- return n * fact(n - 1);
- }
- }
- void more(int num1, int num2) {
- int k = 0, n = 0;
- while (num1 > 0 || num2 > 0) {
- num1 = num1 / 10;
- num2 = num2 / 10;
- if (num1 > 0) {
- k += 1;
- }
- if (num2 > 0) {
- n += 1;
- }
- }
- if (k < n) {
- cout << "Во второй";
- }
- if (k > n) {
- cout << "В первой";
- }
- if (k == n) {
- cout << "Одинаково";
- }
- }
- int transformation(char a) {
- int b = a - '0';
- if (b < 0 || b>9) {
- return NAN;
- }
- else {
- return b;
- }
- }
- struct Chem {
- string fio = "Каёшкина Ю.Н.";
- string date = "19.06.2018";
- int mark;
- };
- struct Phys {
- string fio = "Стерлядкин В.В.";
- string date = "27.06.2018";
- int mark;
- };
- struct Math {
- string fio = "Святова Е.Н.";
- string date = "07.06.2018";
- int mark;
- };
- struct RecordBook {
- Math math;
- Phys phys;
- Chem chem;
- };
- struct Student {
- string name;
- string surname;
- int day;
- int month;
- int year;
- RecordBook record_book;
- void filling();
- void show();
- int julian();
- };
- void Student::filling() {
- cout << "Введите имя студента: ";
- cin >> name;
- cout << "Введите фамилию студента: ";
- cin >> surname;
- cout << "Введите день рождения: ";
- cin >> day;
- cout << "Введите месяц рождения: ";
- cin >> month;
- cout << "Введите год рождения: ";
- cin >> year;
- }
- void Student::show() {
- cout << name << " " << surname << "|" << day << "." << month << "." << year << endl;
- }
- int Student::julian() {
- int a = (14 - month) / 12;
- int y = year + 4800 - a;
- int m = month + 12 * a - 3;
- int JDN = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;
- return JDN;
- }
- void swap(Student &x, Student &y) {
- Student temp = x;
- x = y;
- y = temp;
- }
- int main() {
- system("chcp 1251>nul");
- age(18);
- equals(1357);
- change(4231);
- days(256);
- //authentication();
- exist(7);
- randomize();
- division(5);
- zero_or_one();
- sqr();
- //randomize2(6);
- //equals2();
- //char a;
- //cin >> a;
- //cout<<chat_to_upper1(a);
- cout << fact(5) << endl;
- more(120, 5000);
- //char b;
- //cin >> b;
- //cout << transformation(b) << endl;
- cout << "\nВведите количество студентов: ";
- int n;
- cin >> n;
- Student* students = new Student[n];
- for (int i = 0; i < n; i++) {
- students[i].filling();
- }
- for (int i = 0; i < n - 1; i++) {
- for (int j = 0; j < n - 1 - i; j++) {
- if (students[j].julian() > students[j + 1].julian()) {
- swap(students[j], students[j + 1]);
- }
- }
- }
- for (int i = 0; i < n; i++) {
- students[i].show();
- cout << "-----------------------\n";
- }
- system("pause>nul");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement