Team Ai
Datasetpublic

prithivMLmods/Coder-Stat

Coder-Stat Dataset Overview The Coder-Stat dataset is a collection of programming-related data, including problem IDs, programming languages, original statuses, and source code snippets. This dataset is designed to assist in the analysis of coding patterns, error types, and performance metrics. Dataset Details Modalities Tabular: The dataset is structured in a tabular format. Text: Contains text data, including source code snippets.… See the full description on the dataset page: https://huggingface.co/datasets/prithivMLmods/Coder-Stat.

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
3likes139downloads
p00786.html176 linesDownload Raw Back to problem_descriptions
1 2<H1><font color="#000">Problem G:</font>BUT We Need a Diagram</H1>3 4<p>5Consider a data structure called BUT (Binary and/or Unary Tree). A BUT is defined inductively as follows:6</p>7 8<ul>9<li>Let <i>l</i> be a letter of the English alphabet, either lowercase or uppercase (n the sequel, we say simply "a letter"). Then, the object that consists only of <i>l</i>, designating <i>l</i> as its label, is a BUT. In this case, it is called a 0-ary BUT.</li>10<li>Let <i>l</i> be a letter and <i>C</i> a BUT. Then, the object that consists of <i>l</i> and <i>C</i>, designating <i>l</i> as its label and <i>C</i> as its component, is a BUT. In this case, it is called a unary BUT.</li>11<li>Let <i>l</i> be a letter, <i>L</i> and <i>R</i> BUTs. Then, the object that consists of <i>l</i>, <i>L</i> and <i>R</i>, designating <i>l</i> as its label, <i>L</i> as its left component, and <i>R</i> as its right component, is a BUT. In this case, it is called a binary BUT.</li>12</ul>13 14<p>15A BUT can be represented by a expression in the following way.16</p>17 18<ul>19<li>When a BUT <i>B</i> is 0-ary, its representation is the letter of its label.</li>20<li>When a BUT <i>B</i> is unary, its representation is the letter of its label followed by the parenthesized representation of its component.</li>21<li>When a BUT <i>B</i> is binary, its representation is the letter of its label, a left parenthesis, the representation of its left component, a comma, the representation of its right component, and a right parenthesis, arranged in this order.</li>22</ul>23 24 25<p>26Here are examples:27</p>28 29<pre>30a31A(b)32a(a,B)33a(B(c(D),E),f(g(H,i)))34</pre>35 36<p>37Such an expression is concise, <i>but</i> a diagram is much more appealing to our eyes. We prefer a diagram:38</p>39 40<pre>41D  H i42-  ---43c E g44--- -45 B  f46 ----47  a48</pre>49 50<p>51to the expression <pre>a(B(c(D),E),f(g(H,i)))</pre>52</p>53 54<pre>55Your mission is to write a program that converts the expression representing a BUT into its diagram. We want to keep a diagram as compact as possible assuming that we display it on a conventional character terminal with a fixed pitch font such as Courier. Let's define the diagram <i>D</i> for BUT <i>B</i> inductively along the structure of <i>B</i> as follows:56</pre>57 58<ul>59<li>When <i>B</i> is 0-ary, <i>D</i> consists only of a letter of its label. The letter is called the root of <i>D</i>, and also called the leaf of <i>D</i></li>60<li>When <i>B</i> is unary, <i>D</i> consists of a letter <i>l</i> of its label, a minus symbol <i>S</i>, and the diagram <i>C</i> for its component, satisfying the following constraints:61  <ul>62    <li><i>l</i> is just below <i>S</i></li>63    <li>The root of <i>C</i> is just above <i>S</i></li>64  </ul>65<i>l</i> is called the root of <i>D</i>, and the leaves of <i>C</i> are called the leaves of <i>D</i>.66</li>67<li>When <i>B</i> is binary, <i>D</i> consists of a letter <i>l</i> of its label, a sequence of minus symbols <i>S</i>, the diagram <i>L</i> for its left component, and the diagram <i>R</i> for its right component, satisfying the following constraints:68  <ul>69    <li><i>S</i> is contiguous, and is in a line.</li>70    <li><i>l</i> is just below the central minus symbol of <i>S</i>, where, if the center of <i>S</i> locates on a minus symbol <i>s</i>, <i>s</i> is the central, and if the center of <i>S</i> locates between adjacent minus symbols, the left one of them is the central.</li>71    <li>The root of <i>L</i> is just above the left most minus symbols of <i>S</i>, and the rot of <i>R</i> is just above the rightmost minus symbol of <i>S</i></li>72    <li>In any line of <i>D</i>, <i>L</i> and <i>R</i> do not touch or overlap each other.</li>73    <li>No minus symbols are just above the leaves of <i>L</i> and <i>R</i>.</li>74  </ul>75<i>l</i> is called the root of <i>D</i>, and the leaves of <i>L</i> and <i>R</i> are called the leaves of <i>D</i>76</li>77</ul>78 79<H2>Input</H2>80 81<p>82The input to the program is a sequence of expressions representing BUTs. Each expression except the last one is terminated by a semicolon. The last expression is terminated by a period. White spaces (tabs and blanks) should be ignored. An expression may extend over multiple lines. The number of letter, i.e., the number of characters except parentheses, commas, and white spaces, in an expression is at most 80.83</p>84 85<p>86You may assume that the input is syntactically correct and need not take care of error cases.87</p>88 89<H2>Output</H2>90 91<p>92Each expression is to be identified with a number starting with 1 in the order of occurrence in the input. Output should be produced in the order of the input.93</p>94 95<p>96For each expression, a line consisting of the identification number of the expression followed by a colon should be produced first, and then, the diagram for the BUT represented by the expression should be produced.97</p>98 99<p>100For diagram, output should consist of the minimum number of lines, which contain only letters or minus symbols together with minimum number of blanks required to obey the rules shown above.101</p>102 103<H2>Sample Input</H2>104<pre>105a(A,b(B,C));106x( y( y( z(z), v( s, t ) ) ), u ) ;107 108a( b( c,109      d(110         e(f),111         g112       )113    ),114   h( i(115         j(116            k(k,k),117            l(l)118          ),119         m(m)120       )121    )122 );123 124a(B(C),d(e(f(g(h(i(j,k),l),m),n),o),p))125.126</pre>127 128<H2>Output for the Sample Input</H2>129<pre>1301:131 B C132 ---133A b134---135 a1362:137z s t138- ---139z  v140----141 y142 -143 y u144 ---145  x1463:147   k k l148   --- -149 f  k  l m150 -  ---- -151 e g j   m152 --- -----153c d    i154---    -155 b     h156 -------157    a1584:159j k160---161 i l162 ---163  h m164  ---165   g n166   ---167    f o168    ---169   C e p170   - ---171   B  d172   ----173    a174</pre>175<!-- from UVA-->176