From 8884255b045a6dc9e3a30e44a85022825f56e076 Mon Sep 17 00:00:00 2001 From: Mandisi Date: Fri, 15 Apr 2016 15:45:39 +0200 Subject: [PATCH 1/2] testPull MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an optional extended description… --- test.c | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test.c diff --git a/test.c b/test.c new file mode 100644 index 0000000..afd6af3 --- /dev/null +++ b/test.c @@ -0,0 +1,7 @@ +#include <stdio> + +int main(void) +{ + printf("testing git pull requests. \n"); + return (0); +} From b141cf7f678277877976ab7e2bcb63f4e1c15952 Mon Sep 17 00:00:00 2001 From: Mandisi Date: Sat, 16 Apr 2016 15:01:28 +0200 Subject: [PATCH 2/2] Mphiwes Files --- global.h | 24 +++++++++++++ output.c | 28 +++++++++++++++ putchar.c | 6 ++++ solver.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ themain.c.txt | 29 +++++++++++++++ 5 files changed, 184 insertions(+) create mode 100644 global.h create mode 100644 output.c create mode 100644 putchar.c create mode 100644 solver.c create mode 100644 themain.c.txt diff --git a/global.h b/global.h new file mode 100644 index 0000000..713c4cd --- /dev/null +++ b/global.h @@ -0,0 +1,24 @@ +#include +#include +#include + +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; + \ No newline at end of file diff --git a/output.c b/output.c new file mode 100644 index 0000000..e69e1e2 --- /dev/null +++ b/output.c @@ -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; + } + } + } +} \ No newline at end of file diff --git a/putchar.c b/putchar.c new file mode 100644 index 0000000..457b7a3 --- /dev/null +++ b/putchar.c @@ -0,0 +1,6 @@ +#include + +void putchar (char c) +{ + write (1, &c, 1); +} \ No newline at end of file diff --git a/solver.c b/solver.c new file mode 100644 index 0000000..2f9d840 --- /dev/null +++ b/solver.c @@ -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++; + } +} \ No newline at end of file diff --git a/themain.c.txt b/themain.c.txt new file mode 100644 index 0000000..709b1e2 --- /dev/null +++ b/themain.c.txt @@ -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); +} \ No newline at end of file