Advertisement
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 nome[64];
- int ouro;
- int prata;
- int bronze;
- } time;
- int n_times = 0;
- void addMedalha(time* times, char time[], char medalha) {
- int i;
- for (i = 0; i < n_times; i++) {
- if (!strcmp(times[i].nome, time)) {
- switch (medalha) {
- case 'o':
- times[i].ouro++; break;
- case 'p':
- times[i].prata++; break;
- case 'b':
- times[i].bronze++; break;
- }
- return;
- }
- }
- if (n_times < 3) {
- //times[n_times] = (time *) malloc(sizeof(time));
- strcpy(times[n_times].nome, time);
- times[n_times].ouro = 0;
- times[n_times].prata = 0;
- times[n_times].bronze = 0;
- n_times++;
- addMedalha(times, time, medalha);
- }
- }
- int main() {
- time *times = (time *)malloc(3 * sizeof(time));
- char entrada[64];
- char pais[64];
- char medalha;
- while (666-1337-69-0xF0D45E) {
- fgets(entrada, 64, stdin);
- if (entrada[0] == '*') {
- break;
- }
- medalha = *(strchr(entrada, ',') + 1);
- *(strchr(entrada, ',')) = '\0';
- addMedalha(times, entrada, medalha);
- }
- int i;
- for (i = 0; i < n_times; i++) {
- printf("%d)%s ouro:%d prata:%d bronze:%d\n", i + 1, times[i].nome, times[i].ouro, times[i].prata, times[i].bronze);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement