added xor

This commit is contained in:
ada-dmitry
2023-04-17 21:29:57 +03:00
parent b8727b3820
commit ea4d0db0f1
13 changed files with 294 additions and 0 deletions
Binary file not shown.
+17
View File
@@ -0,0 +1,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
typedef struct node {
int x;
struct node* next;
}Plate;
void print_plates(Plate* plates);
Plate* push(Plate* plates, int x);
Plate* remove_plate(Plate* plates);
int pop(Plate** plates);
int len(Plate* plates);
int isnm(char *str);
+74
View File
@@ -0,0 +1,74 @@
#include "head.h"
void print_plates(Plate *plates)
{
if (plates == NULL)
{
printf("[%p]\n", plates);
return;
}
while(plates){
printf("[%14p]->[%14p] ", plates, plates->next);
printf("data: [%4d]\n", plates->x);
plates = plates->next;
}
printf("-------------\n");
}
Plate* push(Plate* plates, int d){
Plate *temp = NULL;
if((temp=malloc(sizeof(Plate)))==NULL){
perror("malloc:NULL");
exit(2);
}
temp->x = d;
if(plates==NULL) temp->next=NULL;
else{
temp->next=plates;
}
return temp;
}
Plate* del_head(Plate* plates){
Plate *temp=plates;
if(plates==NULL) return NULL;
if(plates->next==NULL){
free(plates);
return NULL;
}
plates = plates->next;
free(temp);
return plates;
}
int len(Plate* plates){
int ans = 0;
Plate *temp = plates;
if(plates==NULL) return 0;
while(temp){
ans++;
temp=temp->next;
}
return ans;
}
int pop(Plate** plates){
int i;
if(*plates==NULL){
printf("Error");
exit(4);
}
i = (*plates)->x;
*plates = del_head(*plates);
return i;
}
int isnm(char *str){
int i = 0, n = strlen(str);
for(i=0; i<n; i++){
if(!isdigit(str[i])){
return 0;
}
}
return 1;
}
+51
View File
@@ -0,0 +1,51 @@
#include "head.h"
int main(int argc, char *argv[]){
Plate *plates = NULL;
char c;
int i,j,k, ans = 0;
for (k=1; k < argc; k++){
if (isnm(argv[k])){
plates = push(plates, atoi(argv[k]));
}
else if (strlen(argv[k]) == 1 || !strcmp(argv[k], "*m")){
if (len(plates)<2){
printf("Not enough numbers");
exit(2);
}
if (!strcmp(argv[k], "*m")) c = '*';
else c = *argv[k];
i = pop(&plates);
j = pop(&plates);
switch(c){
case '+':
plates = push(plates, j + i);
break;
case '-':
plates = push(plates, j - i);
break;
case '*':
plates = push(plates, j * i);
break;
case '/':
plates = push(plates, j / i);
break;
default:
printf("You wrote something wrong");
exit(3);
}
}
else{
printf("You wrote something wrong");
exit(7);
}
}
if (len(plates)!=1){
printf("Not enough operations");
exit(4);
}
ans = pop(&plates);
printf("Result of line is %d\n", ans);
return 0;
}
Binary file not shown.