Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct
- {
- char nume[100];
- int viata, putere;
- } gladiator;
- void cit_glad(FILE *f, gladiator *a)
- {
- fscanf(f, "%s %d %d", a->nume, &a->viata, &a->putere);
- }
- int codific(char *a)
- {
- if(strcmp(a, "strike_high") == 0)
- return 1;
- if(strcmp(a, "strike_low") == 0)
- return 2;
- if(strcmp(a, "block_high") == 0)
- return 3;
- if(strcmp(a, "block_low") == 0)
- return 4;
- }
- void realizeaza_o_actiune(int x, int y, gladiator *a, gladiator *b)
- {
- if(x == 2)
- {
- if(y != 4)
- b->viata -= a->putere;
- if(y == 1 || y == 2)
- a->viata -= b->putere/2;
- }
- else
- {
- if(y != 3)
- b->viata -= a->putere;
- if(y == 1 || y == 2)
- a->viata -= b->putere/2;
- }
- }
- int cit_lovitura(FILE *f)
- {
- char actiune[100];
- fscanf(f, "%s", actiune);
- if(feof(f))
- return -1;
- return codific(actiune);
- }
- int main()
- {
- FILE *f = fopen("intrare.in", "r");
- if(f == NULL)
- return 1;
- gladiator a, b;
- cit_glad(f, &a);
- cit_glad(f, &b);
- gladiator *g1 = &a, *g2 = &b;
- while(1)
- {
- int x = cit_lovitura(f);
- if(x == -1)
- break;
- int y = cit_lovitura(f);
- if(y == -1)
- break;
- realizeaza_o_actiune(x, y, g1, g2);
- gladiator *t;
- t = g1;
- g1 = g2;
- g2 = t;
- }
- if(g1->viata > g2->viata)
- printf("a castigat %s v: ", g1->nume);
- else
- printf("a castigat %s", g2->nume);
- return 0;
- }
Add Comment
Please, Sign In to add comment