Created
June 5, 2018 05:07
-
-
Save vitorpiovezam/5912b2659e055e5fd1455393ac7ed1cf to your computer and use it in GitHub Desktop.
estudo c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define pilhaSize 10 | |
void criapilha (void) { | |
t = 0; | |
} | |
void empilha (char y) { | |
pilha[t++] = y; | |
} | |
char desempilha (void) { | |
return pilha[--t]; | |
} | |
int pilhavazia (void) { | |
return t <= 0; | |
} | |
int bemFormada (char s[]) | |
{ | |
criapilha (); | |
for (int i = 0; s[i] != '\0'; ++i) { | |
char c; | |
switch (s[i]) { | |
case ')': if (pilhavazia ()) return 0; | |
c = desempilha (); | |
if (c != '(') return 0; | |
break; | |
case ']': if (pilhavazia ()) return 0; | |
c = desempilha (); | |
if (c != '[') return 0; | |
break; | |
default: empilha (s[i]); | |
} | |
} | |
return pilhavazia (); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
DESENVOLVIDO POR PAULO LOURENÇO - RM78027 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> | |
float caractereUnicoParaFloat(char a) { | |
char temp[2]; | |
temp[0] = a; | |
temp[1] = '\0'; //indica fim | |
return atof(temp); | |
} | |
int main() { | |
char expressao[15]; | |
bool expressaoOk = true; | |
int topo = 0; | |
float pilha[15]; | |
//Valida expressão | |
//Repete a leitura da expressao ate estar correta | |
do { | |
puts("Informe a expressao (Ex. 32+7*): "); | |
gets(expressao); | |
int i; | |
for (i = 0; i < strlen(expressao); i++) { | |
if (!isdigit(expressao[i]) && expressao[i] != '+' && expressao[i] != '-' && expressao[i] != '*' && expressao[i] != '/') { | |
//Se encontrar um caractere nao permitido, para de buscar (sai do loop) | |
expressaoOk = false; | |
break; | |
} | |
} | |
if (expressaoOk) | |
break; //se a expressao estiver OK, sai do loop while e comeca a processar | |
printf("Expressao incorreta. Informe uma expressao correta com digitos e operadores.\n"); | |
printf("Operadores permitidos: + - * / \n"); | |
printf("Exemplo: 32+\n\n"); | |
} while (!expressaoOk); | |
printf("Show! Expressao ok, continuando... \n"); | |
int i; | |
for (i = 0; i <= strlen(expressao); i++) { | |
char caractere = expressao[i]; | |
printf("::: Processando caractere: %c \n", caractere); | |
if (i == strlen(expressao)) { | |
printf("Todos caracteres da expressao ja analisados\n"); | |
//desempilha res | |
topo--; | |
float finalRes = pilha[topo]; | |
printf("\n RESULTADO FINAL: %f \n", finalRes); | |
return; | |
} | |
float tempDado1 = 0; | |
float tempDado2 = 0; | |
float tempRes = 0; | |
int j; | |
if (isdigit(caractere)) { | |
float ei = caractereUnicoParaFloat(caractere); | |
pilha[topo] = ei; | |
topo++; | |
} else { | |
printf("nao e digito, ou seja, eh operador..\n"); | |
topo--; | |
tempDado1 = pilha[topo]; | |
topo--; | |
tempDado2 = pilha[topo]; | |
if (caractere == '+') { | |
printf("OPERACAO: SOMA \n"); | |
tempRes = tempDado1 + tempDado2; | |
} else if (caractere == '-') { | |
printf("OPERACAO: SUBTRACAO \n"); | |
tempRes = tempDado1 - tempDado2; | |
} else if (caractere == '*') { | |
printf("OPERACAO: MULTIPLICAÇÃO \n"); | |
tempRes = tempDado1 * tempDado2; | |
} else if (caractere == '/') { | |
printf("OPERACAO: DIVISÃO \n"); | |
tempRes = tempDado1 / tempDado2; | |
} | |
pilha[topo] = tempRes; | |
topo++; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// INTEGRANTES: | |
// | |
// Paulo Henrique Lima Lourenço - RM 78027 | |
// Vitor Gonçalves Piovezam - RM 78227 | |
// Caio Cesar - RM 79224 | |
// Thiago Cavalcante - RM 79449 | |
#include <stdio.h> | |
#include <string.h> | |
#define MAX_CLIENTES 500 | |
void Le_Vetores(char cnpj[MAX_CLIENTES][50], char atividade[MAX_CLIENTES][20], float consumo[MAX_CLIENTES], int* qtd) { | |
int menu = 0; | |
do { | |
fflush(stdin); | |
printf("Selecione a opcao: \n"); | |
printf("1. Adicionar novo cliente\n"); | |
printf("2. Sair\n"); | |
scanf("%d", &menu); | |
if (menu == 2) { | |
break; | |
} | |
printf("== INFORME OS DADOS DO CLIENTE ==\n"); | |
printf("-> CNPJ: "); | |
fflush(stdin); | |
scanf("%s", cnpj[*qtd]); | |
printf("-> Atividade: "); | |
fflush(stdin); | |
scanf("%s", atividade[*qtd]); | |
printf("-> Consumo (em Gigabytes): "); | |
fflush(stdin); | |
scanf("%f", &consumo[*qtd]); | |
printf("\n"); | |
(*qtd)++; | |
} while (menu == 1); | |
return; | |
} | |
void Consumo_Superior_500(char cnpj[MAX_CLIENTES][50], char atividade[MAX_CLIENTES][20], float consumo[MAX_CLIENTES], int qtd, char cnpj500[MAX_CLIENTES][50], int* cont) { | |
int i; | |
for (i = 0; i < qtd; i++) { | |
if (strcmp(atividade[i], "agronegocio") == 0 && consumo[i] > 500) { | |
strcpy(cnpj500[*cont], cnpj[i]); | |
(*cont)++; | |
} | |
} | |
} | |
void Maior_e_Menor_Consumo(float consumo[MAX_CLIENTES], int num, int* pos_maior, int* pos_menor) { | |
int i; | |
int maior = 0; | |
int menor = 99999999; | |
for (i = 0; i < num; i++) { | |
if (consumo[i] > maior) { | |
(*pos_maior) = i; | |
maior = consumo[i]; | |
} | |
if (consumo[i] < menor) { | |
(*pos_menor) = i; | |
menor = consumo[i]; | |
} | |
} | |
} | |
void Exibe_CNPJ(char cnpj500[MAX_CLIENTES][50], int cont) { | |
int i; | |
printf("\n --- CLIENTES DO AGRONEGOCIO COM CONSUMO SUPERIOR A 500 GIGABYTES --- \n"); | |
for (i = 0; i < cont; i++) { | |
printf("CNPJ: %s\n", cnpj500[i]); | |
} | |
} | |
int main() { | |
char cnpj[MAX_CLIENTES][50]; | |
char atividade[MAX_CLIENTES][20]; | |
float consumo[MAX_CLIENTES]; | |
int num = 0; | |
char cnpj_500[MAX_CLIENTES][50]; | |
int cont = 0; | |
int pos_maior; | |
int pos_menor; | |
Le_Vetores(cnpj, atividade, consumo, &num); | |
Consumo_Superior_500(cnpj, atividade, consumo, num, cnpj_500, &cont); | |
Maior_e_Menor_Consumo(consumo, num, &pos_maior, &pos_menor); | |
printf("\n"); | |
printf("==> MAIOR CONSUMO: %f \n", consumo[pos_maior]); | |
printf("==> MENOR CONSUMO: %f \n", consumo[pos_menor]); | |
printf("\n"); | |
Exibe_CNPJ(cnpj_500, cont); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment