Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <conio.h>
- #include <locale.h>
- #include <string.h>
- #include <string>
- struct stack {
- int data;
- stack* next;
- };
- stack *head, *now;
- void callMenu() {
- printf("push(x)\n");
- printf("pop\n");
- printf("do\n");
- }
- void push(int a) {
- now = new(stack);
- now->next = head;
- now->data = a;
- head = now;
- }
- void pop() {
- if (head == NULL) {
- printf("Stack is empty\n");
- return;
- }
- printf("%d\n", head->data);
- now = head->next;
- delete(head);
- head = now;
- }
- void toDo() {
- int a = 0, kol = 0;
- float diff = 0;
- now = head;
- while (now != NULL) {
- kol++;
- a += now->data;
- now = now->next;
- }
- diff = float(a) / kol;
- kol = 0;
- now = head;
- while (now != NULL) {
- if (now->data > diff)
- kol++;
- now = now->next;
- }
- printf("Result = %d\n", kol);
- }
- void view() {
- now = head;
- if (now == NULL) {
- printf("Stack is empty\n");
- return;
- }
- while (now != NULL) {
- printf("%d ", now->data);
- now = now->next;
- }
- printf("\n");
- }
- int main()
- {
- char input[255];
- std::string temp;
- int toAdd = 0;
- char zero = ' ';
- setlocale(LC_ALL, "Russian");
- callMenu();
- while (1) {
- scanf("%s", input);
- if (input[0] == 'p' && input[1] == 'u' && input[2] == 's' && input[3] == 'h') {
- temp = "";
- for (int i = 5; i < strlen(input), input[i] != ')'; i++)
- temp += input[i];
- toAdd = stoi(temp);
- push(toAdd);
- }
- if (input[0] == 'p' && input[1] == 'o' && input[2] == 'p') {
- pop();
- }
- if (input[0] == 'd' && input[1] == 'o') {
- toDo();
- }
- if (input[0] == 'v' && input[1] == 'i' && input[2] == 'e' && input[3] == 'w')
- view();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement