"use strict";(self.webpackChunkfi=self.webpackChunkfi||[]).push([[9193],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>k});var i=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=i.createContext({}),u=function(e){var t=i.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=u(e.components);return i.createElement(s.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},d=i.forwardRef((function(e,t){var n=e.components,a=e.mdxType,r=e.originalType,s=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),c=u(n),d=a,k=c["".concat(s,".").concat(d)]||c[d]||m[d]||r;return n?i.createElement(k,o(o({ref:t},p),{},{components:n})):i.createElement(k,o({ref:t},p))}));function k(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var r=n.length,o=new Array(r);o[0]=d;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[c]="string"==typeof e?e:a,o[1]=l;for(var u=2;u{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>m,frontMatter:()=>r,metadata:()=>l,toc:()=>u});var i=n(7462),a=(n(7294),n(3905));const r={id:"seminar-08",title:"8th seminar",description:"Manipulating with files only char-by-char and a magic tree.\n"},o="8th seminar bonus assignment",l={unversionedId:"bonuses/seminar-08",id:"bonuses/seminar-08",title:"8th seminar",description:"Manipulating with files only char-by-char and a magic tree.\n",source:"@site/pb071/bonuses/08.md",sourceDirName:"bonuses",slug:"/bonuses/seminar-08",permalink:"/pb071/bonuses/seminar-08",draft:!1,editUrl:"https://github.com/mfocko/blog/tree/main/pb071/bonuses/08.md",tags:[],version:"current",lastUpdatedAt:1694960869,formattedLastUpdatedAt:"Sep 17, 2023",frontMatter:{id:"seminar-08",title:"8th seminar",description:"Manipulating with files only char-by-char and a magic tree.\n"},sidebar:"autogeneratedBar",previous:{title:"5th and 6th seminar",permalink:"/pb071/bonuses/seminar-05-06"},next:{title:"10th seminar",permalink:"/pb071/bonuses/seminar-10"}},s={},u=[{value:"Introduction",id:"introduction",level:2},{value:"Warning",id:"warning",level:2},{value:"Testing",id:"testing",level:2},{value:"Task no. 1: Counting (0.75 K\u20a1)",id:"task-no-1-counting-075-k",level:2},{value:"Requirements",id:"requirements",level:3},{value:"Bonus part (0.75 K\u20a1)",id:"bonus-part-075-k",level:3},{value:"Task no. 2: Weird trees (1 K\u20a1)",id:"task-no-2-weird-trees-1-k",level:2},{value:"Submitting",id:"submitting",level:2}],p={toc:u},c="wrapper";function m(e){let{components:t,...r}=e;return(0,a.kt)(c,(0,i.Z)({},p,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"8th-seminar-bonus-assignment"},"8th seminar bonus assignment"),(0,a.kt)("p",null,(0,a.kt)("a",{parentName:"p",href:"pathname:///files/pb071/bonuses/08.tar.gz"},"Source")),(0,a.kt)("h2",{id:"introduction"},"Introduction"),(0,a.kt)("p",null,"In this bonus you can implement two tasks, one of them has a bonus part with generic\nsolution."),(0,a.kt)("p",null,"One is focused on counting ananas or in case of generic version any substring in\nthe file, but with a restriction on the function you use."),(0,a.kt)("p",null,"Other one has a more algorithmic spirit."),(0,a.kt)("p",null,"For this bonus you can get at maximum 2.5 K\u20a1."),(0,a.kt)("h2",{id:"warning"},"Warning"),(0,a.kt)("p",null,(0,a.kt)("strong",{parentName:"p"},"DO NOT COMMIT test data")," to your own git repository, since the tests include\nfiles that exceed 10MB by themselves. Even if they are on separate branch, they\ntake up the space."),(0,a.kt)("h2",{id:"testing"},"Testing"),(0,a.kt)("p",null,"For testing you are provided with python script (requires ",(0,a.kt)("inlineCode",{parentName:"p"},"click")," to be installed:\n",(0,a.kt)("inlineCode",{parentName:"p"},"pip3 install --user click"),") and ",(0,a.kt)("inlineCode",{parentName:"p"},"Makefile")," that provides following targets:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"check-counting")," - runs the ",(0,a.kt)("inlineCode",{parentName:"li"},"counting")," tests"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"check-counting-bonus")," - runs the ",(0,a.kt)("inlineCode",{parentName:"li"},"counting")," tests with bonus implemented"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"check")," - runs both ",(0,a.kt)("inlineCode",{parentName:"li"},"counting")," and ",(0,a.kt)("inlineCode",{parentName:"li"},"counting-bonus")," tests"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"clean")," - removes output files from the test runs")),(0,a.kt)("h2",{id:"task-no-1-counting-075-k"},"Task no. 1: Counting (0.75 K\u20a1)"),(0,a.kt)("p",null,"Your first task is to make smallish program that counts occurences of specific\n(or given) word from file and writes the number to other file."),(0,a.kt)("p",null,"Usage of the program is:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"Usage: ./counting [string-to-be-counted]\n")),(0,a.kt)("p",null,"Arguments that are passed to the program represent:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"")," - path to the file where we count the words"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"")," - path to the file where we output the count"),(0,a.kt)("li",{parentName:"ul"},"(optional argument) ",(0,a.kt)("inlineCode",{parentName:"li"},"[string-to-be-counted]")," - in case you implement bonus,\notherwise we default to word ",(0,a.kt)("inlineCode",{parentName:"li"},"ananas")," ;)")),(0,a.kt)("p",null,"In skeleton you are given 3 empty, but documented, functions to implement."),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("inlineCode",{parentName:"li"},"count_anything")," - function accepts input file and substring to be counted in\nthe file, returns the count."),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("inlineCode",{parentName:"li"},"count_ananas")," - same as ",(0,a.kt)("inlineCode",{parentName:"li"},"count_anything"),", but specialized for ananases, the\ndefault implementation from the skeleton expects you to implement ",(0,a.kt)("inlineCode",{parentName:"li"},"count_anything"),"\nand therefore it just calls the other function."),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("inlineCode",{parentName:"li"},"write_number")," - function that writes the number to the file, why would you\nneed the function is explained later :)")),(0,a.kt)("h3",{id:"requirements"},"Requirements"),(0,a.kt)("p",null,"For manipulation with the files you are only allowed to use ",(0,a.kt)("inlineCode",{parentName:"p"},"fopen"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"fclose"),",\n",(0,a.kt)("inlineCode",{parentName:"p"},"fgetc")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"fputc"),". Functions like ",(0,a.kt)("inlineCode",{parentName:"p"},"fprintf")," (except for ",(0,a.kt)("inlineCode",{parentName:"p"},"stderr")," or logging) and\n",(0,a.kt)("inlineCode",{parentName:"p"},"fscanf")," are ",(0,a.kt)("strong",{parentName:"p"},"forbidden"),"."),(0,a.kt)("p",null,"In case you struggle and want to use one of those functions, the solution will be\npenalized by 50% of points."),(0,a.kt)("h3",{id:"bonus-part-075-k"},"Bonus part (0.75 K\u20a1)"),(0,a.kt)("p",null,"Bonus part of this assignment is to implement ",(0,a.kt)("inlineCode",{parentName:"p"},"count_anything")," rather than ",(0,a.kt)("inlineCode",{parentName:"p"},"count_ananas"),"."),(0,a.kt)("blockquote",null,(0,a.kt)("p",{parentName:"blockquote"},"Smaller hint: This task does not need dynamic allocation :) You just need one\ngood helper function and the right idea ;)")),(0,a.kt)("h2",{id:"task-no-2-weird-trees-1-k"},"Task no. 2: Weird trees (1 K\u20a1)"),(0,a.kt)("p",null,"In this task we are crossing our paths with ",(0,a.kt)("em",{parentName:"p"},"algorithms and data structures"),".\nYour task is to write a program that constructs tree from the file that is given\nas an argument and pretty-prints it."),(0,a.kt)("p",null,"Input file consists of lines, that include ",(0,a.kt)("inlineCode",{parentName:"p"},"key")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"rank")," in form ",(0,a.kt)("inlineCode",{parentName:"p"},"key;rank"),"\nor ",(0,a.kt)("inlineCode",{parentName:"p"},"nil"),". Why would we have ",(0,a.kt)("inlineCode",{parentName:"p"},"nil")," in a file? The file represents pre-order iteration\nthrough the tree. Leaves never have rank different than 0, so you can safely assume\n2 non-existing ",(0,a.kt)("inlineCode",{parentName:"p"},"nil"),"s in the input after you read such node ;)"),(0,a.kt)("table",null,(0,a.kt)("tr",null,(0,a.kt)("th",null,"Example input file"),(0,a.kt)("th",null,"Tree it represents")),(0,a.kt)("tr",null,(0,a.kt)("td",null,(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"8;4\n5;3\n3;2\n2;1\n1;0\nnil\n4;0\n7;1\n6;0\nnil\n11;2\n10;1\n9;0\nnil\n12;0\n"))),(0,a.kt)("td",null,(0,a.kt)("p",null,(0,a.kt)("img",{alt:"tree",src:n(4860).Z,width:"633",height:"684"}))))),(0,a.kt)("p",null,"In this task you are only provided with different trees in the ",(0,a.kt)("inlineCode",{parentName:"p"},"test-trees")," directory.\nImplementation and format of the pretty-print is totally up to you. :)"),(0,a.kt)("p",null,"Example of mine for the tree above:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"8 (rank = 4)\n+-- 5 (rank = 3)\n| +-- 3 (rank = 2)\n| | +-- 2 (rank = 1)\n| | | +-- 1 (rank = 0)\n| | +-- 4 (rank = 0)\n| +-- 7 (rank = 1)\n| +-- 6 (rank = 0)\n+-- 11 (rank = 2)\n +-- 10 (rank = 1)\n | +-- 9 (rank = 0)\n +-- 12 (rank = 0)\n")),(0,a.kt)("blockquote",null,(0,a.kt)("p",{parentName:"blockquote"},"Can you find out what are those trees? :)")),(0,a.kt)("h2",{id:"submitting"},"Submitting"),(0,a.kt)("p",null,"In case you have any questions, feel free to reach out to me."),(0,a.kt)("hr",null))}m.isMDXComponent=!0},4860:(e,t,n)=>{n.d(t,{Z:()=>i});const i=n.p+"assets/images/tree-c9e37f87f9095c00fad33ea034485ce6.png"}}]);