Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main(){
  7.  
  8.     char c;
  9.     int count_letter = 0;
  10.     int count_total_letter = 0;
  11.     int count_dots = 0;
  12.     int count_words = 0;
  13.     int word_size;
  14.     int tamanho, pontuacao, i;
  15.     int valid = 1;
  16.  
  17.     while(scanf("%c", &c) != EOF){
  18.         //printf("--------- %c ----- \n", c);
  19.         // Checa se os digitos estao entre os validos   (a-z A-Z)      
  20.         if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'){
  21.             count_letter++;
  22.             // Se ja tiver tido um ponto
  23.             if(count_dots>0){
  24.                 valid = 0;
  25.             }
  26.         }else if(c == '.'){
  27.             count_dots++;          
  28.         }else if(c >= '0' && c <='9'){
  29.             valid = 0;         
  30.         }
  31.  
  32.         // Checa se a palavra terminou
  33.         if(c == ' ' || c == '\n'){
  34.             // Checa se tem mais de um ponto
  35.             if(count_dots>1 || count_letter == 0 || (count_letter == 0 && count_dots>0)){
  36.                 valid = 0;
  37.             }          
  38.  
  39.             //printf("Valido: %d\n", valid);
  40.             if(valid){
  41.                 count_total_letter += count_letter;
  42.                 count_words++;
  43.             }
  44.  
  45.             // Se for o fim da linha
  46.             if(c == '\n'){
  47.                 //printf("COUNT TOTAL LETTER %d",count_total_letter );
  48.                 //printf("count_words %d", count_words);
  49.                 if(count_words == 0){
  50.                     tamanho = 0;
  51.                 }else{
  52.                     tamanho = (int)(count_total_letter/count_words);
  53.                 }
  54.                 if(tamanho <= 3){
  55.                     pontuacao = 250;
  56.                 }else if(tamanho == 4 || tamanho == 5){
  57.                     pontuacao = 500;
  58.                 }else if(tamanho >= 6){
  59.                     pontuacao = 1000;
  60.                 }
  61.  
  62.  
  63.                 printf("%d\n", pontuacao );
  64.  
  65.                 // Resetamos pois teremos uma nova frase
  66.                 count_letter = count_total_letter = count_dots = count_words = 0;
  67.             }
  68.  
  69.             // Resetamos
  70.             valid = 1;
  71.             count_letter = 0;
  72.             count_dots = 0;
  73.  
  74.             //printf("CARACTER DA VEZ: %c   LETRAS TOTAIS: %d     PALAVRAS TOTAIS:  %d \n",c,count_total_letter,count_words );
  75.  
  76.         }
  77.  
  78.  
  79.     }
  80.     return 1;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement