Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(){
- char c;
- int count_letter = 0;
- int count_total_letter = 0;
- int count_dots = 0;
- int count_words = 0;
- int word_size;
- int tamanho, pontuacao, i;
- int valid = 1;
- while(scanf("%c", &c) != EOF){
- //printf("--------- %c ----- \n", c);
- // Checa se os digitos estao entre os validos (a-z A-Z)
- if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'){
- count_letter++;
- // Se ja tiver tido um ponto
- if(count_dots>0){
- valid = 0;
- }
- }else if(c == '.'){
- count_dots++;
- }else if(c >= '0' && c <='9'){
- valid = 0;
- }
- // Checa se a palavra terminou
- if(c == ' ' || c == '\n'){
- // Checa se tem mais de um ponto
- if(count_dots>1 || count_letter == 0 || (count_letter == 0 && count_dots>0)){
- valid = 0;
- }
- //printf("Valido: %d\n", valid);
- if(valid){
- count_total_letter += count_letter;
- count_words++;
- }
- // Se for o fim da linha
- if(c == '\n'){
- //printf("COUNT TOTAL LETTER %d",count_total_letter );
- //printf("count_words %d", count_words);
- if(count_words == 0){
- tamanho = 0;
- }else{
- tamanho = (int)(count_total_letter/count_words);
- }
- if(tamanho <= 3){
- pontuacao = 250;
- }else if(tamanho == 4 || tamanho == 5){
- pontuacao = 500;
- }else if(tamanho >= 6){
- pontuacao = 1000;
- }
- printf("%d\n", pontuacao );
- // Resetamos pois teremos uma nova frase
- count_letter = count_total_letter = count_dots = count_words = 0;
- }
- // Resetamos
- valid = 1;
- count_letter = 0;
- count_dots = 0;
- //printf("CARACTER DA VEZ: %c LETRAS TOTAIS: %d PALAVRAS TOTAIS: %d \n",c,count_total_letter,count_words );
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement