Skip to content

Commit

Permalink
Aula 11 Problema 5
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Pereira committed Dec 18, 2015
1 parent 32a6cb1 commit b1c1da9
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 46 deletions.
130 changes: 88 additions & 42 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions Aula_Pratica_11/Problema_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
void inverte(char *strOriginal, char *strInvertida);

int main() {
int i;
char f[M], inf[M];
fgets(f, M, stdin);
inverte(f, inf);
for (i = 0; i < strlen(f); ++i) {
printf("%c", inf[i]);
}
printf("%s", inf);
return 0;
}

Expand Down
49 changes: 49 additions & 0 deletions Aula_Pratica_11/Problema_5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>
#include <string.h>

#define M 100

int main() {
char in[M], pal[M];
int m[M];
int i, max = 0, j = 0, z = 0, mdiff = 0, pos, y, a = 0, p = 0;
printf("Frase? ");
fgets(in, M, stdin);
in[strlen(in) - 1] = '\0';
for (i = 0; in[i] != '\0'; i++) {
if (in[i] == ' ') {
m[j] = i;
j++;
p++;
}
}
for (z = 0; m[z] != 0; z++) {
if (mdiff < m[z + 1] - m[z]) {
mdiff = m[z + 1] - m[z];
pos = z + 1;
}
}
for (y = pos; in[y] != ' '; y++) {
pal[a] = in[y];
a++;
}

/*for(i=0; in[i]!='\0'; i++){
j++;
if(in[i] == ' '){
sum += j;
if(j-1>max){
max = j-1;
for(z=j; z!=0; z--){
m[z] = in[z]; //TODO: Forma muito muito pouco optimizada, não e apeteceu apagar
}
}
j=0;
p++;
}
}*/
printf("Numero de palavras: %d\n", i);
printf("Palavra maior = %s\n", pal);
printf("Comprimento medio: %d\n", i / p);

}

0 comments on commit b1c1da9

Please sign in to comment.