Advertisement
EWTD

Untitled

Nov 2nd, 2019
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <math.h>
  5. char from_input(char input){
  6.     if(input >= '0' && input <= '9'){
  7.         return input - '0';
  8.     }else{
  9.         return input - 'a' + 10;
  10.     }
  11. }
  12. int main() {
  13.     FILE* fp = fopen("test.txt","r");
  14.     char ch;
  15.     int cnt = 0;
  16.     int square = 0;
  17.     int x = 0, y = 0;
  18.     int width = 0, height = 0;
  19.     char input[6250000];
  20.  
  21.     while ((ch = fgetc(fp)) != EOF) {
  22.         if (ch != ' ' && ch != '\n') {
  23.             input[cnt] = from_input(ch);
  24.             cnt++;
  25.         }
  26.     }
  27.     int size = sqrt((float)cnt)*2;
  28.     unsigned short* b = malloc(sizeof(unsigned short)*cnt);
  29.     unsigned short* c = malloc(sizeof(unsigned short)*cnt);
  30.     unsigned short* prev_b = malloc(sizeof(unsigned short)*cnt);
  31.     unsigned short* prev_c = malloc(sizeof(unsigned short)*cnt);
  32.     for(int i = 0 ; i < size; ++i){
  33.         prev_c[i] = 1 - ((input[i/4] >> (3 - (i%4))) & 1u);
  34.         printf("%d ",prev_c[i]);
  35.         prev_b[i] = prev_c[i];
  36.     }
  37.     printf("\n");
  38.     for(int i = 1; i < size; ++i){
  39.         b[0] = 1 - ((input[(size/4)*i] >> 3) & 1u);
  40.         c[0] = b[0];
  41.         for(int j = 1; j < size; ++j){
  42.             if((input[(size/4)*i + j/4] >> (3-(j%4)))&1u == 1){
  43.                 b[j] = 0;
  44.                 c[j] = 0;
  45.             }else{
  46.                 /*
  47.                 if(i == size-1 || j == size-1){
  48.                     b[j] = 0;
  49.                     c[j] = 0;
  50.                     continue;
  51.                 }
  52.                 */
  53.                 b[j] = __min( prev_b[j],b[j-1])+1;
  54.                 c[j] = __max(1 + prev_c[j], c[j-1]);
  55.             }
  56.             printf("%d ",b[j]);
  57.             if(square < (int)(b[j])*(int)(c[j])){
  58.                 x = i - c[j] + 1;
  59.                 y = j - b[j] + 1;
  60.                 width = c[j];
  61.                 height = b[j];
  62.             }
  63.         }
  64.         for(int j = 0;j < size; ++j){
  65.             prev_c[j] = c[j];
  66.             prev_b[j] = b[j];
  67.         }
  68.         printf("\n");
  69.     }
  70.     free(prev_b);
  71.     free(prev_c);
  72.     free(c);
  73.     free(b);
  74.     //printf("%d %d %d %d\n",x,y,width,height);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement