Advertisement
Guest User

row_ratio

a guest
Aug 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. // DO NOT CHANGE HERE
  4. void wtf() {
  5.     FILE *f = fopen("datnum.txt", "w");
  6.     char c;
  7.     while((c = getchar()) != EOF) {
  8.         fputc(c, f);
  9.     }
  10.     fclose(f);
  11. }
  12.  
  13. int main() {
  14.     wtf();
  15.     // your code here
  16.     FILE *f = fopen("datnum.txt", "r");
  17.     char c;
  18.     char cc[100];
  19.     int countDigit = 0;
  20.     int countLetter = 0;
  21.     int max = 0;
  22.     int ratio = 0;
  23.     char result[100];
  24.    
  25.     while((c = fgetc(f)) != EOF)
  26.     {
  27.         while((c = fgetc(f)) != '\n')
  28.         {
  29.             if(isdigit(c))
  30.             {
  31.                 countDigit++;
  32.             }
  33.            
  34.             if(isalpha(c))
  35.             {
  36.                 countLetter++;
  37.             }
  38.            
  39.             ratio = countDigit / countLetter;
  40.            
  41.             if(ratio > max)
  42.             {
  43.                 max = ratio;
  44.                 fgets(cc, 100, f);
  45.                 //strcpy(result, cc);
  46.             }
  47.            
  48.         }
  49.        
  50.         countDigit = 0;
  51.         countLetter = 0;
  52.         ratio = 0;
  53.     }
  54.    
  55.     printf("%s", cc);
  56.    
  57.     fclose(f);
  58.    
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement