Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>

solver (char *str);
writer (buf);
putchar (char c);

char space;
char obstacle;
char filler;
int root;

int x;
int y;

int top;
int left;
int tolef;

int sq_sz;
int sq_posx;
int sq_posy;

28 changes: 28 additions & 0 deletions output.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "global.h"

void writer (char *str)
{
int cou;
int trig;

cou = 0;
trig = 0;
while (str[cou])
{
if (cou >= ((root * y) + (x + y)) && trig != 1)
{
putchar (filler);
if (((root * y) + (x + y) + sq_sz) < cou)
trig = 1;
}
else
{
putchar (str[cou]);
if (str[cou] == '\n' && trig == 1)
{
y++;
trig = 0;
}
}
}
}
6 changes: 6 additions & 0 deletions putchar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <unistd,h>

void putchar (char c)
{
write (1, &c, 1);
}
97 changes: 97 additions & 0 deletions solver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "global.h"

void translater (char *str)
{
int cou;
int convertor;
cou = 0;
root = 0;
convertor = 0;
while (covertor == 0)
{
if ((covertor = atoi(str[cou]) == 0)
convertor = 1;
break;
root *= 10;
root += atoi(str[cou]);
cou++;
}
space = str[cou];
obstacle = str[cou + 1];
filler = str[cou + 2];
}

void bsqf (int entry)
{
if (entry > sq_sz)
{
sq_sz = entry;
sq_posx = x;
sq_posy = y;
}
}


void saver (int entry)
{
int grid[1000][1000];
grid[y][x] = entry;
if (y == 0)
{
if (x == 0)
left = 0;
else
left = grid[y][x - 1];
}
else if (x == 0)
{
left = 0;
tolef = 0;
top = grid[y - 1][x];
}
else
{
left = grid[y][x - 1];
top = grid[y - 1][x];
tolef = grid[y - 1][x - 1];
}
bsqf (entry);
}


void calculator (char value)
{
if (value == obstacle)
saver (0);
else
{
if (top <= left && top <= tolef)
saver (top + 1);
else if (left <= top && left <= tolef)
saver (left + 1);
else
saver (tolef + 1);
}
}

void solver (char *str)
{
int cou;
y = 0;
x = 0;
top = 0;
left = 0;
tolef = 0;
cou = 0;
translater (str);
while(str[cou])
{
if (str[cou] == '\n')
y++;
x = 0;
else
calculator (str[cou]);
cou++;
x++;
}
}
7 changes: 7 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include &lt;stdio&gt;

int main(void)
{
printf("testing git pull requests. \n");
return (0);
}
29 changes: 29 additions & 0 deletions themain.c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "global.h"

main (int argc, char argv)
{
int fd;
int cou;
char *buf;

cou = 0;
if (argc != 2)
{
write (1, "argument error", 14);
return (0);
}
fd = open (argv[1], O_RDWR);
if (fd == -1)
{
write (1, "open error" , 11);
return (0);
}
while ((ret = read (fd, buf, malloc_size)))
{
buf[cou] = '\0';
cou++;
}
solver (buf);
writer (buf);
return (0);
}