forked from daveagp/websheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sql
372 lines (357 loc) · 621 KB
/
install.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
-- phpMyAdmin SQL Dump
-- version 3.4.3.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 02, 2015 at 06:07 PM
-- Server version: 5.0.95
-- PHP Version: 5.3.3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `cscircles`
--
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `ws_history` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`problem` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`submission` varchar(5000) COLLATE utf8_unicode_ci NOT NULL,
`result` mediumtext COLLATE utf8_unicode_ci NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`passed` tinyint(1) NOT NULL DEFAULT '0',
`meta` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `user` (`user`,`problem`,`passed`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
-- Table structure for table `ws_settings`
--
CREATE TABLE IF NOT EXISTS `ws_settings` (
`user` varchar(40) COLLATE utf8_unicode_ci default NULL,
`keyname` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`value` text COLLATE utf8_unicode_ci NOT NULL,
`id` int(11) NOT NULL auto_increment,
PRIMARY KEY (`id`),
KEY `user` (`user`,`keyname`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Table structure for table `ws_sheets`
--
CREATE TABLE IF NOT EXISTS `ws_sheets` (
`id` int(11) NOT NULL auto_increment,
`author` varchar(100) collate utf8_unicode_ci NOT NULL,
`problem` varchar(100) collate utf8_unicode_ci NOT NULL,
`definition` mediumtext collate utf8_unicode_ci,
`time` timestamp NOT NULL default CURRENT_TIMESTAMP,
`action` varchar(20) collate utf8_unicode_ci NOT NULL,
`sharing` varchar(20) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`),
KEY `problem` (`problem`,`action`,`time`),
KEY `author` (`author`,`problem`,`action`,`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=329 ;
--
-- Dumping data for table `ws_sheets`
--
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(1, '[email protected]', 'DigitSum', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program that takes an integer command-line argument,\\nand outputs the sum of its digits, by using <tt>while</tt> loop.", "source_code": "\\npublic static void main(String[] args) {\\n int n = Integer.parseInt(args[0]);\\n int total = 0; // running sum\\n \\n while (\\\\[n > 0]\\\\) {\\n\\\\[\\n total = total + n%10;\\n n = n/10;\\n]\\\\\\n }\\n\\n System.out.println(total);\\n}\\n", "tests": "\\ntestMain(\\"123\\");\\ntestMain(\\"2014\\");\\ntestMain(\\"7\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(2, '[email protected]', 'java/15-practicefinal/BinaryInteger', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Spring 2010 Programming Midterm 2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/fall13/cos126/docs/mid2b-s10.pdf\\">\\nthis PDF link</a>. \\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own, then copying here for full testing\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\npublic class BinaryInteger {\\n\\\\[\\n private final int N; // number of bits\\n private final String s; // bit string\\n\\n // create a binary integer from a string of 0s and 1s\\n public BinaryInteger(String s) {\\n if (!s.matches(\\"[01]*\\")) {\\n throw new RuntimeException(\\"Illegal argument to BinaryInteger()\\");\\n }\\n this.s = s;\\n this.N = s.length();\\n }\\n\\n // length of this binary integer\\n public int length() {\\n return N;\\n }\\n\\n // number of leading zeros in this binary integer\\n public int leadingZeros() {\\n int count = 0;\\n for (int i = N-1; i >= 0; i--) {\\n if (!ith(i)) count++;\\n else break;\\n }\\n return count;\\n }\\n\\n // is this binary integer strictly greater than that binary integer?\\n public boolean isGreaterThan(BinaryInteger that) {\\n int n1 = this.length() - this.leadingZeros();\\n int n2 = that.length() - that.leadingZeros();\\n if (n1 > n2) return true;\\n if (n1 < n2) return false;\\n for (int i = n1 - 1; i >= 0; i--) {\\n if (this.ith(i) && !that.ith(i)) return true;\\n if (that.ith(i) && !this.ith(i)) return false;\\n }\\n return false; // equal\\n }\\n\\n // return the ith least significant bit as a boolean\\n private boolean ith(int i) {\\n if (s.charAt(N - i - 1) == ''0'') return false;\\n else if (s.charAt(N - i - 1) == ''1'') return true;\\n else throw new RuntimeException(\\"Inconsisent state\\");\\n }\\n\\n // return the bitwise xor of this binary integer and that binary integer\\n public BinaryInteger xor(BinaryInteger that) {\\n if (this.N != that.N) throw new RuntimeException(\\"Size mismatch\\");\\n String answer = \\"\\";\\n for (int i = 0; i < N; i++) {\\n if (this.ith(i) ^ that.ith(i)) answer = \\"1\\" + answer;\\n else answer = \\"0\\" + answer;\\n }\\n return new BinaryInteger(answer);\\n }\\n\\n // return the bitwise not of this binary integer\\n public BinaryInteger not() {\\n String answer = \\"\\";\\n for (int i = 0; i < N; i++) {\\n if (this.ith(i)) answer = \\"0\\" + answer;\\n else answer = \\"1\\" + answer;\\n }\\n return new BinaryInteger(answer);\\n }\\n\\n // return string representation of this binary integer\\n public String toString() {\\n return s;\\n }\\n]\\\\\\n}\\n", "tests": "\\nsaveAs = \\"a\\";\\ntestConstructor(\\"00011110\\");\\nsaveAs = \\"b\\";\\ntestConstructor(\\"01010000\\");\\ntestOn(\\"a\\", \\"toString\\");\\ntestOn(\\"b\\", \\"toString\\");\\ntestOn(\\"a\\", \\"length\\");\\ntestOn(\\"b\\", \\"length\\");\\nsaveAs = \\"notA\\";\\ntestOn(\\"a\\", \\"not\\");\\ntestOn(\\"notA\\", \\"toString\\");\\nsaveAs = \\"x\\";\\ntestOn(\\"a\\", \\"xor\\", var(\\"b\\"));\\ntestOn(\\"x\\", \\"toString\\");\\ntestOn(\\"a\\", \\"leadingZeros\\");\\ntestOn(\\"a\\", \\"isGreaterThan\\", var(\\"b\\"));\\n\\nsaveAs = \\"sextillion\\";\\ntestConstructor(\\"1101100011010111001001101011011100010111011110101000000000000000000000\\");\\ntestOn(\\"sextillion\\", \\"toString\\");\\ntestOn(\\"sextillion\\", \\"length\\");\\ntestOn(\\"sextillion\\", \\"leadingZeros\\");\\nsaveAs = \\"lengthyZero\\";\\ntestOn(\\"sextillion\\", \\"xor\\", var(\\"sextillion\\"));\\ntestOn(\\"lengthyZero\\", \\"toString\\");\\ntestOn(\\"lengthyZero\\", \\"leadingZeros\\");\\n\\nsaveAs = \\"one\\";\\ntestConstructor(\\"00000001\\");\\ntestOn(\\"one\\", \\"leadingZeros\\");\\nexpectException = true;\\ntestOn(\\"one\\", \\"xor\\", var(\\"sextillion\\"));\\n\\nsaveAs = \\"zero\\";\\ntestConstructor(\\"00000000\\");\\ntestOn(\\"zero\\", \\"leadingZeros\\");\\ntestOn(\\"one\\", \\"isGreaterThan\\", var(\\"zero\\"));\\ntestOn(\\"zero\\", \\"isGreaterThan\\", var(\\"zero\\"));\\ntestOn(\\"zero\\", \\"isGreaterThan\\", var(\\"one\\"));\\ntestOn(\\"one\\", \\"isGreaterThan\\", var(\\"one\\"));\\n\\nsaveAs = \\"ten\\";\\ntestConstructor(\\"00001010\\");\\ntestOn(\\"one\\", \\"isGreaterThan\\", var(\\"ten\\"));\\ntestOn(\\"ten\\", \\"isGreaterThan\\", var(\\"one\\"));\\n\\nexpectException = true; testConstructor(\\"1111A\\");\\nexpectException = true; testConstructor(\\"21111\\");\\nexpectException = true; testConstructor(\\" 11111\\");\\nexpectException = true; testConstructor(\\"0000 \\");\\n\\nsaveAs = \\"emptyStringIsLegal\\";\\ntestConstructor(\\"\\");\\ntestOn(\\"emptyStringIsLegal\\", \\"toString\\");\\ntestOn(\\"emptyStringIsLegal\\", \\"leadingZeros\\");\\n\\nsaveAs = \\"three\\";\\ntestConstructor(\\"011\\");\\nsaveAs = \\"paddedFour\\";\\ntestConstructor(\\"00000100\\");\\ntestOn(\\"three\\", \\"isGreaterThan\\", var(\\"paddedFour\\"));\\ntestOn(\\"paddedFour\\", \\"isGreaterThan\\", var(\\"three\\"));\\ntestOn(\\"lengthyZero\\", \\"isGreaterThan\\", var(\\"zero\\"));\\ntestOn(\\"zero\\", \\"isGreaterThan\\", var(\\"lengthyZero\\"));\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(3, '[email protected]', 'java/15-practicefinal/MiniPro2', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Fall 2013 Programming Midterm 2, part 2/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/mid2-f13-prog.pdf\\">\\nthis PDF link</a>. \\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own before using automatic tests\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\n\\\\[\\n/**************************************************************************\\n * MiniPro2: Interpreter for version 2 of a miniature programming language.\\n * \\n * COS 126, Princeton University, Fall 2013, Programming Midterm 2 Part 1\\n * \\n * Notes: functionally different from MiniPro in step() and isDone();\\n * has private helper method evaluate(), not part of API.\\n * \\n * Dependencies: ST, StdOut\\n * \\n * Compilation: javac-introcs MiniPro.java\\n **************************************************************************/\\n private int pc; // the program counter\\n private String[][] program; // the program itself\\n private ST<String, Integer> varTable; // values of all defined variables\\n \\n // Create interpreter for this program. Don''t execute it yet!\\n public MiniPro2(String[][] program) {\\n this.program = program;\\n pc = 0; // line 0 is always the first to execute\\n varTable = new ST<String, Integer>();\\n }\\n\\n // Return the current value of the variable named v. If no\\n // such variable is currently defined, throw a RuntimeException.\\n public int valueOf(String v) {\\n if (!varTable.contains(v))\\n throw new RuntimeException(\\"Variable named \\" + v + \\" not defined\\");\\n return varTable.get(v);\\n }\\n\\n // Return the number of the line that will execute next.\\n public int programCounter() {\\n return pc;\\n }\\n \\n // Check if this token is an integer or variable, and give the value\\n // of it in either case.\\n private int evaluate(String token) {\\n // look at token, evaluate it\\n if (token.matches(\\"[a-z]+\\")) // it''s a variable name\\n return varTable.get(token);\\n else // it''s an integer\\n return Integer.parseInt(token);\\n }\\n\\n // Execute the line whose number equals the value of the\\n // program counter. Then, increment the program counter.\\n public void step() {\\n String[] line = program[pc]; // current line (1d piece of 2d array)\\n String command = line[1]; \\n\\n // assignment statement\\n if (command.equals(\\"=\\")) {\\n // look at token on right-hand side, evaluate it\\n String rhsToken = line[2];\\n int rhsValue = evaluate(rhsToken);\\n \\n // save value in variable\\n varTable.put(line[0], rhsValue);\\n }\\n\\n // println statement\\n else if (command.equals(\\"println\\")) {\\n // get value of desired variable, then print it\\n int value = varTable.get(line[0]);\\n StdOut.println(value);\\n }\\n\\n // mathematical operations\\n else if (command.equals(\\"+=\\")) {\\n // which variable are we updating?\\n int oldValue = varTable.get(line[0]);\\n\\n // what should its new value be?\\n int newValue = oldValue + evaluate(line[2]);\\n \\n // update\\n varTable.put(line[0], newValue);\\n }\\n else if (command.equals(\\"-=\\")) {\\n // which variable are we updating?\\n int oldValue = varTable.get(line[0]);\\n\\n // what should its new value be?\\n int newValue = oldValue - evaluate(line[2]);\\n \\n // update\\n varTable.put(line[0], newValue);\\n }\\n else if (command.equals(\\"*=\\")) {\\n // which variable are we updating?\\n int oldValue = varTable.get(line[0]);\\n\\n // what should its new value be?\\n int newValue = oldValue * evaluate(line[2]);\\n \\n // update\\n varTable.put(line[0], newValue);\\n }\\n\\n // jump if positive statement\\n else if (command.equals(\\"pos?jump\\")) {\\n // value of variable we are testing\\n int testValue = evaluate(line[0]);\\n \\n if (testValue > 0) { // positive?\\n pc += evaluate(line[2]); // jump!\\n // return right now so that we don''t hit the pc++ line below\\n return;\\n }\\n // else, take no special action\\n }\\n \\n // increment the program counter\\n pc++;\\n }\\n\\n // Is the program done?\\n // For MiniPro2, we have to check not only being at the end,\\n // but also after the end or before the start.\\n public boolean isDone() {\\n return pc >= program.length || pc < 0;\\n }\\n]\\\\\\n\\\\hide[\\npublic static void MP2Run_main() {\\n\\n // read all input into lines; handle Windows newlines & extra space\\n String[] allLines = StdIn.readAll().trim().split(\\"\\\\\\\\s*\\\\\\\\n\\");\\n\\n // two-dimensional array to hold program\\n String[][] program = new String[allLines.length][];\\n\\n // break each line into tokens\\n for (int i=0; i<allLines.length; i++)\\n program[i] = allLines[i].split(\\" \\");\\n \\n // construct intepreter\\n MiniPro2 mp = new MiniPro2(program);\\n\\n // execute the program\\n int steps = 0;\\n while (!mp.isDone()) {\\n mp.step();\\n steps++;\\n if (steps > 500) throw new Error(\\"MP2Run ran this MiniPro2 instance for 500 step()s, halting!\\\\nCheck for infinite looping behavior.\\");\\n }\\n} \\n]\\\\\\n", "tests": "\\ntitle = \\"Running <tt>java-introcs MP2Run </tt>\\";\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/data/MiniPro/math.txt\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Running <tt>java-introcs MP2Run </tt>\\";\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/data/MiniPro/absL.txt\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Running <tt>java-introcs MP2Run </tt>\\";\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/data/MiniPro/absR.txt\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Running <tt>java-introcs MP2Run </tt>\\";\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/data/MiniPro/sum10.txt\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Running <tt>java-introcs MP2Run </tt>\\";\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/data/MiniPro/gcf.txt\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\ny = 3\\\\nx += y\\\\nx println\\\\ny println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing += with variable: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\ny = 3\\\\nx -= y\\\\nx println\\\\ny println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing -= with variable: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\ny = 3\\\\nx *= y\\\\nx println\\\\ny println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing *= with variable: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\ny = 3\\\\nx *= y\\\\nx println\\\\ny println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing += with int: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\nx += 3\\\\nx println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing -= with int: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\nx += 3\\\\nx println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing *= with int: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\nx += 3\\\\nx println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing pos?jump with +ve LHS: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\nx pos?jump 2\\\\nx println\\\\nx println\\\\nx println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing pos?jump with 0 LHS: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 0\\\\nx pos?jump 2\\\\nx println\\\\nx println\\\\nx println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing pos?jump with -ve LHS: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = -2\\\\nx pos?jump 2\\\\nx println\\\\nx println\\\\nx println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing pos?jump with +ve LHS, var RHS: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\nx pos?jump x\\\\nx println\\\\nx println\\\\nx println\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing pos?jump to before start: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\nx pos?jump -126\\\\n100 print\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing pos?jump to just before start: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\nx pos?jump -2\\\\n100 print\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing pos?jump to just after end: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\nx pos?jump 2\\\\n100 print\\";\\ntest(\\"MP2Run_main\\");\\n\\ntitle = \\"Testing pos?jump to after end: running <tt>java-introcs MP2Run</tt> \\";\\nstdin = \\"x = 2\\\\nx pos?jump 126\\\\n100 print\\";\\ntest(\\"MP2Run_main\\");\\n\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(4, '[email protected]', 'java/15-practicefinal/Person', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Spring 2013 Programming Midterm 2, part 1/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/fall13/cos126/docs/mid2-s13-prog.pdf\\">\\nthis PDF link</a>. \\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>Because of Websheet formatting, on this page you have to put your header inside the class. On the exam, put it at the top as usual\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own, then copying here for full testing\\n<li>The exam grader is generally less picky about output whitespace than the Websheet grader.\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\npublic class Person { \\n\\\\[\\n/*************************************************************************\\n Reference solution for Spring 2013 COS 126 Programming Exam 2: Person\\n\\n Author: COS 126 Staff\\n Netid: cos126\\n Precepts: lots of them\\n Dependencies: Stack, Queue, StdOut\\n\\n Description: Models a person, a list of messages that they can\\n read, and a list of their friends, so that when you\\n post a message, all your friends can read it too.\\n\\n**************************************************************************/\\n private String name;\\n private Queue<Person> friends; // Stack or Queue, doesn''t matter\\n private Stack<String> wall; // Stack, so newest is iterated first\\n\\n // Create a new Person with this name.\\n public Person(String name) {\\n this.name = name;\\n this.friends = new Queue<Person>();\\n this.wall = new Stack<String>();\\n }\\n\\n // Make these two people become friends with each other.\\n // Throw an exception if you try to meet yourself.\\n // We are allowed to assume we didn''t meet this person yet.\\n public void meet(Person otherPerson) {\\n if (otherPerson == this)\\n throw new RuntimeException(\\"You can''t meet yourself\\");\\n\\n friends.enqueue(otherPerson); // remember this friend\\n otherPerson.friends.enqueue(this); // reciprocate\\n }\\n\\n // Are these two people friends?\\n // Throw an exception if you ask about knowing yourself.\\n public boolean knows(Person otherPerson) {\\n if (otherPerson == this)\\n throw new RuntimeException(\\"You can''t call knows() on yourself\\");\\n\\n // Search through all my friends\\n for (Person p : friends) {\\n if (p == otherPerson)\\n return true;\\n }\\n\\n // If otherPerson was not found, I don''t know them\\n return false;\\n }\\n\\n // Post a message to my list and the lists of all my friends\\n public void post(String message) {\\n wall.push(message); // add to my own list\\n\\n for (Person p : friends)\\n p.wall.push(message); // and to each friend''s\\n }\\n\\n // Print a header, then all messages this Person can read, newest first\\n public void listMessages() {\\n // header\\n StdOut.println(\\"== The wall of \\" + name + \\" ==\\");\\n\\n // Iterate through all messages and print them\\n for (String s : wall)\\n StdOut.println(s);\\n }\\n]\\\\ \\n}\\n", "tests": "\\nsaveAs = \\"first\\";\\ntestConstructor(\\"Kim\\");\\nsaveAs = \\"second\\";\\ntestConstructor(\\"Pat\\");\\ntestOn(\\"first\\", \\"knows\\", var(\\"second\\"));\\ntestOn(\\"first\\", \\"meet\\", var(\\"second\\"));\\ntestOn(\\"first\\", \\"knows\\", var(\\"second\\"));\\ntestOn(\\"second\\", \\"knows\\", var(\\"first\\"));\\nexpectException = true;\\ntestOn(\\"first\\", \\"knows\\", var(\\"first\\"));\\n\\nsaveAs = \\"first\\";\\ntestConstructor(\\"Kim\\");\\nsaveAs = \\"second\\";\\ntestConstructor(\\"Pat\\");\\ntestOn(\\"first\\", \\"post\\", \\"Only Kim can read this\\");\\ntestOn(\\"first\\", \\"meet\\", var(\\"second\\"));\\ntestOn(\\"second\\", \\"post\\", \\"Friends are awesome\\");\\ntestOn(\\"first\\", \\"post\\", \\"I agree\\");\\ntestOn(\\"first\\", \\"listMessages\\");\\ntestOn(\\"second\\", \\"listMessages\\");\\n\\nsaveAs = \\"testPerson\\";\\ntestConstructor(\\"Jack\\");\\nexpectException = true;\\ntestOn(\\"testPerson\\", \\"meet\\", var(\\"testPerson\\"));\\n\\nString samename = \\"Different people with the same name\\";\\nsaveAs = \\"a\\"; testConstructor(samename); \\nsaveAs = \\"b\\"; testConstructor(samename); \\nsaveAs = \\"c\\"; testConstructor(samename); \\nsaveAs = \\"d\\"; testConstructor(samename); \\ntestOn(\\"a\\", \\"meet\\", var(\\"b\\"));\\ntestOn(\\"b\\", \\"meet\\", var(\\"c\\"));\\ntestOn(\\"a\\", \\"post\\", \\"a posts this\\");\\ntestOn(\\"b\\", \\"post\\", \\"b posts this\\");\\ntestOn(\\"c\\", \\"post\\", \\"c posts this\\");\\ntestOn(\\"d\\", \\"post\\", \\"d posts this\\");\\ntestOn(\\"a\\", \\"listMessages\\");\\ntestOn(\\"b\\", \\"listMessages\\");\\ntestOn(\\"c\\", \\"listMessages\\");\\ntestOn(\\"d\\", \\"listMessages\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(5, '[email protected]', 'java/15-practicefinal/TigerBook', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Spring 2013 Programming Midterm 2, part 2/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/fall13/cos126/docs/mid2-s13-prog.pdf\\">\\nthis PDF link</a>. \\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>Because of Websheet formatting, on this page you have to put your header inside the class. On the exam, put it at the top as usual\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own, then copying here for full testing\\n<li>The exam grader is generally less picky about output whitespace than the Websheet grader.\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n<p>\\n<b>You have to solve the <a href=''javascript:websheets.load(\\"java/15-practicefinal/Person\\")''>Person</a> websheet before this one will work.</b> (But in a real exam, you don''t necessarily need\\nto complete one part to get credit for the next.)\\n", "dependencies": "[\\"java/15-practicefinal/Person\\"]", "source_code": "\\npublic class TigerBook { \\n\\\\[\\n/************************************************************************* \\n Reference solution for Spring 2013 COS 126 Programming Exam 2: TigerBook\\n\\n Author: COS 126 Staff\\n Netid: cos126\\n Precepts: lots of them\\n Dependencies: Person, ST\\n\\n Description: Models a collection of users (Person objects) each with\\n a unique id (String).\\n\\n**************************************************************************/\\n private ST<String, Person> users; // map each id to a user\\n\\n // Constructor\\n public TigerBook() {\\n users = new ST<String, Person>();\\n }\\n\\n // Add a person to the list of users.\\n // We are allowed to assume this id was not registered yet.\\n public void register(String id, Person p) {\\n users.put(id, p);\\n }\\n\\n // Return the person registered with this id.\\n // Throw a RuntimeException if no such person exists.\\n public Person lookup(String id) {\\n\\n // Was this id String registered?\\n if (!users.contains(id))\\n throw new RuntimeException(\\"User id not found\\");\\n\\n // return the right Person\\n return users.get(id);\\n }\\n]\\\\\\n\\\\hide[\\n public static void exampleClientMain(String[] args) {\\n TigerBook tb = new TigerBook(); \\n\\n while (!StdIn.isEmpty()) {\\n\\n String first = StdIn.readString(); // first word on line\\n \\n if (first.startsWith(\\"//\\")) { // is this line a comment?\\n StdIn.readLine(); // if so, skip the rest of the line\\n continue; // and don''t try to read an action\\n }\\n\\n String name = first; // the first word is a person \\n String action = StdIn.readString(); // now, read the action\\n\\n // now translate the action to method calls\\n if (action.equals(\\"registers\\")) {\\n Person newUser = new Person(name);\\n tb.register(name, newUser);\\n }\\n else if (action.equals(\\"meets\\")) {\\n String name2 = StdIn.readString();\\n Person user1 = tb.lookup(name);\\n Person user2 = tb.lookup(name2);\\n user1.meet(user2);\\n }\\n else if (action.equals(\\"posts\\")) {\\n String message = StdIn.readLine(); // read rest of line\\n message = message.substring(1); // get rid of space at start\\n Person user = tb.lookup(name);\\n user.post(message);\\n }\\n else if (action.equals(\\"queries\\")) {\\n String name2 = StdIn.readString();\\n Person user1 = tb.lookup(name);\\n Person user2 = tb.lookup(name2);\\n StdOut.print(\\"Are \\"+name+\\" and \\"+name2+\\" friends? \\");\\n boolean isFriend = user1.knows(user2);\\n StdOut.println(isFriend);\\n }\\n else if (action.equals(\\"reads\\")) {\\n Person user = tb.lookup(name);\\n user.listMessages();\\n }\\n else {\\n // this case would be triggered by a line like \\"person1 coughs\\"\\n // but could also be caused by typos, or putting too many words\\n // on one line, or not enough words on one line, etc\\n String msg = \\"ExampleClient doesn''t know how to perform action\\";\\n msg += \\" \\\\\\"\\"+action+\\"\\\\\\"\\\\n Your input is misformatted, \\";\\n msg += \\"see the ExampleClient header comment for help\\";\\n throw new RuntimeException(msg);\\n }\\n }\\n } \\n]\\\\\\n}\\n", "tests": "\\nsaveAs = \\"t\\";\\ntestConstructor();\\nsaveAs = \\"first\\";\\nconstruct(null, \\"Person\\", \\"\\", \\"Tony\\");\\ntestOn(\\"t\\", \\"register\\", \\"tony10010\\", var(\\"first\\"));\\nsaveAs = \\"personFound\\";\\ntestOn(\\"t\\", \\"lookup\\", \\"tony10010\\");\\ntestOn(\\"personFound\\", \\"listMessages\\");\\nexpectException = true;\\nsaveAs = \\"nobody\\";\\ntestOn(\\"t\\", \\"lookup\\", \\"tony-the-tiger\\");\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring13/cos126/docs/data/TigerBook/friendly.txt\\";\\ntestNamedMain(\\"exampleClientMain\\", \\"ExampleClient\\");\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring13/cos126/docs/data/TigerBook/mutual.txt\\";\\ntestNamedMain(\\"exampleClientMain\\", \\"ExampleClient\\");\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring13/cos126/docs/data/TigerBook/networking.txt\\";\\ntestNamedMain(\\"exampleClientMain\\", \\"ExampleClient\\");\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring13/cos126/docs/data/TigerBook/monologue.txt\\";\\ntestNamedMain(\\"exampleClientMain\\", \\"ExampleClient\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(6, '[email protected]', 'java/15-practicefinal/MiniPro', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Fall 2013 Programming Midterm 2, part 1/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/mid2-f13-prog.pdf\\">\\nthis PDF link</a>. \\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own before using automatic tests\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\n\\\\[\\n/**************************************************************************\\n * MiniPro: Interpreter for a miniature programming language.\\n * \\n * COS 126, Princeton University, Fall 2013, Programming Midterm 2 Part 1\\n * \\n * Dependencies: ST, StdOut\\n * \\n * Compilation: javac-introcs MiniPro.java\\n * \\n * Execution:\\n * % java-introcs MiniPro\\n * false\\n * 0\\n * currently x is 13\\n * 39\\n * 13\\n * true\\n **************************************************************************/\\n private int pc; // the program counter\\n private String[][] program; // the program itself\\n private ST<String, Integer> varTable; // values of all defined variables\\n \\n // Create interpreter for this program. Don''t execute it yet!\\n public MiniPro(String[][] program) {\\n this.program = program;\\n pc = 0; // line 0 is always the first to execute\\n varTable = new ST<String, Integer>();\\n }\\n\\n // Return the current value of the variable named v. If no\\n // such variable is currently defined, throw a RuntimeException.\\n public int valueOf(String v) {\\n if (!varTable.contains(v))\\n throw new RuntimeException(\\"Variable named \\" + v + \\" not defined\\");\\n return varTable.get(v);\\n }\\n\\n // Return the number of the line that will execute next.\\n public int programCounter() {\\n return pc;\\n }\\n\\n // Execute the line whose number equals the value of the\\n // program counter. Then, increment the program counter.\\n public void step() {\\n String[] line = program[pc]; // current line (1d piece of 2d array)\\n String command = line[1]; \\n\\n // assignment statement\\n if (command.equals(\\"=\\")) {\\n // look at token on right-hand side, evaluate it\\n String rhsToken = line[2];\\n int rhsValue;\\n \\n if (rhsToken.matches(\\"[a-z]+\\")) // it''s a variable name\\n rhsValue = varTable.get(rhsToken);\\n else // it''s an integer\\n rhsValue = Integer.parseInt(rhsToken);\\n \\n // save value in variable\\n varTable.put(line[0], rhsValue);\\n }\\n \\n // println statement\\n else if (command.equals(\\"println\\")) {\\n // get value of desired variable, then print it\\n int value = varTable.get(line[0]);\\n StdOut.println(value);\\n }\\n \\n // increment the program counter\\n pc++;\\n }\\n\\n // Is the program done?\\n public boolean isDone() {\\n return pc == program.length;\\n }\\n]\\\\\\n\\\\hide[\\npublic static void MPRun_main() {\\n\\n // read all input into lines; handle Windows newlines & extra space\\n String[] allLines = StdIn.readAll().trim().split(\\"\\\\\\\\s*\\\\\\\\n\\");\\n\\n // two-dimensional array to hold program\\n String[][] program = new String[allLines.length][];\\n\\n // break each line into tokens\\n for (int i=0; i<allLines.length; i++)\\n program[i] = allLines[i].split(\\" \\");\\n \\n // construct intepreter\\n MiniPro mp = new MiniPro(program);\\n\\n // execute the program\\n int steps = 0;\\n while (!mp.isDone()) {\\n mp.step();\\n steps++;\\n if (steps > 500) throw new Error(\\"MPRun ran this MiniPro instance for 500 step()s, halting!\\\\nCheck for infinite looping behavior.\\");\\n }\\n} \\n]\\\\\\n", "tests": "\\nsaveAs = \\"mp\\";\\ntestConstructor((Object)new String[][]\\n {{\\"x\\", \\"=\\", \\"13\\"}, // line 0\\n {\\"y\\", \\"=\\", \\"x\\"}, // line 1\\n {\\"x\\", \\"=\\", \\"39\\"}, // line 2\\n {\\"x\\", \\"println\\"}, // line 3\\n {\\"y\\", \\"println\\"}}); // line 4\\ntestOn(\\"mp\\", \\"isDone\\");\\ntestOn(\\"mp\\", \\"programCounter\\");\\ntestOn(\\"mp\\", \\"step\\");\\ntestOn(\\"mp\\", \\"valueOf\\", \\"x\\");\\ntestOn(\\"mp\\", \\"step\\");\\ntestOn(\\"mp\\", \\"step\\");\\ntestOn(\\"mp\\", \\"step\\");\\ntestOn(\\"mp\\", \\"isDone\\");\\n\\nsaveAs = \\"mpThrow\\";\\ntestConstructor((Object)new String[][]\\n {{\\"one\\", \\"=\\", \\"1\\"}}); // line 0\\ntestOn(\\"mpThrow\\", \\"programCounter\\");\\nexpectException = true;\\ntestOn(\\"mpThrow\\", \\"valueOf\\", \\"one\\");\\n\\ntitle = \\"Running <tt>java-introcs MPRun </tt>\\";\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/data/MiniPro/sample.txt\\";\\ntest(\\"MPRun_main\\");\\n\\ntitle = \\"Running <tt>java-introcs MPRun </tt>\\";\\nstdinURL = \\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/data/MiniPro/swap.txt\\";\\ntest(\\"MPRun_main\\");\\n\\nString program = \\"a = 1\\\\nb = 2\\\\nc = 3\\\\ntmp = a\\\\na = b\\\\nb = c\\\\nc = tmp\\\\na println\\\\nb println\\\\nc println\\";\\nString[] lines = program.split(\\"\\\\\\\\n\\");\\nString[][] p1 = new String[lines.length][];\\nfor (int i=0; i<lines.length; i++) p1[i] = lines[i].split(\\" \\");\\n \\nsaveAs = \\"mp3\\";\\ntestConstructor((Object)p1);\\ntestOn(\\"mp3\\", \\"programCounter\\");\\ntestOn(\\"mp3\\", \\"programCounter\\");\\ntestOn(\\"mp3\\", \\"isDone\\");\\nexpectException = true;\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"a\\");\\nexpectException = true;\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"b\\");\\nexpectException = true;\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"c\\");\\ntestOn(\\"mp3\\", \\"step\\");\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"a\\");\\ntestOn(\\"mp3\\", \\"step\\");\\ntestOn(\\"mp3\\", \\"step\\");\\ntestOn(\\"mp3\\", \\"programCounter\\");\\ntestOn(\\"mp3\\", \\"isDone\\");\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"a\\");\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"b\\");\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"c\\");\\ntestOn(\\"mp3\\", \\"step\\");\\ntestOn(\\"mp3\\", \\"step\\");\\ntestOn(\\"mp3\\", \\"step\\");\\ntestOn(\\"mp3\\", \\"step\\");\\ntestOn(\\"mp3\\", \\"programCounter\\");\\ntestOn(\\"mp3\\", \\"isDone\\");\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"a\\");\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"b\\");\\ntestOn(\\"mp3\\", \\"valueOf\\", \\"c\\"); \\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(7, '[email protected]', 'java/00-intro/NameAge', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing <code>args[]</code>, <code>System.out.print()</code> and <code>System.out.println()</code>, complete the code so that <code>java NameAge Trey 3</code> prints out \\n<pre>Trey is 3 years old.</pre>\\nYour code should print the name and age in the same format for any arguments <code>\\u00abname\\u00bb \\u00abage\\u00bb</code>.\\n", "source_code": "\\npublic static void main(String[] args) {\\n\\\\[\\n System.out.print(args[0]); // name\\n System.out.print(\\" is \\");\\n System.out.print(args[1]); // age\\n System.out.println(\\" years old.\\");\\n]\\\\\\n}\\n", "tests": "\\n //test(\\"main\\", (Object) new String[] {\\"Jim\\", \\"29\\"});\\n testMain(\\"Jim\\", \\"29\\");\\n testMain(\\"Jane\\", \\"9\\");\\n testMain(\\"Whiskers\\", \\"0\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(8, '[email protected]', 'java/00-intro/TwoPlusTwo', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nFill in the program so it <i>prints</i> out the integer obtained by adding 2 and 2.\\n", "source_code": "\\npublic static void main(String[] args) {\\n\\\\[\\n System.out.print(2+2);\\n]\\\\\\n}\\n", "tests": "\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(9, '[email protected]', 'java/00-intro/HelloWorld', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program that prints out\\n<pre>\\nHello, World\\n</pre>\\n", "source_code": "\\n/*\\n * Name: Alan Turing\\n * Netid: at12\\n * Precept: P63X\\n *\\n * A program with an existential greeting\\n */\\npublic class HelloWorld {\\n public static void main(String[] args) {\\n\\\\[\\n System.out.println(\\"Hello, World\\");\\n]\\\\\\n }\\n}\\n", "tests": "\\n testMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(10, '[email protected]', 'java/00-intro/SquareSwap', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nSwap the 4 variables indicated in the code to match the change\\nthat occurs when we rotate a square 90 degrees clockwise.\\n<br> Hint: If you get stuck, see how to swap two variables in Web Exercise 2 from\\n<a href=\\"http://introcs.cs.princeton.edu/java/12types/\\">booksite Section 1.2</a>. One of the important ideas from there needs to be used here.\\n<div><img style=''height:150px;margin-top:5px'' src=''http://cscircles.cemc.uwaterloo.ca/websheets/images/FourSwap.ipe.png''></div>\\n", "source_code": "\\n\\\\hide[\\npublic static void squareSwap(String top, String bottom,\\n String left, String right) {\\n String[] args = new String[0];\\n]\\\\\\n\\\\fake[\\npublic static void main(String[] args) {\\n // the grader will pre-define 4 variables with color names\\n String top = ...; // e.g. \\"red\\" or \\"blue\\", etc\\n String bottom = ...;\\n String left = ...;\\n String right = ...;\\n]\\\\\\n\\n System.out.println(\\"Before rotation, top = \\" + top + \\", bottom = \\" + bottom\\n + \\", left = \\" + left + \\", right = \\" + right + \\".\\");\\n // Now, write code to swap the variable values correctly,\\n // to reflect a clockwise 90-degree rotation being performed.\\n // The code you add doesn''t need to print anything.\\n\\\\[\\nString tmp = top; // save old value in new temp variable\\ntop = left; // write over old value\\nleft = bottom; // write over old value\\nbottom = right; // write over old value\\nright = tmp; // complete the swap using saved value\\n]\\\\\\n System.out.println(\\"After rotation, top = \\" + top + \\", bottom = \\" + bottom\\n + \\", left = \\" + left + \\", right = \\" + right + \\".\\");\\n}\\n", "tests": "\\ntitle = \\"We set <tt>top = red, bottom = green, left = blue, right = yellow</tt> and ran your code\\";\\ntest(\\"squareSwap\\", \\"red\\", \\"green\\", \\"blue\\", \\"yellow\\");\\n\\ntitle = \\"We set <tt>top = fuschia, bottom = turquoise, left = sienna, right = vermilion</tt> and ran your code\\";\\ntest(\\"squareSwap\\", \\"fuschia\\", \\"turquoise\\", \\"sienna\\", \\"vermilion\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(11, '[email protected]', 'java/00-intro/SquareOf', '{"sharing": "open", "attempts_until_ref": "1", "epilogue": "\\nIt''s better to call\\n<code>Integer.parseInt(args[0])</code>\\nonce rather than twice; \\navoiding redundant\\nfunction calls becomes more important\\nfor more complex programs. (Here it also helps readability.)\\n", "description": "\\nWrite a program that takes an integer number as a command-line argument,\\nand prints its square. For example, <pre>java SquareOf 10</pre> should print:\\n<pre>100</pre>\\nUse simple multiplication rather than using exponents.\\n", "source_code": "\\npublic static void main(String[] args) {\\n int inputNum =\\\\[Integer.parseInt(args[0])]\\\\; // convert the input\\n System.out.println(\\\\[inputNum * inputNum]\\\\); // print its square\\n}\\n", "tests": "\\n testMain(\\"4\\");\\n testMain(\\"-12\\");\\n testMain(\\"11111\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(12, '[email protected]', 'java/00-intro/NextYear', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<p><i>This is a more complex version of the <a href=''javascript:websheets.load(\\"java/00-intro/NameAge\\")''>NameAge</a> exercise.</i></p>\\nUsing <code>Integer.parseInt()</code>, \\ncomplete the code so that <code>java NextYear Trey 3</code> prints out \\n<pre>Next year, Trey will be 4 years old.</pre>\\nYour code should similarly compute the age next year for any arguments <code>\\u00abname\\u00bb \\u00abage\\u00bb</code>.\\n", "source_code": "\\npublic static void main(String[] args) {\\n\\\\[\\n System.out.print(\\"Next year, \\");\\n System.out.print(args[0]); // name\\n System.out.print(\\" will be \\");\\n int inputAge = Integer.parseInt(args[1]);\\n System.out.print(inputAge + 1);\\n System.out.println(\\" years old.\\");\\n]\\\\\\n}\\n", "tests": "\\n //test(\\"main\\", (Object) new String[] {\\"Jim\\", \\"29\\"});\\n testMain(\\"Jim\\", \\"29\\");\\n testMain(\\"Jane\\", \\"9\\");\\n testMain(\\"Whiskers\\", \\"0\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(13, '[email protected]', 'java/14-regex/RegularExercise', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nComplete the program below by defining five strings, each containing a regular\\nexpression to match one of the five languages indicated in the comments.\\nThe first one is filled in for you as an example. \\nYou may assume that we will only test your program on strings containing\\nthe letters <tt>E</tt>, <tt>G</tt>, <tt>R</tt> and <tt>X</tt>.", "source_code": "\\npublic class RegularExercise {\\n\\n // regular expression for: all strings that start with G or R\\n public static String startsWithGorR = \\"(G|R).*\\";\\n\\n // regular expression for: all strings that contain a substring \\"EX\\"\\n public static String containsEX = \\\\[\\".*EX.*\\"]\\\\;\\n\\n // regular expression for: all strings that do not contain an E\\n public static String noE = \\\\[\\"(R|G|X)*\\"]\\\\;\\n\\n // regular expression for: all strings in which every X is followed by a G\\n public static String everyXfollowedByG = \\\\[\\"(XG|G|R|E)*\\"]\\\\;\\n\\n // regular expression for: all strings that do not end with X\\n public static String doesNotEndWithX = \\\\[\\"(.*(G|R|E))|\\"]\\\\;\\n \\n public static void main(String[] args) {\\n StdOut.printf(\\"%24s%12s%6s%18s%16s\\\\n\\", \\"startsWithGorR\\", \\"containsEX\\",\\n \\"noE\\", \\"everyXfollowedByG\\", \\"doesNotEndWithX\\");\\n for (String a : args) {\\n StdOut.printf(\\"%8s%16s%12s%6s%18s%16s\\\\n\\", a, \\n a.matches(startsWithGorR),\\n a.matches(containsEX),\\n a.matches(noE),\\n a.matches(everyXfollowedByG),\\n a.matches(doesNotEndWithX));\\n }\\n }\\n \\n}\\n", "tests": "\\ntestMain(\\"REGEX\\", \\"GREE\\", \\"XRXG\\", \\"XX\\");\\ntest(\\"main\\", (Object)new String[]{\\"\\", \\"R\\", \\"G\\", \\"E\\", \\"X\\"});\\nString[] letters = {\\"R\\",\\"G\\",\\"E\\",\\"X\\"};\\ndefaultOptions.quietOnPass = true;\\nfor (String a : letters) for (String b : letters)\\ntest(\\"main\\", (Object)new String[]{a+b});\\nfor (String a : letters) for (String b : letters)\\nfor (String c : letters) \\ntest(\\"main\\", (Object)new String[]{a+b+c});\\nfor (String a : letters) for (String b : letters)\\nfor (String c : letters) \\nfor (String d : letters) \\ntest(\\"main\\", (Object)new String[]{a+b+c+d});\\nfor (String a : letters) for (String b : letters)\\nfor (String c : letters) \\nfor (String d : letters) \\nfor (String e : letters) \\ntest(\\"main\\", (Object)new String[]{a+b+c+d+e});\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(14, '[email protected]', 'java/16-threads/FJSort', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nTODO\\n", "imports": "[\\"java.util.concurrent.RecursiveAction\\", \\"java.util.concurrent.ForkJoinPool\\"]", "source_code": "\\npublic class FJSort {\\n public static void main(String[] args) {\\n int SIZE = 2_000_000;\\n int[] list = new int[SIZE];\\n \\n for (int i = 0; i < SIZE; i++)\\n list[i] = (int)(Math.random() * Integer.MAX_VALUE);\\n\\n int maxProc = Runtime.getRuntime().availableProcessors();\\n\\n // timing[i] : time to sort on i processors\\n long[] timing = new long[maxProc+1];\\n\\n for (int i=1; i<=maxProc; i++)\\n timing[i] = parallelMergeSort((int[])list.clone(), i);\\n \\n for (int i=2; i<=maxProc; i++)\\n if (!(timing[i] < timing[i-1]/1.05))\\n throw new RuntimeException(\\"More processors should make it faster!\\");\\n }\\n \\n public static long parallelMergeSort(int[] list, int proc) {\\n long startTime = System.currentTimeMillis();\\n\\n ForkJoinPool pool = new ForkJoinPool(proc);\\n pool.invoke(new SortTask(list));\\n pool.shutdown();\\n while (!pool.isTerminated()) Thread.yield();\\n\\n long time = System.currentTimeMillis() - startTime;\\n System.out.println(\\"Time with \\"+proc+\\" processors is \\"+time+\\" ms\\");\\n return time;\\n } \\n \\n private static class SortTask extends RecursiveAction {\\n private int[] list;\\n SortTask(int[] list) { this.list = list; }\\n \\n @Override\\n protected void compute() {\\n if (list.length < 2) return; // base case\\n\\n // split into halves \\n int[] firstHalf = new int[list.length / 2];\\n System.arraycopy(list, 0, firstHalf, 0, list.length / 2);\\n int secondHalfLength = list.length - list.length / 2;\\n int[] secondHalf = new int[secondHalfLength];\\n System.arraycopy(list, list.length / 2, secondHalf, 0, secondHalfLength);\\n \\n // recursively sort the two halves\\n\\\\[\\n invokeAll(new SortTask(firstHalf),\\n new SortTask(secondHalf));\\n\\\\show:\\n new SortTask(firstHalf).invoke();\\n new SortTask(secondHalf).invoke();\\n]\\\\\\n // merge halves together\\n merge(firstHalf, secondHalf, list);\\n }\\n }\\n\\n public static void merge(int[] list1, int[] list2, int[] merged) {\\n int i1 = 0, i2 = 0, i3 = 0; // index in list1, list2, out\\n \\n while (i1 < list1.length && i2 < list2.length) \\n merged[i3++] = (list1[i1] < list2[i2]) ? list1[i1++] : list2[i2++];\\n \\n // any trailing ends \\n while (i1 < list1.length) merged[i3++] = list1[i1++];\\n while (i2 < list2.length) merged[i3++] = list2[i2++];\\n }\\n}\\n", "tests": "\\ndontRunReference = true;\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(15, '[email protected]', 'java/16-threads/FTPLimiter', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nYou would like to download some files from an FTP site. You want to download 20 files called \\n<tt>file0.zip</tt>, <tt>file1.zip</tt>, ..., <tt>file19.zip</tt>. Assume that the <tt>static</tt> \\nmethod \\n<pre>FTP.get(String filename)</pre>\\nhas been defined for you, and that it tells your FTP client to download that named file from\\nthe server.\\n<p>\\n<i>However,</i> because you are downloading so many files, it will take a long time. You\\nwould like to speed this up by downloading multiple files at once. The FTP site allows\\n<b>up to 5 simultaneous downloads at once</b>. If you try to download more than 5 at once,\\nyour account will be banned.\\n<p>Use a <tt>Semaphore</tt> to download all of the files as quickly as possible while\\nnever downloading more than 5 at once.\\n", "imports": "[\\"java.util.concurrent.Semaphore\\"]", "source_code": "\\npublic class FTPLimiter {\\n\\\\hide[\\nstatic int NUMFILES = 20;\\n public static class FTP {\\n static int maxload = 0;\\n static int connections = 0;\\n static int successes = 0;\\n static int left = 0;\\n static Stopwatch w;\\n static int[] counts = new int[NUMFILES];\\n static int totalTime = 0;\\n static boolean errored = false;\\n static void init() {w = new Stopwatch();}\\n static String err = null;\\n static synchronized void error(String msg) {\\n if (err == null) err = msg;\\n errored = true;\\n }\\n public static void get(String filename) {\\n left++;\\n if (!(filename.startsWith(\\"file\\") || filename.endsWith(\\".zip\\")))\\n error(\\"File not on server: \\" + filename);\\n String c = filename.substring(4, filename.length()-4);\\n if (!(c.length()==1 || c.length()==2))\\n error(\\"File not on server: \\" + filename);\\n for (char ch:c.toCharArray()) if (ch < ''0'' || ch > ''9'')\\n error(\\"File not on server: \\" + filename);\\n if (c.charAt(0)==''0'' && c.length()==2)\\n error(\\"File not on server: \\" + filename);\\n if (errored) return;\\n int index = Integer.parseInt(c);\\n synchronized (FTP.class) {\\n connections++;\\n maxload = Math.max(maxload, connections);\\n System.out.println(\\"Getting \\"+filename+\\"...\\");\\n if (connections > 5) {error(\\"More than 5 connections!\\"); return;}\\n if (counts[index] > 0) {error(\\"Tried to download \\" + filename + \\" twice!\\"); return;}\\n counts[index] = 1;\\n }\\n int i = index;\\n int time = 5 + (i*67)%39;\\n try {Thread.sleep(time);} catch (InterruptedException e) {error(\\"interrupt!\\");}\\n synchronized (FTP.class) {successes++;\\n totalTime += time;\\n System.out.println(\\"... finished downloading \\"+filename+\\" (\\"+time+\\" ms)!\\");\\n connections--;\\n }\\n if (successes == NUMFILES) {\\n double elapsed = w.elapsedTime();\\n System.out.println(\\"Elapsed real time: \\" + elapsed + \\" seconds\\");\\n double load = totalTime/elapsed/1000;\\n System.out.printf(\\"Cumulative download time %d ms, average load %.3f, max load %d\\\\n\\", totalTime, load, maxload);\\n if (load <= 3) error(\\"Average load is too small.\\");\\n if (maxload <= 4) error(\\"Max load should be 5\\");\\n}\\n left--;\\n }\\n static void done() {\\n while (!errored && left > 0) Thread.yield();\\n if (successes < NUMFILES) error(\\"Did not download all files.\\");\\n if (errored) {throw new websheets.Grader.FailException(err);}\\n }\\n }\\n]\\\\\\n static Semaphore \\\\[semaphore = new Semaphore(5)]\\\\;\\n\\\\[\\nstatic class GetThread extends Thread {\\n String filename;\\n GetThread(String filename) {\\n this.filename = filename;\\n }\\n public void run() {\\n semaphore.acquireUninterruptibly();\\n try {\\n FTP.get(filename);\\n } finally {\\n semaphore.release();\\n }\\n }\\n}\\n\\\\show:\\n;// extra inner classes or anything else?\\n]\\\\\\n public static void main(String[] args) {\\\\hide[ FTP.init(); ]\\\\\\n\\\\[\\n for (int i=0; i<20; i++) \\n new GetThread(\\"file\\"+i+\\".zip\\").start();\\n]\\\\\\n\\\\hide[\\nFTP.done();\\n]\\\\\\n }\\n}\\n", "tests": "\\ndontRunReference = true;\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(16, '[email protected]', 'java/16-threads/SumParallel', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nCorrect the following program so that it correctly adds up\\nall of the numbers from 1 to <tt>n</tt>, where <tt>n</tt> is its command-line argument. \\nE.g., <tt>java Example1 100</tt> should print <tt>5050</tt>.\\n<p>\\nYou will have to fix two separate problems.\\n", "imports": "[\\"java.util.concurrent.*\\", \\"java.util.concurrent.locks.*\\"]", "source_code": "\\npublic class SumParallel {\\n\\n // utility function\\n static void nap(int limit_ms) {\\n try {Thread.sleep((int)(limit_ms*Math.random()));} \\n catch (InterruptedException ie) \\n {System.out.println(\\"!\\");} \\n }\\n \\n static int total;\\n\\n\\\\[\\n static Lock lock = new ReentrantLock();\\n\\\\show:\\n ; // more variables? \\n]\\\\\\n\\n // a class that adds a number to total\\n static class AdderRunnable implements Runnable {\\n int increment;\\n AdderRunnable(int increment) {this.increment = increment;}\\n public void run() {\\n\\\\[\\n // do nothing here\\n\\\\show:\\n;// maybe do something here?\\n]\\\\ \\n nap(10); // random delay up to 10ms\\n\\\\[\\n lock.lock();\\n\\\\show:\\n;// maybe do something here?\\n]\\\\\\n {\\n // increase total by increment\\n int oldTotal = total;\\n nap(2); // random delay up to 2ms\\n total = oldTotal + increment;\\n }\\n\\\\[\\n lock.unlock();\\n\\\\show:\\n;// maybe do something here?\\n]\\\\\\n }\\n }; \\n\\n public static void main(String[] args) {\\n total = 0; \\n\\n int n = Integer.parseInt(args[0]);\\n \\n // keep track of all the things we execute\\n // & impose limit b/c using many threads at makes memory run out\\n ExecutorService pool = Executors.newFixedThreadPool(23);\\n \\n for (int i=1; i<=n; i++)\\n pool.execute(new AdderRunnable(i));\\n\\n\\\\[\\n pool.shutdown(); // ask to shut down\\n while (!pool.isTerminated()) \\n Thread.yield(); // wait until shutdown complete\\n\\\\show:\\n pool.shutdown(); // ask to shut down\\n]\\\\\\n System.out.println(total);\\n }\\n}\\n", "tests": "\\ntestMain(100);\\ntestMain(1000);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(17, '[email protected]', 'java/01-types/Eggsactly', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nEgg cartons each hold exactly 12 eggs. Write a program which reads an integer\\nnumber of eggs as an argument, then prints out two numbers: how many cartons\\ncan be filled by these eggs, and how many eggs will be left over. For example,\\nthe output corresponding to <code>java Eggsactly 27</code> is\\n<pre>\\n2 3\\n</pre>\\nsince 27 eggs fill 2 cartons, leaving 3 eggs left over. <i>Hint:</i> use \\n<code>%</code>.\\n", "source_code": "\\npublic static void main(String[] args) {\\n int n = Integer.parseInt(args[0]); // number of eggs\\n System.out.print(\\\\[n / 12]\\\\); // number of filled 12-egg cartons\\n System.out.print(\\" \\"); \\n System.out.println(\\\\[n % 12]\\\\); // number of eggs left over\\n}\\n", "tests": "\\ntestMain(\\"27\\");\\ntestMain(randgen.nextInt(100)+\\"\\");\\ntestMain(randgen.nextInt(10)*12+\\"\\");\\ntestMain(randgen.nextInt(10)*12+1+\\"\\");\\ntestMain(randgen.nextInt(10)*12+11+\\"\\");\\n\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(18, '[email protected]', 'java/01-types/ThreeSort', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nRead 3 integer values from the command line and print them\\nin ascending order. For example, <code>java ThreeSort 8 2 5</code>\\nshould print out \\n<pre>\\n2 5 8\\n</pre>\\nHint: use functions from the <code>Math</code> library,\\nand a little algebra.", "source_code": "\\npublic class ThreeSort {\\n public static void main(String[] args) {\\n\\\\[\\n int a = Integer.parseInt(args[0]);\\n int b = Integer.parseInt(args[1]);\\n int c = Integer.parseInt(args[2]);\\n\\n int smallest = Math.min(a, Math.min(b, c));\\n int biggest = Math.max(a, Math.max(b, c));\\n // main trick: original sum equals the sorted sum\\n int middle = a + b + c - smallest - biggest;\\n\\n System.out.print(smallest + \\" \\");\\n System.out.print(middle + \\" \\");\\n System.out.println(biggest);\\n]\\\\\\n }\\n}\\n", "tests": "\\nfor (int[] a : new int[][]{\\n{1, 2, 3},\\n{3, 1, 2},\\n{3, 2, 1},\\n{1, 3, 2},\\n{2, 1, 3},\\n{2, 3, 1}}) \\ntestMain(a[0]*5+randgen.nextInt(5)+\\"\\", \\na[1]*5+randgen.nextInt(5)+\\"\\", \\na[2]*5+randgen.nextInt(5)+\\"\\");\\ntestMain(\\"8\\", \\"8\\", \\"5\\");\\ntestMain(\\"8\\", \\"5\\", \\"8\\");\\ntestMain(\\"5\\", \\"8\\", \\"8\\");\\ntestMain(\\"9\\", \\"4\\", \\"4\\");\\ntestMain(\\"4\\", \\"9\\", \\"4\\");\\ntestMain(\\"4\\", \\"4\\", \\"9\\");\\ntestMain(\\"10\\", \\"10\\", \\"10\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(19, '[email protected]', 'java/01-types/Distance', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n(<a href=\\"http://introcs.cs.princeton.edu/java/12types/\\">Web Exercise 1.2.1.</a>)\\nWrite a program <tt>Distance.java</tt> which, \\ngiven two integer command-line arguments, <tt>x</tt>\\nand <tt>y</tt>, computes the Euclidean distance from the point \\n$(x, y)$ to the origin $(0, 0)$ using the formula\\n$$\\\\textrm{distance} = \\\\sqrt{x^2 + y^2}.$$\\n\\nDo NOT use <tt>Math.pow(x, 2)</tt> to compute $x^2$. (It is too slow \\nfor many applications.) \\n\\n<p>Output your answer like the following:\\n<tt>java Distance 3 4</tt> should output\\n<pre style=''text-align: center''>\\ndistance from (3, 4) to (0, 0) = 5.0\\n</pre>\\n", "source_code": "\\npublic static void main(String[] args) {\\n // read point coordinates from input\\n int x = Integer.parseInt(\\\\[args[0]]\\\\);\\n\\\\[\\n int y = Integer.parseInt(args[1]);\\n]\\\\\\n \\n // compute distance\\n\\\\[\\n double dist = Math.sqrt(x*x + y*y);\\n]\\\\\\n\\n // print output\\n\\\\[\\n System.out.print(\\"distance from \\");\\n System.out.print(\\"(\\" + x + \\", \\" + y + \\")\\");\\n System.out.println(\\" to (0, 0) = \\" + dist);\\n]\\\\\\n}", "tests": "\\ntestMain(\\"3\\", \\"4\\");\\ntestMain(\\"0\\", \\"0\\");\\ntestMain(\\"1000\\", \\"1000\\");\\ntestMain(\\"-1064\\", \\"1710\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(20, '[email protected]', 'java/01-types/AboveAverage', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nInput 3 integer command line arguments whose numbers are in ascending order.\\nPrint the average of the 3 integers. \\nThen print true if the average of the 3 numbers is greater than the middle \\nnumber. Print false otherwise. For example, <code>java AboveAverage 2 5 8</code>\\nshould print out \\n<pre>\\nAverage is: 5.0\\nfalse\\n</pre>\\n", "lang": "Java", "source_code": "\\npublic class AboveAverage {\\n public static void main(String[] args) {\\n\\\\[\\n int a = Integer.parseInt(args[0]);\\n int b = Integer.parseInt(args[1]);\\n int c = Integer.parseInt(args[2]);\\n double avg = (a + b + c) / 3.0;\\n System.out.println(\\"Average is: \\" + avg);\\n boolean isGreater = (avg > b);\\n System.out.println(isGreater);\\n]\\\\\\n }\\n}\\n", "tests": "\\nfor (int[] a : new int[][]{\\n{1, 2, 3},\\n{3, 5, 7},\\n{3, 5, 9},\\n{1, 2, 3},\\n{2, 10, 30},\\n{2, 3, 6}}) \\ntestMain(a[0]*5+randgen.nextInt(5)+\\"\\", \\na[1]*5+randgen.nextInt(5)+\\"\\", \\na[2]*5+randgen.nextInt(5)+\\"\\");\\ntestMain(\\"5\\", \\"8\\", \\"8\\");\\ntestMain(\\"4\\", \\"4\\", \\"9\\");\\ntestMain(\\"3\\", \\"5\\", \\"9\\");\\ntestMain(\\"10\\", \\"10\\", \\"10\\");\\nexpectException = true;\\ntestMain(\\"10.0\\", \\"10\\", \\"10\\");\\nexpectException = true;\\ntestMain(\\"10\\", \\"10.0\\", \\"10\\");\\nexpectException = true;\\ntestMain(\\"10\\", \\"10\\", \\"10.0\\");\\n", "remarks": "Originally by Maia Ginsburg ([email protected]) and Dave Pritchard ([email protected])\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(21, '[email protected]', 'java/01-types/WindChill', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nYour program will be given two command-line arguments: <code>t</code>, representing the temperature \\n(in Fahrenheit), and <code>v</code>, representing the wind speed \\n(in miles per hour). It should print the wind chill <code>w</code> using the \\nfollowing formula:\\n$$\\\\LARGE w = 35.74 + 0.6215 \\\\times t + (0.4275 \\\\times t - 35.75) v ^ {0.16}$$\\nUse <code>Math.pow</code> to compute the exponent.\\n<i>Source</i>: <a href=\\"http://www.nws.noaa.gov/om/windchill/index.shtml\\">National Weather Service</a>\\n", "source_code": "\\npublic static void main(String[] args) {\\n double t =\\\\[ Double.parseDouble(args[0])]\\\\; // temperature\\n\\\\[\\n double v = Double.parseDouble(args[1]); // velocity\\n // careful to add all three * signs:\\n double w = 35.74 + 0.6215 * t + (0.4275 * t - 35.75) * Math.pow(v, 0.16);\\n System.out.println(w); // windchill\\n]\\\\\\n}\\n", "tests": "\\ntestMain(\\"32.0\\", \\"15.0\\");\\ntestMain(\\"-40\\", \\"6.2\\");\\ntestMain(\\"79.5\\", \\"27.62\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(22, '[email protected]', 'java/01-types/PizzaCalculator', '{"sharing": "open", "attempts_until_ref": "1", "description": " \\n<p>Write a program to help you feed your friends at a pizza party.\\nThere will be one command-line argument, the pizza''s radius.\\nThe area of the pizza is the square of the side length times π (use\\n<code>Math.PI</code>). \\nAssuming that each person needs to eat\\n100 cm<sup>2</sup> of pizza, compute the number of people you can feed,\\nrounded down to the nearest integer. For example, if you run \\n<code>java PizzaCalculator 10</code> the area will be 314.15...\\ncm<sup>2</sup>, so <code>3</code> is the correct output. \\n</p><p>Hint: use an explicit typecast at the end.</p>\\n", "source_code": "\\npublic class PizzaCalculator {\\n public static void main(String[] args) {\\n double PERSONAL_AREA = 100; // in square cm\\n\\\\[\\n double r = Double.parseDouble(args[0]); // radius\\n double area = r*r*Math.PI;\\n // cast to int rounds down:\\n int people = (int) (area / 100); \\n System.out.println(people);\\n]\\\\\\n }\\n}\\n", "tests": "\\ntestMain(\\"10\\");\\ntestMain(\\"10.0\\");\\ntestMain(\\"100.0\\");\\ntestMain(\\"30.48\\");\\ntestMain(randgen.nextInt(20000)*0.001+\\"\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(23, '[email protected]', 'java/01-types/PercentScore', '{"sharing": "open", "attempts_until_ref": "1", "epilogue": "\\nIf you used <i>integer division</i> like this,\\n<pre>100 * (score1 + score2) / (total1 + total2)</pre>\\nJava interprets this as dividing an integer by an integer,\\nand will give you an integer answer, which is not correct.\\n<p>The reference solution shows one correct approach, or you can <i>typecast</i> to a floating-point number before dividing,\\nlike this:\\n<pre>(double) (score1 + score2) / (total1 + total2) * 100</pre>\\n", "description": "\\nCompute your average score on a two-part exam.\\nYou will be given 4 command-line arguments:\\n<ul>\\n<li>The number of questions you got right on the first part</li>\\n<li>The total number of questions on the first part</li>\\n<li>The number of questions you got right on the second part</li>\\n<li>The total number of questions on the second part</li>\\n</ul>\\nOutput your percentage score on the exam. For example, for\\n<pre>PercentScore 8 10 15 17</pre>\\nsince you got a total of 23 questions correct out of 27 \\nand 23/27 = 0.8518… you should print\\n<pre>85.18518518518519</pre>\\nYou may assume the total number of questions is positive.\\n", "source_code": "\\npublic class PercentScore {\\n public static void main(String[] args) {\\n\\\\[\\n int score1 = Integer.parseInt(args[0]);\\n int total1 = Integer.parseInt(args[1]);\\n int score2 = Integer.parseInt(args[2]);\\n int total2 = Integer.parseInt(args[3]);\\n // avoid integer division:\\n System.out.println(100.0 * (score1 + score2) / (total1 + total2));\\n]\\\\\\n }\\n}\\n", "tests": "\\ntestMain(\\"8\\", \\"10\\", \\"15\\", \\"17\\");\\ntestMain(\\"10\\", \\"10\\", \\"5\\", \\"5\\");\\ntestMain(randgen.nextInt(130)+\\"\\", \\"130\\", randgen.nextInt(70)+\\"\\", \\"70\\");\\ntestMain(randgen.nextInt(10)+\\"\\", 10+randgen.nextInt(12)+\\"\\", randgen.nextInt(70)+\\"\\", 70+randgen.nextInt(5)+\\"\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(24, '[email protected]', 'java/07-recursion/Factorial', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a recursive method <code>factorial(n)</code>\\nthat returns n × (n-1) × (n-2) × … × 3 × 2 × 1. For example, <code>factorial(4)</code> should return 24 since that is the value of 1 × 2 × 3 × 4.\\n", "source_code": "\\npublic static \\\\[long]\\\\ factorial(\\\\[int n]\\\\) {\\n // base case\\n if (\\\\[n == 0]\\\\) \\n return \\\\[1]\\\\;\\n\\n // reduction step\\n // note that n! = n * (n-1) * ... * 2 * 1 = n * ((n-1) * ... * 2 * 1)\\n return \\\\[n]\\\\ * factorial(\\\\[n-1]\\\\);\\n}\\n\\npublic static void main(String[] args) {\\n StdOut.println(factorial(4)); // should be 24\\n StdOut.println(factorial(10)); // should be 3628800\\n StdOut.println(factorial(20)); // watch for overflow. what return type?\\n}", "tests": "\\ntestMain();\\ntest(\\"factorial\\", 1);\\ntest(\\"factorial\\", 6);\\ntest(\\"factorial\\", 11);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(25, '[email protected]', 'java/07-recursion/BinarySum', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a recursive static method <code>binaryDigitSum(n)</code> that\\ntakes a nonnegative integer <code>n</code> and\\n<ul>\\n<li>if <code>n</code> is zero, returns zero</li>\\n<li>if <code>n</code> is odd, returns one plus <code>binaryDigitSum(n/2)</code>\\n</li>\\n<li>if <code>n</code> is even and not zero, returns <code>binaryDigitSum(n/2)\\n</code></li>\\n", "source_code": "\\n// sum of the binary digits of n\\n\\\\[\\npublic static int binaryDigitSum(int n) {\\n if (n==0) return 0;\\n\\n if (n%2 == 1) // is n odd?\\n return 1 + binaryDigitSum(n/2);\\n\\n // n is even and positive\\n return binaryDigitSum(n/2);\\n}\\n]\\\\\\n\\npublic static void main(String[] args) {\\n StdOut.println(binaryDigitSum(5)); // should be 2, 5 is 101\\n StdOut.println(binaryDigitSum(25)); // should be 3, 25 is 11001\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"binaryDigitSum\\", 0);\\ntest(\\"binaryDigitSum\\", 1);\\ntest(\\"binaryDigitSum\\", 2);\\ntest(\\"binaryDigitSum\\", 3);\\ntest(\\"binaryDigitSum\\", 4);\\ntest(\\"binaryDigitSum\\", 126);\\ntest(\\"binaryDigitSum\\", 255);\\ntest(\\"binaryDigitSum\\", 256);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(26, '[email protected]', 'java/07-recursion/ZeroSum', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<div>\\nIs it possible to assign + and – signs to the numbers\\n<pre>\\n1434 3243 343 5 293 3408 123 487 93 12 2984 29\\n</pre>\\nso that the sum is 0? With recursion, we can try all possible combinations\\nof + and – for each number to find out. There are $2^n$ ways to assign\\n+ or – signs to $n$ numbers, and recursion can accomplish this by making\\ntwo recursive calls (one for +, one for –) at each of $n$ levels.\\nEach branch of the recursive call tree will keep a running sum of the numbers\\nit has assigned signs so far. To implement this in Java,\\nwrite a recursive static method\\n<pre>boolean testAllCombs(int runningSum, int[] nums, int seenSoFar)</pre>\\nwhich tries every assignment of +/– signs to the numbers\\n<pre>nums[seenSoFar], nums[seenSoFar+1], …, nums[nums.length-1]</pre> and adds each sum of signed numbers to\\n<code>runningSum</code>. To do this and acheieve the overall goal, your method should:\\n<ol>\\n<li>return true if <tt>seenSoFar</tt> is the same \\nas nums.length (we examined all numbers) and runningSum is zero, this means we got 0 as the sum\\nfor the choice of signs on this leaf of the recursive call tree</li>\\n<li>return false if <tt>seenSoFar</tt> is the same\\nas nums.length (we examined all numbers) and runningSum is not zero, this means we missed 0 as the sum for the choice of signs\\non this leaf of the recursive call tree</li>\\n<li>otherwise, recursively call <code>testAllCombs</code> on \\n<code>runningSum ± nums[seenSoFar]</code> and with <code>seenSoFar+1</code> in place of <code>seenSoFar</code>;\\nreturn true if <i>either one</i> of the two recursive calls returns true\\n</li>\\n</ol>\\nUsing seenSoFar is analogous to the level of a fractal, to control \\nthe recursion depth and ensure that each number is included (as + or \\n–) exactly once\\nin each branch.\\nOther than this, how is this recursive method used to achieve our goal?\\nTo test if <tt>int[] arr</tt> has a zero-sum signing, \\nwe make an initial call with <tt>testAllCombs(0, arr, 0)</tt>.\\nIf there is some 0-sum signing, then some call\\non the bottom level (seenSoFar = nums.length) has a runningSum of \\n0 and by rule 1, returns\\ntrue. By rule 2, this true value is propagated up the recursive call tree \\nto return true at the top.\\n", "source_code": "\\npublic static boolean testAllCombs(int runningSum, int[] nums, int seenSoFar) {\\n\\\\[\\n // we''ve given a sign to all numbers\\n if (seenSoFar == nums.length) {\\n if (runningSum == 0) \\n return true; // hit the runningSum\\n else\\n return false; // missed the runningSum\\n }\\n\\n // try both possibilities, propagating any hit\\n if (testAllCombs(runningSum + nums[seenSoFar], nums, seenSoFar+1))\\n return true;\\n\\n if (testAllCombs(runningSum - nums[seenSoFar], nums, seenSoFar+1))\\n return true;\\n\\n // neither recursive call found a solution\\n return false;\\n]\\\\\\n}\\n\\npublic static void main(String[] args) {\\n int[] testArr = {1434, 3243, 343, 5, 293, 3408, 123, 487, 93, 12, 2984, 29};\\n // should print true because\\n // -1434+3243-343-5-293-3408-123-487-93-12+2984-29 = 0\\n StdOut.println(testAllCombs(0, testArr, 0)); // true\\n testArr = new int[] {1, 2};\\n // no way to make zero\\n StdOut.println(testAllCombs(0, testArr, 0)); // false\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"testAllCombs\\", 0, new int[] {1, 1, 1, 1, 1, 1}, 0);\\ntest(\\"testAllCombs\\", 0, new int[] {1, 1, 1, 1, 1, 1, 1}, 0);\\ntest(\\"testAllCombs\\", 0, new int[] {1, 2, 3, 4, 5, 6}, 0);\\ntest(\\"testAllCombs\\", 0, new int[] {1, 2, 3, 4, 5, 6, 7}, 0);\\ntest(\\"testAllCombs\\", 0, new int[] {1000, 100000, 100, 111111, 10, 1, 10000}, 0);\\ntest(\\"testAllCombs\\", 0, new int[] {9, 16, 25}, 0);\\ntest(\\"testAllCombs\\", 0, new int[] {0, 0, 0}, 0);\\ntest(\\"testAllCombs\\", 0, new int[] {1435, 3243, 343, 5, 293, 3408, 123, 487, 93, 12, 2984, 29}, 0);\\ntest(\\"testAllCombs\\", 0, new int[] {1434, 3253, 343, 5, 293, 3408, 123, 487, 93, 22, 2984, 29}, 0);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(27, '[email protected]', 'java/07-recursion/Kettles', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>Kettles</code> with a recursive static method\\n<code>sing(n)</code> which prints the famous \\"kettles of tea\\" song.\\nFor example, when <code>n</code> is 3, calling <code>sing(3)</code>\\nshould print out\\n<pre>\\n3 kettles of tea on the wall\\n3 kettles of tea\\ntake one down, pass it around\\n2 kettles of tea on the wall!\\n2 kettles of tea on the wall\\n2 kettles of tea\\ntake one down, pass it around\\n1 kettles of tea on the wall!\\n1 kettles of tea on the wall\\n1 kettles of tea\\ntake one down, pass it around\\nno more kettles of tea on the wall!\\n</pre>\\n<div>\\n<i>To sing this song, first sing the first four lines, and then sing\\nthe song for a smaller value of n (unless you are done).</i>\\nThis is the strategy that you can turn into\\na recursive method.\\n</div>\\nNote that we require your song to say <code>1 kettles</code>\\ninstead of the grammatically correct <code>1 kettle</code>. Fixing this \\nis left as a challenge for the thirsty.\\n", "source_code": "\\npublic static void sing(int n) {\\n // print three lines\\n\\\\[\\n StdOut.println(n + \\" kettles of tea on the wall\\");\\n StdOut.println(n + \\" kettles of tea\\");\\n StdOut.println(\\"take one down, pass it around\\");\\n]\\\\\\n if (n > 1) {\\n // sing fourth line, with exclamation point!\\n\\\\[\\n StdOut.println(n-1 + \\" kettles of tea on the wall!\\");\\n]\\\\\\n // call sing recursively on remaining kettles\\n sing(\\\\[n-1]\\\\);\\n }\\n else { \\n // sing the final line, with exclamation point!\\n\\\\[\\n StdOut.println(\\"no more kettles of tea on the wall!\\");\\n]\\\\\\n }\\n}\\n\\npublic static void main(String[] args) {\\n sing(Integer.parseInt(args[0]));\\n}\\n", "tests": "\\ntestMain(3);\\ntest(\\"sing\\", 1);\\ntestMain(9);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(28, '[email protected]', 'java/07-recursion/Evaluate', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a static method <code>evaluate()</code> that evaluates\\na mathematical expression (a String) consisting of\\nintegers, +, *, and parentheses.\\nBy definition, it must use\\n recursion to evaluate two halves of the expression and\\ncombine them. The string manipulation and logic are filled in, but\\nyou need to add two recursive calls and a base case.\\n", "source_code": "\\npublic static int evaluate(String expression) {\\n // here -1 means ''not found yet''\\n int plusPos = -1; // position of last ''+'' outside of parentheses\\n int timesPos = -1; // position of last ''*'' outside of parentheses\\n\\n // scan expression, looking for operators outside of parentheses\\n int level = 0; // current nesting depth\\n for (int i=0; i<expression.length(); i++) {\\n char ch = expression.charAt(i);\\n\\n // look for operator\\n if (ch==''+'' && level==0) plusPos = i;\\n if (ch==''*'' && level==0) timesPos = i;\\n \\n // count level of parentheses\\n if (ch==''('') level++;\\n if (ch=='')'') level--;\\n }\\n \\n // recurse on lowest-precedence operator\\n\\n if (plusPos != -1) {\\n // break down, e.g. \\"3*4+5*6\\" => \\"3*4\\" and \\"5*6\\"\\n String exprLeft = expression.substring(0, plusPos);\\n String exprRight = expression.substring(plusPos+1);\\n int valueLeft = evaluate(exprLeft);\\n int valueRight = evaluate(exprRight);\\n return valueLeft + valueRight;\\n }\\n else if (timesPos != -1) {\\n // break down, e.g. \\"(3+4)*(5+6)\\" => \\"(3+4)\\" and \\"(5+6)\\"\\n String exprLeft = expression.substring(0, timesPos);\\n String exprRight = expression.substring(timesPos+1);\\n\\\\[\\n int valueLeft = evaluate(exprLeft);\\n int valueRight = evaluate(exprRight);\\n return valueLeft * valueRight;\\n]\\\\\\n }\\n else if (expression.charAt(0)==''('') {\\n // everything was in a matched pair of parentheses\\n // break down, e.g. \\"(3*4)\\" => \\"3*4\\"\\n return evaluate(expression.substring(1, expression.length()-1));\\n }\\n else {\\n // base case: just a number. convert expression to int.\\n // don''t make any recursive calls\\n return \\\\[Integer.parseInt(expression)]\\\\;\\n }\\n}\\n\\npublic static void main(String[] args) {\\n String test = \\"1*2+3*(4+5)\\";\\n StdOut.println(test + \\" evaluates to \\" + evaluate(test));\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"evaluate\\", \\"2*2+3*3\\");\\ntest(\\"evaluate\\", \\"(3+4)*(5+6)\\");\\ntest(\\"evaluate\\", \\"126\\");\\ntest(\\"evaluate\\", \\"(2*(1+6*2+2)+6*6+2*2*(1+2+6))+6*2*2\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(29, '[email protected]', 'java/07-recursion/TextFractal', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nA ruler''s pattern makes shorter marks each time you divide the length\\nin half. Mimic this with a static method <code>printRuler(n)</code> that\\nprints a ruler like this whose longest line has length <code>n</code>.\\nFor example <code>printRuler(2)</code> should print out\\n<pre>\\n-\\n--\\n-\\n</pre>\\nand <code>printRuler(3)</code> should print out\\n<pre>\\n-\\n--\\n-\\n---\\n-\\n--\\n-\\n</pre>\\n", "source_code": "\\npublic static void printRuler(int n) {\\n // return if we''re in the base case. \\n\\\\[\\n if (n == 0) return;\\n]\\\\\\n // otherwise, make two recursive calls, with a length-n line in between\\n printRuler(\\\\[n-1]\\\\);\\n\\\\[\\n for (int i=0; i<n; i++)\\n StdOut.print(''-'');\\n StdOut.println(); \\n printRuler(n-1);\\n]\\\\\\n}\\n\\npublic static void main(String[] args) {\\n // just a test\\n printRuler(3);\\n}\\n", "tests": "\\ntest(\\"printRuler\\", 1);\\ntest(\\"printRuler\\", 2);\\ntest(\\"printRuler\\", 3);\\ntest(\\"printRuler\\", 4);\\ntest(\\"printRuler\\", 5);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(30, '[email protected]', 'java/03-arrays/Reverse', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>Reverse</code> that takes any number\\nof command-line arguments and prints them out on a single\\nline in reverse order. For example, <code>java Reverse these words will be reversed</code> should output\\n<pre>reversed be will words these</pre>\\nFor simplicity, add spaces after each word, including the last one.\\n", "source_code": "\\npublic static void main(String[] args) {\\n\\\\[\\n for (int i=args.length-1; i>=0; i--)\\n System.out.print(args[i]+\\" \\");\\n]\\\\\\n}\\n", "tests": "\\ntestMain(\\"reversed\\", \\"be\\", \\"will\\", \\"words\\", \\"these\\");\\ntestMain(\\"arrays\\", \\"are\\", \\"awesome\\");\\ntestMain(\\"The\\", \\"structure\\", \\"of\\", \\"a\\", \\"sentence\\", \\"is\\", \\"not\\", \\"symmetric\\");\\ntestMain(\\"one-word\\");\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(31, '[email protected]', 'java/03-arrays/Students', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n Read an integer N from standard input, then a list\\n of N student records, where each record consists of four\\n fields, separated by whitespace:\\n<ul>\\n<li>first name</li>\\n<li>last name</li>\\n<li>email address</li>\\n<li>which section they''re in</li>\\n</ul>\\n Then, print a list of email address of students in sections 4 and 5.\\n (Booksite Web Exercise 1.5.31)\\n\\n<div>\\nFor example, if the standard input is \\n<pre>\\n6\\nBob Sedgewick rs 1\\nKevin Wayne wayne 4\\nDonna Gabai dgabai 5\\nDavid Pritchard dp6 6\\nJudith Israel jlisrael 3\\nAlan Turing turing 4\\n</pre>\\nThen the output should be\\n<pre>\\nSection 4\\n---------\\nwayne\\nturing\\n\\nSection 5\\n---------\\ndgabai\\n</pre>\\n", "source_code": "\\npublic static void main(String[] args) { \\n\\n // read the number of students\\n int N = \\\\[StdIn.readInt()]\\\\ ;\\n\\n // declare and initialize four parallel arrays\\n String[] first = new String[N];\\n \\\\[String[]]\\\\ last = \\\\[new String[N]]\\\\;\\n String[] \\\\[email]\\\\ = \\\\[new String[N]]\\\\;\\n int[] section = \\\\[new int[N]]\\\\;\\n\\n // read in the data from standard input\\n for (\\\\[int i=0; i<N; i++]\\\\) {\\n first[\\\\[i]\\\\] = \\\\[StdIn.readString();]\\\\ \\n last[\\\\[i]\\\\] = \\\\[StdIn.readString();]\\\\ \\n email[\\\\[i]\\\\] = \\\\[StdIn.readString();]\\\\ \\n section[\\\\[i]\\\\] = \\\\[StdIn.readInt();]\\\\ \\n }\\n\\n // print email addresses of all students in section 4\\n StdOut.println(\\"Section 4\\");\\n StdOut.println(\\"---------\\");\\n for (int i = 0; i < N; i++) {\\n if (\\\\[section[i] == 4]\\\\) {\\n StdOut.println(\\\\[email[i]]\\\\);\\n }\\n }\\n StdOut.println(); // blank line\\n\\n // print email addresses of all students in section 5\\n StdOut.println(\\"Section 5\\");\\n StdOut.println(\\"---------\\");\\n for \\\\[(int i = 0; i < N; i++)]\\\\ {\\n\\\\[\\n if (section[i] == 5) {\\n StdOut.println(email[i]);\\n }\\n]\\\\\\n }\\n} \\n", "tests": "\\nstdin = \\"6\\\\nBob Sedgewick rs 1\\\\nKevin Wayne wayne 4\\\\nDonna Gabai dgabai 5\\\\nDavid Pritchard dp6 6\\\\nJudith Israel jlisrael 3\\\\nAlan Turing turing 4\\";\\ntestMain();\\nstdinURL = \\"http://introcs.cs.princeton.edu/java/15inout/students.txt\\";\\ntestMain();\\nstdin = \\"1\\\\nJoe Student joestu 0\\\\nYour program should only have read 1 student for this input\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(32, '[email protected]', 'java/03-arrays/NOrdered', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>NOrdered</code> that takes any\\nnumber of integer command-line arguments. If they are in strictly\\nincreasing or strictly descreasing order, it should print <code>true</code>.\\nOtherwise it should print <code>false</code>.\\n", "source_code": "\\npublic static void main(String[] args) {\\n int n = args.length; // for convenience\\n\\\\[\\n int[] vals = new int[n];\\n for (int i=0; i<n; i++)\\n vals[i] = Integer.parseInt(args[i]);\\n \\n // check for increasing\\n boolean increasing = true;\\n for (int i=0; i<n-1; i++) // one shorter than usual\\n increasing = increasing && (vals[i] < vals[i+1]);\\n\\n // check for decreasing\\n boolean decreasing = true;\\n for (int i=0; i<n-1; i++) // one shorter than usual\\n decreasing = decreasing && (vals[i] > vals[i+1]);\\n\\n System.out.println(increasing || decreasing);\\n]\\\\\\n}\\n", "tests": "\\ntestMain(1, 2, 6);\\ntestMain(100, 25, 10, 5, 1);\\ntestMain(9, 999, 99);\\ntestMain(10, 15, 15, 20);\\ntestMain(1, 2, 3, 4, 5, 4, 3, 2, 1);\\ntestMain(10, 100);\\ntestMain(10, 10);\\ntestMain(1, 10, 2, 11, 3, 12);\\ntestMain(126);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(33, '[email protected]', 'java/03-arrays/Commonest', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<div>\\nWrite a program <code>Commonest</code> that takes any number of command-line\\narguments, which will be strings, and prints out the one that occurs most\\noften. For example <code>java Commonest cat dog monkey cat goose</code>\\nshould print out <code>cat</code> and <code>java Commonest a a b b b</code> should print out <code>b</code>.\\n</div>\\n<div>\\nIf more than one word is the commonest, print out the first one that \\noccurs. Don''t forget that strings have to be compared with <code>.equals</code>\\ninstead of <code>==</code>.\\n</div>", "source_code": "\\npublic static void main(String[] args) {\\n String commonest = \\"\\"; // just a placeholder for now\\n int commonest_count = -1; // same\\n int n = args.length;\\n for (int i=0; i<n; i++) {\\n // count how many times args[i] occurred\\n\\\\[\\n int count=0;\\n for (int j=0; j<n; j++) { // look everywhere\\n if (args[i].equals(args[j])) // when you find it\\n count++; // count it\\n }\\n]\\\\\\n // we found a new commonest word\\n if (count > commonest_count) {\\n commonest = args[i];\\n commonest_count = count;\\n }\\n }\\n System.out.println(commonest);\\n}\\n", "tests": "\\ntestMain(\\"dog\\", \\"cat\\", \\"fish\\", \\"bird\\", \\"cat\\");\\ntestMain(\\"a\\", \\"a\\", \\"a\\", \\"b\\", \\"b\\", \\"a\\", \\"b\\", \\"b\\", \\"b\\");\\ntestMain(\\"the\\", \\"commonest\\", \\"word\\", \\"in\\", \\"the\\", \\"English\\", \\"language\\");\\ntestMain(\\"first\\", \\"second\\", \\"third\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(34, '[email protected]', 'java/03-arrays/NSwap', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nThis is an extension of the <a href=''javascript:websheets.load(\\"java/00-intro/SquareSwap\\")''>SquareSwap</a> websheet.\\nGiven an array <code>colors</code> of <code>n</code> strings,\\nmove each string one position later in the array; and, you\\nmust move the one at the end to the start.\\n", "source_code": "\\npublic static void main(String[] args) {\\n // the grader will pre-define an array of color names\\n String[] colors = \\\\fake[...; // e.g. new String[] {\\"red\\", \\"blue\\", \\"green\\"};]\\\\ \\\\hide[args.clone();]\\\\ \\n int n = colors.length; // for convenience\\n\\n System.out.println(\\"Before n-swapping:\\");\\n for (int i=0; i<n; i++)\\n System.out.println(\\"color \\" + i + \\" is \\" + colors[i]);\\n \\n // your swapping code here:\\n\\\\[\\n String tmp = colors[n-1];\\n for (int i=n-1; i>=1; i--)\\n colors[i] = colors[i-1];\\n colors[0] = tmp;\\n]\\\\\\n System.out.println(\\"After n-swapping:\\");\\n for (int i=0; i<n; i++)\\n System.out.println(\\"color \\" + i + \\" is \\" + colors[i]);\\n}\\n", "tests": "\\ntitle = \\"Running with <tt>colors[] = {\\\\\\"red\\\\\\", \\\\\\"green\\\\\\", \\\\\\"blue\\\\\\"}</tt>\\";\\ntestMain(\\"red\\", \\"green\\", \\"blue\\");\\n\\ntitle = \\"Running with <tt>colors[] = {\\\\\\"fuschia\\\\\\", \\\\\\"turquoise\\\\\\", \\\\\\"sienna\\\\\\", \\\\\\"vermilion\\\\\\"}</tt>\\";\\ntestMain(\\"fuschia\\", \\"turquoise\\", \\"sienna\\", \\"vermilion\\");\\n\\ntitle = \\"Running with <tt>colors[] = {\\\\\\"a\\\\\\", \\\\\\"b\\\\\\", \\\\\\"c\\\\\\", \\\\\\"d\\\\\\", \\\\\\"e\\\\\\", \\\\\\"f\\\\\\", \\\\\\"g\\\\\\", \\\\\\"h\\\\\\"}</tt>\\"; \\ntestMain(\\"a\\", \\"b\\", \\"c\\", \\"d\\", \\"e\\", \\"f\\", \\"g\\", \\"h\\");\\n\\ntitle = \\"Running with <tt>colors[] = {\\\\\\"monocolor\\\\\\"}</tt>\\";\\ntestMain(\\"monocolor\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(35, '[email protected]', 'java/03-arrays/Distinct', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>Distinct</code> that takes an arbitrary\\nnumber of integer command-line arguments; it should print\\n<code>true</code> if they all have distinct values, and \\n<code>false</code> otherwise.", "source_code": "\\npublic class Distinct {\\n public static void main(String[] args) {\\n \\n int N = args.length; \\n \\n // convert each arg and store them in an array of integers\\n int[] values =\\\\[ new int[N] ]\\\\;\\n for (int i = 0; \\\\[i < N]\\\\; \\\\[i += 1]\\\\)\\n \\\\[ values[i] ]\\\\ = Integer.parseInt(args[i]); \\n \\n // are all of the pairs examined so far distinct?\\n boolean result = true;\\n\\n // we''ll examine each values[i] in the array \\n for (int i = 0; i < N; i++) {\\n // we''ll examine values[j] for each other j\\n for (int j =\\\\[i+1]\\\\; \\\\[j < N]\\\\; \\\\[j++]\\\\) {\\n // are they different or not?\\n if (\\\\[values[i] == values[j]]\\\\) {\\n result =\\\\[false]\\\\;\\n }\\n }\\n }\\n \\n System.out.println(result);\\n }\\n}\\n", "tests": "\\ntestMain(11, 23, -7, 0, 99, 5, 42);\\ntestMain(2, 4, 6, 3, 6);\\ntestMain(-3, -2, -1, -0, \\"+3\\", \\"+2\\", \\"+1\\", \\"+0\\");\\ntestMain(2, 3, -3, -2);\\ntestMain(126);\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(36, '[email protected]', 'java/04-stdin/Means', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>Means</code> that takes a command-line input\\n<code>N</code> and then reads in <code>N</code> double values from\\nstandard input. It should print out several means (averages) of the numbers,\\nwhich we \\ndefine below; let <i>x</i><sub>1</sub>, <i>x</i><sub>2</sub>,\\n… <i>x</i><sub>N</sub> denote the numbers. \\n<ul>\\n<li>the arithmetic mean is (<i>x</i><sub>1</sub> + <i>x</i><sub>2</sub> + … + <i>x</i><sub>N</sub>)/N </li>\\n<li>the geometric mean is (<i>x</i><sub>1</sub> × <i>x</i><sub>2</sub> × … × <i>x</i><sub>N</sub>)<sup>1/N</sup> </li>\\n<li>the harmonic mean is N/(1/<i>x</i><sub>1</sub> + 1/<i>x</i><sub>2</sub> + … + 1/<i>x</i><sub>N</sub>)</li>\\n</ul> \\nPrint all three of these means out.\\nIn order that the means are well-defined, you may assume the inputs\\nare positive. We will provide the output format for you to round to three decimal places. For example, <code>java Means 5</code> with standard input\\n<pre>1.0 2.0 3.0 4.0 5.0</pre> should output\\n<pre>\\nArithmetic mean: 3.000\\nGeometric mean: 2.605\\nHarmonic mean: 2.190\\n</pre>", "source_code": "\\npublic static void main(String[] args) {\\n\\\\[\\n int N = Integer.parseInt(args[0]);\\n double sum = 0; // running sum\\n double prod = 1; // running product\\n double recipsum = 0; // running sum of reciprocals\\n\\n for (int i=0; i<N; i++) {\\n double val = StdIn.readDouble();\\n sum += val;\\n prod *= val;\\n recipsum += 1/val;\\n }\\n]\\\\\\n double arithmetic = \\\\[sum/N]\\\\;\\n double geometric = \\\\[Math.pow(prod, 1.0/N)]\\\\;\\n double harmonic = \\\\[N/recipsum]\\\\;\\n\\n StdOut.printf(\\"Arithmetic mean: %.3f\\\\n\\", arithmetic);\\n StdOut.printf(\\"Geometric mean: %.3f\\\\n\\", geometric);\\n StdOut.printf(\\"Harmonic mean: %.3f\\\\n\\", harmonic);\\n}", "tests": "\\nstdin = \\"1.0 2.0 3.0 4.0 5.0\\";\\ntestMain(5);\\nstdin = \\"4 8 15 16 23 42\\\\nThese are the numbers from LOST\\\\n(Your program should not read this, only the N numbers.)\\"; \\ntestMain(6);\\nstdin = \\"126 126 126\\";\\ntestMain(3);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(37, '[email protected]', 'java/04-stdin/Powers', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>Powers</code> that takes in two numbers from standard input:\\na double <code>k</code> and an integer <code>N</code>. It should print out the\\nfirst <code>N</code> powers of <code>k</code> (using the format given in the template).\\nFor example running with standard input <code>2.0 5</code> should output\\n<pre>\\n2.0000\\n4.0000\\n8.0000\\n16.000\\n32.000\\n</pre>\\n", "source_code": "\\npublic static void main(String[] args) {\\n\\\\[\\n double k = StdIn.readDouble();\\n int N = StdIn.readInt();\\n]\\\\\\n for (\\\\[int i=1; i<=N; i++]\\\\) {\\n\\\\[\\n double power = Math.pow(k, i); // not very efficient :(\\n]\\\\\\n // you must define a variable called power somewhere\\n StdOut.printf(\\"%.5g\\\\n\\", power); // print to 5 decimal places\\n }\\n}", "tests": "\\nstdin = \\"2.0 8\\";\\ntestMain();\\nstdin = \\"1.1 3\\";\\ntestMain();\\nstdin = \\"-1 4\\";\\ntestMain();\\nstdin = \\"126 10\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(38, '[email protected]', 'java/04-stdin/Squish', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>Squish</code> that reads in a sequence of integers \\nfrom standard input and prints out the integers, but \\nremoving repeated values that appear consecutively. For example, if the input is\\n<pre>1 2 2 1 5 1 1 7 7 7 7 1 1 1 1 1 1 1 1 1</pre>your program should print out \\n<pre>1 2 1 5 1 7 1</pre>\\nFor simplicity, don''t add a space or newline at the end. You may assume there is at least one input.", "source_code": "\\npublic static void main(String[] args) {\\n\\\\[\\n int val = StdIn.readInt();\\n StdOut.print(val);\\n while (!StdIn.isEmpty()) {\\n int next = StdIn.readInt();\\n if (val != next) {\\n val = next;\\n System.out.print(\\" \\"+val);\\n }\\n }\\n]\\\\\\n}\\n", "tests": "\\nstdin = \\"3 4 4 5 6 7 7 8 3 4 5 6 5 5 5 5 5 3\\";\\ntestMain();\\nstdin = \\"1 2 2 1 5 1 1 7 7 7 7 1 1 1 1 1 1 1 1 1\\";\\ntestMain();\\nstdin = \\"3\\";\\ntestMain();\\nstdin = \\"3 3 3 3 3\\";\\ntestMain();\\nstdin = \\"1 1 2 5 8 13 21 0 -0 -5\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(39, '[email protected]', 'java/04-stdin/MaxMin', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>MaxMin</code> that reads in an arbitrary\\nnumber of integers from standard input, and prints out the\\nminimum and maximum values", "source_code": "\\npublic class MaxMin {\\n public static void main(String[] args) {\\n \\n // first value read initializes min and max\\n int max =\\\\[ StdIn.readInt() ]\\\\;\\n int min =\\\\[ max ]\\\\;\\n \\n // read in the data, keep track of min and max\\n while (\\\\[!StdIn.isEmpty()]\\\\) {\\n int value = StdIn.readInt();\\n\\\\[\\n min = Math.min(min, value);\\n max = Math.max(max, value);\\n]\\\\\\n }\\n \\n // output\\n StdOut.println(\\"max = \\" + max + \\" min = \\" + min);\\n }\\n}", "tests": "\\nstdin = \\"23 45 17 56 32\\\\n89 10 53 32 34\\\\n16\\";\\ntestMain();\\nstdin = \\"1 2 3 4 5\\";\\ntestMain();\\nstdin = \\"-1 -2 -3 -4 -5\\";\\ntestMain();\\nstdin = \\"126\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(40, '[email protected]', 'java/13-linkedlists/Quote', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>Web exercise 4.3.1</i> Create a null-terminated linked list that\\nrepresents a series of cards, each with a word on it. It will have\\nthe following API:\\n<pre>\\npublic Quote() // constructor - create an empty quote\\npublic void addWord(String w) // add the word w to the end of the quote\\npublic int count() // number of words in the quote\\npublic String getWord(int k) // return kth word (k = 1 is first word in quote)\\npublic void insertWord(int k, String w) // insert w after the kth word\\npublic String toString() // string representation of the quote\\n</pre>\\n", "source_code": "\\npublic class Quote {\\n\\n // helper linked-list data type, contains a word and reference to next card\\n private class Card {\\n private String word;\\n private Card next;\\n\\n // create a new Card containing this word\\n private Card(String word) {\\n this.word = word;\\n this.next = null;\\n }\\n }\\n \\n // the first card in null-terminated linked list\\n private Card start;\\n\\n // constructor - create an empty quote\\n public Quote() {\\n start = null;\\n }\\n \\n // add the word w to the end of the quote\\n public void addWord(String w) {\\n Card newCard = new Card(w);\\n\\n // special case when w is first word\\n if (start == null)\\n start = newCard;\\n \\n // otherwise, traverse list until card points to last word\\n else {\\n Card card = start; \\n while (card.next != null) {\\n card = \\\\[card.next;]\\\\\\n }\\n\\n // add card for new word to end of list\\n \\\\[card.next]\\\\ = newCard;\\n } \\n }\\n \\n // number of words in the quote\\n public int count() {\\n int total = 0;\\n for (Card card = start; \\\\[card != null]\\\\; \\\\[card = card.next]\\\\)\\n total++;\\n return total;\\n }\\n\\n // return the kth word where k = 1 is first word in quote\\n public String getWord(int k) {\\n // check for less than k words in quote or invalid index\\n if (count() < k || k <= 0) {\\n throw new RuntimeException(\\"index out of bounds\\");\\n }\\n \\n Card card = start;\\n for (int count = 1; \\\\[count < k]\\\\; \\\\[count++]\\\\)\\n card = card.next;\\n return \\\\[card.word;]\\\\\\n }\\n\\n // insert w after the kth word, where k = 1 is the first word \\n public void insertWord(int k, String w) {\\n // check for less than k words in quote or invalid index\\n if (count() < k || k <= 0) \\n throw new RuntimeException(\\"index out of bounds\\");\\n\\n // make Card for the new word, place it after the kth card\\n Card newCard = \\\\[new Card(w)]\\\\;\\n Card card = start;\\n for (int i = 1; i < k; i++) {card = card.next; }\\n \\\\[newCard.next = card.next;]\\\\\\n \\\\[card.next = newCard;]\\\\\\n }\\n\\n // string representation of the quote \\n public String toString(){\\n String s = \\"\\";\\n for (Card card = start; card != null; card = card.next)\\n s = s + card.word + \\" \\";\\n return s;\\n }\\n\\n public static void main(String[] args) { \\n Quote q = new Quote();\\n q.addWord(\\"A\\");\\n q.addWord(\\"rose\\");\\n q.addWord(\\"is\\");\\n q.addWord(\\"a\\");\\n q.addWord(\\"rose.\\");\\n StdOut.println(q);\\n StdOut.println(q.count());\\n StdOut.println(q.getWord(2));\\n q.insertWord(3, \\"just\\");\\n StdOut.println(q);\\n StdOut.println(q.count());\\n }\\n}\\n", "tests": "\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(41, '[email protected]', 'java/13-linkedlists/MonkeyAddStart', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nCreate a method <tt>addStart(String newName)</tt> \\nthat adds a new Node, containing this name, \\nat the start of the list.\\n", "classname": "MonkeyChain", "source_code": "\\n// structure of items in list\\nprivate class Node {\\n // each node knows \\"next\\" node\\n Node next;\\n // and stores a value\\n String name;\\n // constructor for nodes\\n Node(String initialName) {\\n name = initialName;\\n }\\n}\\n\\n// beginning of the list, initially empty\\nprivate Node first = null;\\n\\n// a demo to create a length-3 list\\npublic void threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first.next = new Node(\\"DK\\");\\n first.next.next = new Node(\\"DK Jr.\\");\\n}\\n\\n// a working copy of this method from MonkeyTraverse will be included\\n// it prints all Strings in the linked list, from first to last\\npublic void printAll() // ... method body not shown\\n\\\\hide[\\n{\\n Node current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != null) {\\n // println current node''s name; then repeat loop w/next one\\n System.out.println(current.name);\\n current = current.next;\\n }\\n}\\n]\\\\\\n\\n// add a new node, containing this name, at the start of the list\\npublic void addStart(String newName) {\\n Node newFirst = new Node(newName);\\n\\\\[\\n Node oldFirst = first;\\n first = newFirst;\\n first.next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n]\\\\\\n}\\n", "tests": "\\nsaveAs = \\"mc\\";\\ntestConstructor();\\ntestOn(\\"mc\\", \\"threeKongs\\");\\ntestOn(\\"mc\\", \\"addStart\\", \\"King Kong\\");\\ntestOn(\\"mc\\", \\"printAll\\");\\ntestOn(\\"mc\\", \\"addStart\\", \\"Koko\\");\\ntestOn(\\"mc\\", \\"printAll\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(42, '[email protected]', 'java/13-linkedlists/MonkeyAddEnd', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nCreate a method <tt>addEnd(String newName)</tt> \\nthat adds a new Node, containing this name, \\nat the <b>end</b> of the list.\\n", "classname": "MonkeyChain", "source_code": "\\n// structure of items in list\\nprivate class Node {\\n // each node knows \\"next\\" node\\n Node next;\\n // and stores a value\\n String name;\\n // constructor for nodes\\n Node(String initialName) {\\n name = initialName;\\n }\\n}\\n\\n// beginning of the list, initially empty\\nprivate Node first = null;\\n\\n// a demo to create a length-3 list\\npublic void threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first.next = new Node(\\"DK\\");\\n first.next.next = new Node(\\"DK Jr.\\");\\n}\\n\\n// a working copy of this method from MonkeyTraverse will be included\\n// it prints all Strings in the linked list, from first to last\\npublic void printAll() // ... method body not shown\\n\\\\hide[\\n{\\n Node current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != null) {\\n // println current node''s name; then repeat loop w/next one\\n System.out.println(current.name);\\n current = current.next;\\n }\\n}\\n]\\\\\\n\\n// add a new node, containing this name, at the end of the list\\npublic void addEnd(String newName) {\\n Node newLast = new Node(newName);\\n\\n // loop like printAll(), but stop *just before* the end.\\n // then, add the new node\\n\\\\[\\n if (first == null) {\\n first = newLast;\\n }\\n else {\\n Node current = first;\\n while (current.next != null) {\\n current = current.next;\\n }\\n current.next = newLast;\\n }\\n]\\\\\\n}\\n \\npublic static void main(String[] args) {\\n MonkeyChain mc = new MonkeyChain();\\n mc.threeKongs();\\n mc.addEnd(\\"Bubbles\\");\\n mc.printAll();\\n}\\n", "tests": "\\ntestMain();\\nsaveAs = \\"mc\\";\\ntestConstructor();\\nremark(\\"Checking if special case of adding to empty list is handled correctly…\\");\\ntestOn(\\"mc\\", \\"addEnd\\", \\"Curious George\\");\\ntestOn(\\"mc\\", \\"addEnd\\", \\"Bubbles\\");\\ntestOn(\\"mc\\", \\"printAll\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(43, '[email protected]', 'java/13-linkedlists/MonkeyTraverse', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing a <tt>while</tt> loop, create a method <tt>printAll()</tt> that prints all names in the linked list, \\nstarting with the first one. It should print each name on a separate line.\\n", "classname": "MonkeyChain", "source_code": "\\npublic class MonkeyChain {\\n // structure of items in list\\n private class Node {\\n // each node knows \\"next\\" node\\n Node next;\\n // and stores a value\\n String name;\\n // constructor for nodes\\n Node(String initialName) {\\n name = initialName;\\n }\\n }\\n \\n // beginning of the list, initially empty\\n private Node first = null;\\n \\n // a demo to create a length-3 list\\n public void threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first.next = new Node(\\"DK\\");\\n first.next.next = new Node(\\"DK Jr.\\");\\n }\\n\\n public void printAll() {\\n // one possible approach: use a while loop\\n Node current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (\\\\[current != null]\\\\) {\\n // println current node''s name; then repeat loop w/next one\\n\\\\[\\n System.out.println(current.name);\\n current = current.next;\\n]\\\\\\n }\\n }\\n\\n public static void main(String[] args) {\\n MonkeyChain mc = new MonkeyChain();\\n mc.threeKongs();\\n mc.printAll();\\n }\\n}\\n", "tests": "\\n//testMain();\\n\\nsaveAs = \\"mc\\";\\ntestConstructor();\\n\\ntestOn(\\"mc\\", \\"threeKongs\\");\\ntestOn(\\"mc\\", \\"printAll\\");\\n\\nquietOnPass = true;\\ntitle = \\"Calling <tt>mc.printAll()</tt> <b>again</b> to see if list was destroyed.\\";\\ntestOn(\\"mc\\", \\"printAll\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(44, '[email protected]', 'java/13-linkedlists/LinkIt', '{"sharing": "open", "attempts_until_ref": "1", "description": "<i>(Booksite 4.3)</i>\\nThe class <tt>LinkIt</tt> is a basic example of a linked list that contains <tt>String</tt> items,\\nincluding a <tt>toString()</tt> method that is already complete.\\nWe have left two methods blank for you to fill in.\\n<ul>\\n<li>The method <tt>reverse()</tt> should reverse \\nthe items of the list. \\nFor example, if the list currently contains the 4 items \\"is\\", \\"this\\", \\"code\\", \\"working\\", \\"well?\\" then\\n<tt>reverse()</tt> should alter the list to \\"well?\\", \\"working\\", \\"code\\", \\"this\\", \\"is\\".\\nYou should change the links (<tt>next</tt> variables) but avoid changing the <tt>value</tt> variables\\n(it makes coding it harder).\\nFor maximum challenge, don''t use <tt>new Node()</tt> in this method.\\n</li>\\n<li>The method <tt>deleteKth(int k)</tt> should delete\\nthe kth item from the list, where the first is k=1. Your code should throw a <tt>RuntimeException</tt>\\nif k is invalid. \\nFor example, if the list currently contains the 4 items \\"link\\", \\"think\\", \\"sink\\", \\"wink\\", then\\n<tt>deleteKth(2)</tt> should alter the list to \\"link\\", \\"think\\", \\"wink\\".\\n</li>\\n</ul>\\nSee the test main for more examples.\\n", "source_code": "\\n// helper class\\nprivate class Node {\\n private String value; // value in this item\\n private Node next; // reference to next item\\n private Node(String v, Node n) { // constructor\\n value = v;\\n next = n;\\n }\\n}\\n\\nprivate Node first; // reference to first item\\n\\n// construct a new empty list\\npublic LinkIt() {\\n first = null;\\n}\\n\\n// insert new string at start\\npublic void insertFirst(String s) {\\n first = new Node(s, first);\\n}\\n\\n// convert to string, separated by spaces\\npublic String toString() {\\n StringBuilder sb = new StringBuilder();\\n Node curr = first;\\n while (curr != null) {\\n sb.append(curr.value + \\" \\");\\n curr = curr.next;\\n }\\n return sb.toString();\\n}\\n\\n// reverse the items in the list\\npublic void reverse() {\\n\\\\[\\n Node prev = null;\\n Node curr = first;\\n while (curr != null) {\\n Node newcurr = curr.next;\\n curr.next = prev;\\n prev = curr;\\n curr = newcurr; \\n }\\n first = prev;\\n]\\\\\\n}\\n\\n// delete the kth item from the list, where the first is k=1\\n// throw RuntimeException if list is empty or index is invalid (k < 1)\\npublic void deleteKth(int k) {\\n // deleting from an empty list or from index less than 1 never makes sense\\n if (\\\\[first == null || k < 1]\\\\)\\n throw new RuntimeException(\\"Invalid index!\\");\\n \\n // now delete the item, and throw an exception if the item doesn''t exist\\n\\\\[\\n if (k == 1) {\\n // this is the only case where first changes\\n first = first.next;\\n }\\n else {\\n Node curr = first;\\n // access the (k-1)st node\\n for (int i=1; i<k-1; i++) {\\n if (curr == null)\\n throw new RuntimeException(\\"Invalid index!\\");\\n curr = curr.next;\\n }\\n // link (k-1)st to (k+1)st\\n if (curr == null || curr.next == null)\\n throw new RuntimeException(\\"Invalid index!\\");\\n curr.next = curr.next.next;\\n }\\n]\\\\\\n}\\n\\n// helper method for testing\\n// values[0] in first node, then values[1], etc\\npublic static LinkIt fromStrings(String[] values) {\\n LinkIt result = new LinkIt();\\n for (int i=values.length-1; i>=0; i--)\\n result.insertFirst(values[i]);\\n return result;\\n}\\n\\npublic static void main(String[] args) {\\n String[] testWords1 = {\\"is\\", \\"this\\", \\"code\\", \\"working\\", \\"well?\\"};\\n LinkIt test1 = fromStrings(testWords1);\\n test1.reverse();\\n StdOut.println(test1); // should be: well? working code this is\\n test1.reverse();\\n StdOut.println(test1); // should be: is this code working well?\\n\\n LinkIt test2 = fromStrings(new String[]{\\"mull\\", \\"over\\", \\"null\\", \\"well\\"});\\n test2.deleteKth(3);\\n StdOut.println(test2); // should be: mull over well\\n test2.deleteKth(1);\\n StdOut.println(test2); // should be: over well\\n test2.deleteKth(2);\\n StdOut.println(test2); // should be: over\\n}\\n", "tests": "\\ntestMain();\\nsaveAs = \\"linkit\\";\\ntest(\\"fromStrings\\", (Object)new String[]{\\"sesquipedalian\\"});\\ntestOn(\\"linkit\\", \\"reverse\\");\\ntestOn(\\"linkit\\", \\"toString\\");\\nsaveAs = \\"linkit\\";\\ntestConstructor();\\ntestOn(\\"linkit\\", \\"reverse\\");\\ntestOn(\\"linkit\\", \\"toString\\");\\nsaveAs = \\"linkit\\";\\ntest(\\"fromStrings\\", (Object)(\\"this sentence has five words\\".split(\\" \\")));\\nexpectException = true;\\ntestOn(\\"linkit\\", \\"deleteKth\\", 0);\\nsaveAs = \\"linkit\\";\\ntest(\\"fromStrings\\", (Object)(\\"this sentence has five words\\".split(\\" \\")));\\nexpectException = true;\\ntestOn(\\"linkit\\", \\"deleteKth\\", 6);\\nsaveAs = \\"linkit\\";\\ntest(\\"fromStrings\\", (Object)(\\"this sentence has five words\\".split(\\" \\")));\\ntestOn(\\"linkit\\", \\"deleteKth\\", 4);\\ntestOn(\\"linkit\\", \\"toString\\");\\ntestOn(\\"linkit\\", \\"deleteKth\\", 2);\\ntestOn(\\"linkit\\", \\"toString\\");\\ntestOn(\\"linkit\\", \\"deleteKth\\", 2);\\ntestOn(\\"linkit\\", \\"toString\\");\\ntestOn(\\"linkit\\", \\"deleteKth\\", 1);\\ntestOn(\\"linkit\\", \\"toString\\");\\ntestOn(\\"linkit\\", \\"deleteKth\\", 1);\\ntestOn(\\"linkit\\", \\"toString\\");\\nexpectException = true;\\ntestOn(\\"linkit\\", \\"deleteKth\\", 1);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(45, '[email protected]', 'java/13-linkedlists/CircularQuote', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>Booksite web exercise 4.3.2</i> Write a class <tt>CircularQuote</tt> that mimics \\nthe <tt>Quote</tt> class, but uses a circularly-linked list instead\\nof a null-terminated linked list. Its API will be:\\n<pre>\\npublic CircularQuote() // constructor - create an empty quote\\npublic void addWord(String w) // add the word w to the end of the quote\\npublic String toString() // string representation of the quote\\npublic int count() // number of words in the quote\\npublic String circularGetKth(int k) // the kth word in the quote (k=1 is first\\n // word. loops around if needed)\\n</pre>\\nThis exercise will give you practice with <tt>do {} while ()</tt> loops.\\nOne such example loop, in the <tt>toString()</tt> method, is already completed for you.\\nUse it again in the constructor and in <tt>count()</tt>.\\n", "source_code": "\\npublic class CircularQuote {\\n\\n // the first card in the circular linked list\\n private Card start;\\n\\n // helper linked-list data type\\n private class Card {\\n private String word;\\n private Card next;\\n\\n private Card(String word) {\\n this.word = word;\\n this.next = null;\\n }\\n }\\n \\n // constructor - create an empty quote\\n public CircularQuote() {\\n \\\\[ start = null; ]\\\\ // no card intitially\\n }\\n \\n // add the word w to the end of the quote\\n public void addWord(String w) {\\n Card newCard = \\\\[new Card(w);]\\\\\\n\\n // degenerate case for empty quote, w is the first word\\n if (\\\\[start == null]\\\\) {\\n \\\\[start = newCard;]\\\\ // save the card with the new word\\n start.next = start; // make it circular\\n } \\n\\n // otherwise, traverse list until card points to last word\\n else {\\n // find the current last word\\n Card card = start;\\n do {\\n \\\\[card = card.next;]\\\\\\n } while (\\\\[card.next != start]\\\\);\\n\\n // insert new word\\n\\\\[\\n newCard.next = start;\\n card.next = newCard;\\n]\\\\\\n } \\n }\\n \\n // string representation of the entire quote\\n public String toString(){\\n String result = \\"\\";\\n if (start == null) // special case\\n return result;\\n\\n Card card = start;\\n do {\\n result = result + card.word + \\" \\"; // build string\\n card = card.next; // traverse list\\n } while (card != start);\\n return result;\\n\\n // note! using a plain while loop would normally require separate\\n // logic for the 1-node and the (>1)-node case\\n }\\n\\n // number of words in the quote\\n public int count() {\\n\\\\[\\n // empty quote\\n if (start == null) return 0;\\n\\n Card card = start;\\n int total = 0;\\n do {\\n total++;\\n card = card.next;\\n } while (card != start);\\n return total;\\n]\\\\\\n }\\n\\n // the kth word in the quote (where k = 1 is the first word)\\n public String circularGetKth(int k) {\\n Card card = start;\\n for (int j = 1; j < k; j++) {\\n card = card.next;\\n }\\n return card.word;\\n }\\n\\n // test client\\n public static void main(String[] args) { \\n CircularQuote q = new CircularQuote();\\n StdOut.println(q.count() + \\": \\" + q);\\n\\n q.addWord(\\"A\\");\\n StdOut.println(q.count() + \\": \\" + q);\\n\\n q.addWord(\\"rose\\");\\n StdOut.println(q.count() + \\": \\" + q);\\n StdOut.println(\\"Second word: \\" + q.circularGetKth(2)); // rose\\n\\n q.addWord(\\"is\\");\\n StdOut.println(q.count() + \\": \\" + q);\\n StdOut.println(\\"Tenth word: \\" + q.circularGetKth(10)); // A\\n\\n q.addWord(\\"a\\");\\n StdOut.println(q.count() + \\": \\" + q);\\n StdOut.println(\\"Seventh word: \\" + q.circularGetKth(7)); // is\\n\\n q.addWord(\\"rose.\\");\\n StdOut.println(q.count() + \\": \\" + q);\\n StdOut.println(\\"First word: \\" + q.circularGetKth(1)); // A\\n }\\n}\\n", "tests": "\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(46, '[email protected]', 'java/09-binarysearch/Lambert', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>Lambert''s W function</i> is a mathematical function\\nwith a <a href=\\"https://cs.uwaterloo.ca/research/tr/1993/03/W.pdf\\">diverse\\nrange of applications in math and science</a>. It is an inverse function\\nto $x = w \\\\times \\\\mathrm{e}^w$. In other words, for a given $x$, the value\\nof the Lambert function $W(x)$ is defined as the real number satisfying\\n$$x = W(x) \\\\times \\\\mathrm{e}^{W(x)}.$$\\n\\n<p>\\nFor example, <i>W</i>(126) is approximately 3.5651 since 126 = 3.5651 × e<sup>3.5651</sup>.\\n\\n<p>\\nUse binary search to define a static method <tt>W(double x)</tt> that \\nevaluates the Lambert function at <i>x</i>. You may assume $x \\\\ge 0$. \\nTo help get the binary search\\nstarted, you may use the fact that $0 \\\\le W(x) \\\\le \\\\max(1, \\\\ln(x))$.\\nTerminate the binary search when \\nthe search endpoints differ by 10<sup>-8</sup> or less.\\n\\n<p>\\n<i>Hint</i>: you will need <a href=\\"http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#exp-double-\\">several</a>\\n<a href=\\"http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#log-double-\\">methods</a>\\nfrom the <tt>Math</tt> library.\\n", "source_code": "\\n\\n// evaluate Lambert''s W function at x. Assumes x >= 0.\\npublic static double W(double x) {\\n // we know that W(x) >= 0 and W(x) <= max(1, ln(x))\\n double lo = 0;\\n \\\\[double hi = Math.max(1, Math.log(x));]\\\\\\n\\n // continue until search endpoints differ by 1E-8 or less\\n while (\\\\[hi - lo >= 1E-8]\\\\) {\\n // evaluate midpoint times e^midpoint\\n\\\\[\\n double mid = (lo + hi) / 2;\\n double midval = mid * Math.exp(mid);\\n]\\\\\\n\\n // if this value is smaller than x, search above, else search below\\n\\\\[\\n if (midval < x)\\n lo = mid;\\n else\\n hi = mid;\\n]\\\\\\n }\\n return lo; // return some point in final range\\n}\\n\\npublic static void main(String[] args) {\\n double x = Double.parseDouble(args[0]);\\n StdOut.println(W(x));\\n}\\n", "tests": "\\ntestMain(126);\\ntestMain(2.718281828459045);\\ntestMain(23423.348);\\ntestMain(\\"1E25\\");\\ntestMain(\\"1E-5\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(47, '[email protected]', 'java/12-structures/QMerge', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite code to sort a list of integers using merge sort. You will use the <tt>Queue<Integer></tt> parameterized generic type. \\n<ol>\\n<li>\\nCreate a static method <tt>Queue<Integer> merge(Queue<Integer> a, Queue<Integer> b)</tt> which, assuming\\n <tt>a</tt> and <tt>b</tt> are both queues sorted in increasing order, returns a new queue\\nconsisting of all their elements combined, sorted in increasing order. E.g., if <tt>a</tt> is a queue into which\\n1 and 6 have been enqueued, and <tt>b</tt> is a queue into which 2 and 9 have been enqueued, then the returned\\nqueue should contain 1 first, then 2, 6, 9. \\n</li>\\n<li>\\nThen, create a static method <tt>Queue<Integer> mergeSort(Queue<Integer> input)</tt> to implement merge sort.\\nIt should use <tt>size()</tt> from the <tt>Queue</tt> API to break the queue arbitrarily into two \\n(non-ordered) queues each about half as big as the original. Then sort both halves recusrively, and merge them.\\n</li>\\n</ol>\\nYou may find the <a href=\\"http://algs4.cs.princeton.edu/code/javadoc/Queue.html\\">Queue API</a> helpful!\\n", "source_code": "\\n// ASSUMING a and b are sorted in increasing order, return a new queue\\n// consisting of the elements of both in combined increasing order\\npublic static Queue<Integer> merge(Queue<Integer> a, Queue<Integer> b) {\\n Queue<Integer> result = new Queue<Integer>();\\n\\n // keep going as long as there are elements to merge\\n while (\\\\[!a.isEmpty() && !b.isEmpty()]\\\\) {\\n // take the smaller element from either a or b, move it to result\\n\\\\[\\n if (b.peek() < a.peek())\\n result.enqueue(b.dequeue());\\n else\\n result.enqueue(a.dequeue());\\n]\\\\\\n }\\n\\n // if anything is left over once one queue is empty, move it into result\\n\\\\[\\n while (!a.isEmpty())\\n result.enqueue(a.dequeue());\\n while (!b.isEmpty())\\n result.enqueue(b.dequeue());\\n]\\\\\\n return result;\\n}\\n\\n// return a new queue consisting of the same elements in sorted order\\npublic static Queue<Integer> mergeSort(Queue<Integer> input) {\\n if (input.size() == 1) { // base case\\n Queue<Integer> result = new Queue<Integer>();\\n\\\\[\\n result.enqueue(input.dequeue());\\n]\\\\\\n return result;\\n }\\n else {\\n // move half the elements into a new queue\\n\\\\[\\n int halfSize = input.size() / 2; \\n Queue<Integer> firstHalf = new Queue<Integer>();\\n for (int i=0; i<halfSize; i++) \\n firstHalf.enqueue(input.dequeue());\\n]\\\\\\n // sort both halves and merge\\n return \\\\[merge(mergeSort(firstHalf), mergeSort(input))]\\\\;\\n }\\n}\\n\\n// read all integers from input, sort them, and print them\\npublic static void main(String[] args) {\\n Queue<Integer> data = new Queue<Integer>();\\n while (!StdIn.isEmpty())\\n data.enqueue(StdIn.readInt());\\n Queue<Integer> sortedData = mergeSort(data);\\n while (!sortedData.isEmpty())\\n StdOut.println(sortedData.dequeue());\\n}\\n", "tests": "\\nsaveAs = \\"q1\\";\\nconstruct(\\"stdlibpack\\", \\"Queue\\", \\"<Integer>\\");\\ntestOn(\\"q1\\", \\"enqueue\\", 1);\\ntestOn(\\"q1\\", \\"enqueue\\", 6);\\nsaveAs = \\"q2\\";\\nconstruct(\\"stdlibpack\\", \\"Queue\\", \\"<Integer>\\");\\ntestOn(\\"q2\\", \\"enqueue\\", 2);\\ntestOn(\\"q2\\", \\"enqueue\\", 9);\\nsaveAs = \\"q\\";\\ntest(\\"merge\\", var(\\"q1\\"), var(\\"q2\\"));\\ntestOn(\\"q\\", \\"size\\");\\ntestOn(\\"q\\", \\"dequeue\\");\\ntestOn(\\"q\\", \\"dequeue\\");\\ntestOn(\\"q\\", \\"dequeue\\");\\ntestOn(\\"q\\", \\"dequeue\\");\\ntestOn(\\"q\\", \\"isEmpty\\");\\nstdin = \\"3 7 8 2 4 5 2 4 1\\";\\ntestMain();\\nstdin = \\"3 7 8 2 4 5 2 4 1\\";\\ntestMain();\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/websheets/data/100rand126.txt\\";\\ntestMain();\\nmaxOutputBytes = 100000;\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/websheets/data/10000rand.txt\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(48, '[email protected]', 'java/12-structures/CME', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nDefine a method <tt>addReverses(Set<String> words)</tt> that takes \\na set of strings, and adds to that set the reverse of every string in the set.\\nFor example, if you call it on a set containing <tt>\\"HI\\"</tt> and <tt>\\"MOM\\"</tt>\\nthen after your method executes, it should contain <tt>\\"HI\\"</tt>, <tt>\\"IH\\"</tt> and <tt>\\"MOM\\"</tt>\\n(only once, since that''s all a <tt>Set</tt> can contain).\\n<p>\\nA partial solution is given below, but it throws a <tt>ConcurrentModificationException</tt>. You have to fix it.\\n", "imports": "[\\"java.util.Set\\", \\"java.util.TreeSet\\"]", "source_code": "\\npublic class CME {\\n public static void addReverses(Set<String> words) {\\n\\\\[\\n // we will put the reverses in a new place for now\\n // while we iterate through the main set\\n java.util.HashSet<String> tmp = new java.util.HashSet<String>();\\n for (String s : words) \\n tmp.add(new StringBuffer(s).reverse().toString());\\n \\n // now that we''re done iterating through ''words'', add to it\\n for (String s : tmp) \\n words.add(s);\\n\\\\show:\\n for (String s : words) { // for each string in the set \\n\\n // a one-liner to compute the reverse of a string\\n String sReverse = new StringBuffer(s).reverse().toString();\\n\\n // add it to our set\\n words.add(sReverse);\\n }\\n]\\\\\\n }\\n\\n // test client: e.g. \\"java CME HI MOM\\" should print out on 3 lines HI IH MOM\\n public static void main(String[] args) {\\n Set<String> testSet = new TreeSet<String>();\\n for (int i=0; i < args.length; i++)\\n testSet.add(args[i]); \\n\\n addReverses(testSet);\\n\\n for (String s : testSet)\\n System.out.println(s);\\n }\\n}\\n", "tests": "\\ntestMain(\\"HI\\", \\"MOM\\");\\ntestMain(\\"MADAM\\", \\"IM\\", \\"ADAM\\");\\ntestMain(\\"NOW\\", \\"SIR\\", \\"A\\", \\"WAR\\", \\"IS\\", \\"WON\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(49, '[email protected]', 'java/12-structures/LineEdit', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nCreate a class <tt>LineEdit</tt> to implement a text editor — a very primitive text editor that can only hold one line of text, \\nand supports the following functions.\\n<pre>\\n// create a new LineEdit with given initial text\\n public LineEdit(String text)\\n// get the current state of the editor\\n public String toString()\\n// add the given text at the end of the line\\n public void append(String text) \\n// replace all occurrences of \\"from\\" with \\"to\\"\\n public void replaceEach(String from, String to)\\n// undo the latest append/replaceEach operation that hasn''t already been undone\\n public void undo()\\n</pre>\\nFor example,\\n<pre>\\nLineEdit line = new LineEdit(\\"datatype\\"); // line.toString() is now \\"datatype\\"\\nline.replaceEach(\\"t\\", \\"\\"); // line.toString() is now \\"daaype\\"\\nline.append(\\"st\\"); // line.toString() is now \\"daaypest\\"\\nline.undo(); // line.toString() is now \\"daaype\\"\\n</pre>\\nThe main purpose of this exercise is to gain familiarity with stacks —\\nuse <tt>Stack<String></tt> to implement the history of changes and to\\nimplement the <tt>undo()</tt> functionality. If the client\\n calls <tt>undo()</tt> and everything has already been undone, then \\n<tt>undo()</tt> should just return without changing the state.\\nUse <tt><a href=\\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace(java.lang.CharSequence, java.lang.CharSequence)\\">String.replace</a></tt> to perform the changes required by the <tt>replaceEach</tt> instance method.\\n", "source_code": "\\n// instance variables\\n\\\\[\\nString state; // current state\\nStack<String> oldStates = new Stack<String>(); // previous states for undo\\n]\\\\\\n\\n// create a new LineEdit with given initial text\\npublic LineEdit(String text) {\\n\\\\[\\n state = text;\\n]\\\\\\n}\\n\\n// get the current state of the editor\\npublic String toString() {\\n\\\\[\\n return state;\\n]\\\\\\n}\\n\\n// add the given text at the end of the line\\npublic void append(String text) {\\n\\\\[\\n oldStates.push(state);\\n state = state + text;\\n]\\\\\\n}\\n\\n// replace all occurrences of \\"from\\" with \\"to\\"\\npublic void replaceEach(String from, String to) {\\n\\\\[\\n oldStates.push(state);\\n state = state.replace(from, to);\\n]\\\\\\n}\\n\\n// undo the latest append/replaceEach operation that hasn''t already been undone\\npublic void undo() {\\n\\\\[\\n if (!oldStates.isEmpty()) // avoid crashing when there''s nothing to undo\\n state = oldStates.pop();\\n]\\\\\\n}\\n\\n// test client\\npublic static void main(String[] args) {\\n LineEdit line = new LineEdit(\\"datatype\\");\\n System.out.println(line.toString());\\n line.replaceEach(\\"t\\", \\"\\");\\n System.out.println(line.toString());\\n line.append(\\"st\\");\\n System.out.println(line.toString());\\n line.undo();\\n System.out.println(line.toString());\\n}\\n", "tests": "\\ntestMain();\\nsaveAs = \\"word\\";\\ntestConstructor(\\"COS 226\\");\\ntestOn(\\"word\\", \\"toString\\");\\ntestOn(\\"word\\", \\"replaceEach\\", \\"22\\", \\"12\\");\\ntestOn(\\"word\\", \\"toString\\");\\ntestOn(\\"word\\", \\"replaceEach\\", \\"wierd\\", \\"weird\\");\\ntestOn(\\"word\\", \\"toString\\");\\ntestOn(\\"word\\", \\"append\\", \\" is the best\\");\\ntestOn(\\"word\\", \\"toString\\");\\ntestOn(\\"word\\", \\"undo\\");\\ntestOn(\\"word\\", \\"toString\\");\\ntestOn(\\"word\\", \\"undo\\");\\ntestOn(\\"word\\", \\"toString\\");\\nsaveAs = \\"emacs\\";\\ntestConstructor(\\"your code shouldn''t crash even if there''s nothing to undo\\");\\ntestOn(\\"emacs\\", \\"toString\\");\\ntestOn(\\"emacs\\", \\"undo\\");\\ntestOn(\\"emacs\\", \\"toString\\");\\ntestOn(\\"word\\", \\"replaceEach\\", \\"O\\", \\"oh\\");\\ntestOn(\\"word\\", \\"toString\\"); \\ntestOn(\\"word\\", \\"undo\\");\\ntestOn(\\"word\\", \\"toString\\"); \\ntestOn(\\"word\\", \\"undo\\");\\ntestOn(\\"word\\", \\"toString\\"); \\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(50, '[email protected]', 'java/12-structures/ReverseLookup', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a static method <tt>invert</tt> that takes\\na <tt>ST<Integer, String></tt>, and returns a\\n<tt>ST<String, Integer></tt> where the keys and the values\\nare swapped. If the <tt>ST</tt> passed to <tt>invert</tt> has repeated\\nvalues, since it is not invertible, throw a <tt>RuntimeExeption</tt>.\\n", "source_code": "\\n\\\\[\\npublic static ST<String, Integer> invert(ST<Integer, String> st) {\\n ST<String, Integer> result = new ST<String, Integer>();\\n for (int i : st) {\\n String S = st.get(i);\\n if (result.get(S) != null)\\n throw new RuntimeException(\\"Not invertible!\\");\\n result.put(S, i);\\n }\\n return result;\\n}\\n]\\\\\\n// test client. Reads alternating strings and ints from stdin, loads them\\n// into an ST<Integer, String>, inverts it and prints the result\\npublic static void main(String[] args) {\\n ST<Integer, String> orig = new ST<Integer, String>();\\n while (!StdIn.isEmpty()) {\\n orig.put(StdIn.readInt(), StdIn.readString());\\n }\\n ST<String, Integer> inverted = invert(orig);\\n for (String s : inverted) {\\n StdOut.println(s+\\" \\"+inverted.get(s));\\n }\\n}\\n", "tests": "\\nstdin = \\"1 one\\\\n2 two\\\\n3 three\\";\\ntestMain();\\nstdin = \\"115 Time\\\\n538 Magnetism\\\\n577 Ecology\\\\n664 Food_technology\\";\\ntestMain();\\nexpectException = true;\\nstdin = \\"1 Uninvertible\\\\n2 Uninvertible\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(51, '[email protected]', 'java/12-structures/FrequencyTable', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nThe class <tt>FrequencyTable</tt> represents a table that tracks\\nthe number of repeated occurrences of items in a list of Strings. It has \\nthe API\\n<pre>\\npublic FrequencyTable() // new table\\npublic void click(String word) // add 1 to frequency of this word\\npublic int count(String word) // what is frequency of this word?\\npublic void show() // print out all words and frequencies\\n</pre>\\nFor example,\\n<pre>\\nFrequencyTable ft = new FrequencyTable();\\nft.click(\\"duck\\");\\nft.click(\\"duck\\");\\nft.click(\\"goose\\");\\nStdOut.println(ft.count(\\"duck\\")); // should print 2\\nStdOut.println(ft.count(\\"goose\\")); // should print 1\\nStdOut.println(ft.count(\\"horse\\")); // should print 0\\n</pre>\\nIn addition, create a <tt>main</tt> that takes no arguments, reads words\\nfrom standard input (using <tt>StdIn.readString()</tt>) until none are left,\\nand then prints out the frequencies of all words using <tt>show()</tt>.\\n<div class=\\"noprint\\">\\nYou will need to know the <a href=\\"http://introcs.cs.princeton.edu/java/44st/\\"><tt>ST</tt> API</a>: look up the constructor, <tt>put</tt> and <tt>get</tt>.\\n</div>\\n<div class=\\"printonly\\">\\nHere are the relevant components of the ST API:\\n<pre>public class ST<Key, Value> // Note: Key must be Comparable\\n------------------------------------------------------------------------\\nST<Key, Value>() // create a symbol table\\nvoid put(Key key, Value v) // put key-value pair into the table\\nValue get(Key key) // return value paired with key\\n // or null if no such value\\nboolean contains(key Key) // is there a value paired with key?\\n// Allows iteration with enhanced for loops:\\nfor (Key key : st) {...} // executes body once for each key\\n</pre>\\n</div>\\n", "source_code": "\\n // Dependencies: ST.java (available on precepts page), StdIn, StdOut\\n // maintain counts of all words seen so far\\n // the key is the word and the value is the count\\n private ST<\\\\[String, Integer]\\\\> st = \\\\[new ST<String, Integer>()]\\\\;\\n\\n // remark: we have not declared a constuctor! but Java lets every class \\n // have a no-argument constructor by default. It only runs the line of \\n // code above (instance variable initialization).\\n\\n // add 1 to the frequency of this word\\n public void click(String word) {\\n int count = count(word);\\n st.put(word, count + 1);\\n }\\n\\n // what is the frequency of this word?\\n public int count(String word) {\\n if (!st.\\\\[contains]\\\\(\\\\[word]\\\\)) return 0; // if word is not in ST\\n else return \\\\[st]\\\\.\\\\[get]\\\\(\\\\[word]\\\\); // get word''s count\\n }\\n\\n // print out all words and frequencies\\n public void show() {\\n // foreach loop. goes through all keys in alphabetical order\\n for (String word : st) {\\n // print out frequency and word, separated by a space\\n StdOut.println(\\\\[count]\\\\(\\\\[word]\\\\) + \\" \\" + \\\\[word]\\\\);\\n }\\n }\\n\\n // method used by client to count all words in StdIn\\n public static void main(String[] args) {\\n\\n // build frequency table from words on standard input\\n FrequencyTable freq = new FrequencyTable();\\n while (!StdIn.isEmpty()) {\\n String word = StdIn.readString();\\n freq.\\\\[click]\\\\(word);\\n }\\n\\n // print frequency table to standard output\\n freq.show();\\n }\\n", "tests": "\\nsaveAs = \\"ft\\";\\ntestConstructor();\\ntestOn(\\"ft\\", \\"click\\", \\"duck\\");\\ntestOn(\\"ft\\", \\"count\\", \\"duck\\");\\ntestOn(\\"ft\\", \\"click\\", \\"duck\\");\\ntestOn(\\"ft\\", \\"click\\", \\"goose\\");\\ntestOn(\\"ft\\", \\"count\\", \\"duck\\");\\ntestOn(\\"ft\\", \\"count\\", \\"goose\\");\\ntestOn(\\"ft\\", \\"count\\", \\"horse\\");\\nstdin = \\"in this test the api is tested by the words in the sentence\\";\\ntestMain();\\nmaxOutputBytes = 500000;\\nstdinURL = \\"http://introcs.cs.princeton.edu/java/44st/mobydick.txt\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(52, '[email protected]', 'java/10-objects/IsPalindrome', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n(Exercise 3.1.13)\\nA <i>palindrome</i> is a string that reads the same forwards or backwards,\\nlike <tt>\\"RADAR\\"</tt> or <tt>\\"STOOTS\\"</tt>.\\nDefine a method <tt>isPalindrome</tt> \\nthat takes as input a string and returns true if the \\nstring is a palindrome, and false otherwise. You will need to use\\nthe instance methods <tt>charAt()</tt> and <tt>length()</tt>\\nfrom the <a href=\\"http://introcs.cs.princeton.edu/java/11cheatsheet/#String\\">String API</a>.", "source_code": "\\npublic static boolean isPalindrome(String s) {\\n\\\\[\\n// it''s only necessary to do half the length many checks\\nfor (int i=0; i<s.length()/2; i++) {\\n // look at ith character from start and end\\n if (s.charAt(i) != s.charAt(s.length()-i-1))\\n return false;\\n}\\n\\nreturn true; // everything matched\\n]\\\\\\n}\\n", "tests": "\\ntest(\\"isPalindrome\\", \\"racecar\\");\\ntest(\\"isPalindrome\\", \\"ferrari\\");\\ntest(\\"isPalindrome\\", \\"foolproof\\");\\ntest(\\"isPalindrome\\", \\"cool\\");\\ntest(\\"isPalindrome\\", \\"rester\\");\\ntest(\\"isPalindrome\\", \\"redder\\");\\ntest(\\"isPalindrome\\", \\"pinker\\");\\ntest(\\"isPalindrome\\", \\"o\\");\\ntest(\\"isPalindrome\\", \\"ok\\");\\ntest(\\"isPalindrome\\", \\"kk\\");\\ntest(\\"isPalindrome\\", \\"joUO9G\\");\\ntest(\\"isPalindrome\\", \\"rt2$77$2tr\\");\\ntest(\\"isPalindrome\\", \\"Qay&2&yaQ\\");\\ntest(\\"isPalindrome\\", \\"\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(53, '[email protected]', 'java/10-objects/FourChargeClient', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nHere is an API (Application Programming Interface) for charged particles.\\n<pre>\\npublic class Charge\\n------------------------------------------------------------------------\\nCharge(double x0, double y0, double q0) // location and charge\\ndouble potentialAt(double x, double y) // potential at (x,y) due to charge\\nString toString() // string representation\\n</pre>\\n\\nWrite a program that takes a double value \\n<tt>r</tt> from the command line, creates four\\n<tt>Charge</tt> objects that are each distance \\n<tt>r</tt> from the center of the unit square (.5, .5), and\\nprints the potential at location (.25, .5) due \\nto the combined four charges. All four\\ncharges should have unit positive charge. See the illustration below.\\n\\n<div style=''text-align:center''><img src=''http://cscircles.cemc.uwaterloo.ca/websheets/images/FourChargeClient.ipe.png''></div>\\n\\n<p>For example, <tt>java FourChargeClient 0.1</tt>\\nshould print out\\n<pre>total potential:\\n1.5239509122751547E11\\n</pre>\\n", "source_code": "\\npublic class FourChargeClient {\\n public static void main(String[] args) {\\n double r = Double.parseDouble(args[0]);\\n\\n double cx = 0.5;\\n double cy = 0.5;\\n\\n // construct four charges\\n Charge c1 = new Charge(cx + r, cy, 1.0); // east\\n Charge c2 = \\\\[new Charge(cx, cy - r, 1.0)]\\\\; // south\\n Charge c3 = \\\\[new Charge(cx - r, cy, 1.0)]\\\\; // west\\n Charge c4 = \\\\[new Charge(cx, cy + r, 1.0)]\\\\; // north\\n\\n // Compute potentials at (.25, .5)\\n double px = 0.25;\\n double py = 0.5;\\n double v1 = c1.potentialAt(\\\\[px, py]\\\\);\\n double v2 = \\\\[c2.potentialAt(px, py)]\\\\;\\n double v3 = \\\\[c3.potentialAt(px, py)]\\\\;\\n double v4 = \\\\[c4.potentialAt(px, py)]\\\\;\\n\\n // compute and output total potential\\n double sum = \\\\[v1 + v2 + v3 + v4]\\\\;\\n System.out.println(\\"total potential:\\");\\n System.out.println(sum);\\n }\\n}\\n", "tests": "\\ntestMain(\\"0.1\\");\\ntestMain(\\"0.2\\");\\ntestMain(\\"1\\");\\ntestMain(\\"126\\");\\ntestMain(\\"0.25\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(54, '[email protected]', 'java/10-objects/GeneFind', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nSolve the following simplified version of\\nthe <i>gene finding problem</i>. You will be given a <tt>String dna</tt>\\nconsisiting of the capital letters <tt>A</tt>, <tt>C</tt>,\\n <tt>T</tt>, <tt>G</tt>. You need to determine if there is any subsequence\\nof the form\\n<pre>ATG...TAG</pre>\\nwhere the region <tt>...</tt> has a length that is a \\n<i>positive multiple\\nof three</i>. If such a region exists, return the <tt>...</tt> part (the gene).\\n\\nFor example, if <tt>dna</tt> is <tt>\\"CATTATGGTTCACTAGCC\\"</tt> then the\\ngene you should return is <tt>\\"GTTCAC\\"</tt>. Here are some additional rules\\nyour code must follow.\\n<ul>\\n<li>\\nThe gene part may contain <tt>ATG</tt>.\\n<li>\\nThe gene part must not contain <tt>TAG</tt> at any index that is a multiple\\nof three. But it can contain it at other positions. For example, <tt>\\"TATTAG\\"</tt> is not a possible gene, but <tt>\\"ATAGAC\\"</tt> is.\\n<li>\\nIf one or more multiple possible genes exist, return the one with\\nthe leftmost start position.\\n<li>\\nIf no possible genes exist, return the string <tt>\\"no gene\\"</tt>\\n</ul>\\n\\nWe recommend you use <a href=\\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String, int)\\"><tt>String.indexOf(String, int)</tt></a> to\\nsearch for substrings. This will simplify one of the tricky/repetitive parts of the\\ncode.\\n", "source_code": "\\npublic static String findGene(String dna) {\\n String START_CODON = \\"ATG\\";\\n String END_CODON = \\"TAG\\";\\n\\\\[\\n // what''s the rightmost position so far where we found a start codon?\\n int latestStartIndex = -1;\\n while (true) {\\n // find the next start codon\\n latestStartIndex = dna.indexOf(START_CODON, latestStartIndex+1);\\n\\n // -1 is used to indicate no match by String.indexOf()\\n if (latestStartIndex == -1)\\n return \\"no gene\\"; // we didn''t find a match\\n\\n // where is the next matching end?\\n int endIndex = dna.indexOf(END_CODON, latestStartIndex+6);\\n // keep going if length is not a multiple of 3\\n while ((endIndex != -1) && ((endIndex - latestStartIndex) % 3 != 0)) {\\n endIndex = dna.indexOf(END_CODON, endIndex+1);\\n }\\n \\n // we''re done if length is a multiple of 3\\n if ((endIndex != -1) && ((endIndex - latestStartIndex) % 3 == 0))\\n return dna.substring(latestStartIndex+3, endIndex);\\n }\\n]\\\\\\n}\\n", "tests": "\\ntest(\\"findGene\\", \\"CATTATGGTTCACTAGCC\\");\\ntest(\\"findGene\\", \\"ATGGTTCACTAG\\");\\ntest(\\"findGene\\", \\"AATGGTTCACTAGG\\");\\ntest(\\"findGene\\", \\"ATGATGGTTCACTAG\\");\\ntest(\\"findGene\\", \\"ATGGTTCACTAGTAG\\");\\ntest(\\"findGene\\", \\"CACACATGTTTTTAGTTTTTTAGCCCC\\");\\ntest(\\"findGene\\", \\"CACACATGTTTTTAGTTTTTAGCCCC\\");\\ntest(\\"findGene\\", \\"ATGTAG\\");\\ntest(\\"findGene\\", \\"ATGTAGATGTAG\\");\\ntest(\\"findGene\\", \\"GAGAATGCTAGCTAGCTAGGAGA\\");\\ntest(\\"findGene\\", \\"GAGAATGCATGCATGCATGCATGCTAGGAGA\\");\\ntest(\\"findGene\\", \\"ATGCATTACTAGCCCATGTACCATTAG\\");\\ntest(\\"findGene\\", \\"TACGTAGCTACGATCGTACGATGCTAGCTAGCTGCGTCAGCGTGTATAGTAGGCGCAGT\\");\\ntest(\\"findGene\\", \\"TACGTATGCTACGATCGTACGATGCTAGCTAGCTGCGTCAGCGTGTATAGTAGGCGCAGT\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(55, '[email protected]', 'java/10-objects/ComplementaryDNA', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a static method <tt>complementWC(String dna)</tt>\\nthat takes a String containing only the capital letters <tt>A</tt>, <tt>C</tt>,\\n <tt>T</tt>, <tt>G</tt>,\\n(representing DNA), and returns its <i>Watson-Crick complement</i>:\\nreplace <tt>A</tt> with <tt>T</tt>, <tt>C</tt> with <tt>G</tt>, and vice-versa.\\n\\n<p>For example, <tt>complementWC(\\"GATTACA\\")</tt> should return \\n<tt>\\"CTAATGT\\"</tt>. (You may assume the input is valid, there is no need\\nto check for non-DNA characters.)\\n\\n<p>\\nWe encourage you to \\nreview the <a href=\\"http://introcs.cs.princeton.edu/java/11cheatsheet/#String\\">\\nabbreviated String API</a> on the introcs cheatsheet. If you do this,\\nyou can solve this problem without using any loops.\\n\\n", "source_code": "\\npublic static String complementWC(String dna) {\\n // replace all ''C''s with ''G''s and vice-versa\\n\\\\[\\n String tmp = dna.replaceAll(\\"C\\", \\"X\\");\\n tmp = tmp.replaceAll(\\"G\\", \\"C\\");\\n tmp = tmp.replaceAll(\\"X\\", \\"G\\");\\n]\\\\\\n // replace all ''A''s with ''T''s and vice-versa\\n\\\\[\\n tmp = tmp.replaceAll(\\"A\\", \\"X\\");\\n tmp = tmp.replaceAll(\\"T\\", \\"A\\");\\n tmp = tmp.replaceAll(\\"X\\", \\"T\\");\\n]\\\\\\n return \\\\[tmp;]\\\\ \\n}", "tests": "\\ntest(\\"complementWC\\", \\"GATTACA\\");\\ntest(\\"complementWC\\", \\"CAT\\");\\ntest(\\"complementWC\\", \\"TAGACAT\\");\\ntest(\\"complementWC\\", \\"GCGAGTGAGC\\");\\ntest(\\"complementWC\\", \\"\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(56, '[email protected]', 'java/10-objects/CircularShift', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nA string <tt>S</tt> is a <i>circular shift</i> of a string <tt>T</tt>\\nif they are of the same length, and when written in clockwise circles,\\nthey are the same except for a rotation. For example, <tt>STOP</tt> and\\n<tt>TOPS</tt> are circular shifts of each other,\\nas are <tt>STRING</tt> and <TT>RINGST</tt>. But <tt>STOP</tt> and\\n<tt>POTS</tt> are not circular shifts of one another, nor are \\n<tt>CAT</tt> and <tt>ACT</tt>.\\n\\n<p>\\nWrite a static boolean method\\n<tt>isCircularShift(String S, String T)</tt>\\nthat determines whether two strings are circular shifts of one another.\\n\\n<p>\\nWe encourage you to \\nreview the <a href=\\"http://introcs.cs.princeton.edu/java/11cheatsheet/#String\\">\\nabbreviated String API</a> on the introcs cheatsheet. If you do this,\\nyou can solve this problem in one line\\nusing a concatenation, calls to <tt>length()</tt>,\\nand one additional method call (<a href=\\"http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)\\">hint</a>).\\n", "source_code": "\\npublic static boolean isCircularShift(String S, String T) {\\n\\\\[\\n return S.length() == T.length() && (S+S).indexOf(T)>=0;\\n]\\\\\\n}\\n", "tests": "\\ntest(\\"isCircularShift\\", \\"POTS\\", \\"SPOT\\");\\ntest(\\"isCircularShift\\", \\"TOPS\\", \\"STOP\\");\\ntest(\\"isCircularShift\\", \\"TOPS\\", \\"SPOT\\");\\ntest(\\"isCircularShift\\", \\"ABBA\\", \\"AABB\\");\\ntest(\\"isCircularShift\\", \\"BYEBYE\\", \\"BYE\\");\\ntest(\\"isCircularShift\\", \\"HI\\", \\"HIHI\\");\\ntest(\\"isCircularShift\\", \\"TESTCASE\\", \\"TESTCASE\\");\\ntest(\\"isCircularShift\\", \\"indexOf()\\", \\"Of()index\\");\\ntest(\\"isCircularShift\\", \\"indexOf()\\", \\"Ofindex()\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(57, '[email protected]', 'java/06-practicemidterm/FoodPart1', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Spring 2013 Programming Midterm 1, part 1/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/fall13/cos126/docs/mid1-s13-prog.pdf\\">\\nthis PDF link</a>.\\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>Because of Websheet formatting, on this page you have to put your header inside the class. On the exam, put it at the top as usual\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own, then copying here for full testing\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\\\[\\n/*******************************************************************\\n Reference solution for Spring 2013 COS 126 Programming Exam 1\\n Foodlympics Part One: Competitive Cuisine\\n\\n Author: COS 126 Staff\\n Netid: cos126\\n Precepts: lots of them\\n Dependencies: StdIn, StdOut\\n Usage: java FoodPart1 \\n \\n Description: Reads in judge rankings for C countries by J judges.\\n Prints out the rounded average score for each country,\\n excluding the min and max.\\n\\n**************************************************************************/\\n\\n // excluding the min and max, compute the rounded average\\n // of the entries of judgeRatings\\n public static int score(int[] judgeRatings) {\\n\\n int J = judgeRatings.length; \\n int sum = 0;\\n\\n int min = Integer.MAX_VALUE;\\n int max = Integer.MIN_VALUE;\\n for (int i = 0; i < J; i++) {\\n min = Math.min(min, judgeRatings[i]);\\n max = Math.max(max, judgeRatings[i]);\\n sum += judgeRatings[i];\\n } \\n\\n // eliminate min and max\\n sum = sum - min - max;\\n \\n // average\\n double ave = sum / (double) (J - 2);\\n \\n // rounded average, excluding min and max\\n int score = (int) Math.round(ave);\\n return score;\\n }\\n\\n // read the judges'' ratings for several countries\\n // from standard input and print their overall scores\\n // to standard output\\n public static void main(String[] args) {\\n int C = StdIn.readInt(); // number of countries\\n int J = StdIn.readInt(); // number of judges\\n\\n StdOut.println(C); // first line of output\\n\\n // for each country, process their ratings\\n for (int i = 0; i < C; i++) {\\n\\n // read the next line of input\\n String name = StdIn.readString();\\n int[] ratings = new int[J];\\n for (int j = 0; j < J; j++)\\n ratings[j] = StdIn.readInt();\\n\\n // compute the overall score\\n int overall = score(ratings);\\n\\n // output for this country\\n StdOut.println(name + \\" \\" + overall);\\n }\\n }\\n]\\\\\\n", "tests": "\\ntest(\\"score\\", (Object)new int[]{7, 14, 20, 12, 15, 16});\\ntest(\\"score\\", (Object)new int[]{10, 16, 10, 20, 14, 10});\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/docs/data/Food/german.txt\\";\\ntestMain();\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/docs/data/Food/na.txt\\";\\ntestMain();\\ntest(\\"score\\", (Object)new int[]{15, 5, 10});\\ntest(\\"score\\", (Object)new int[]{7, 7, 7});\\ntest(\\"score\\", (Object)new int[]{4, 8, 12, 16});\\ntest(\\"score\\", (Object)new int[]{4, 5, 10, 12});\\ntest(\\"score\\", (Object)new int[]{4, 5, 8, 12});\\ntest(\\"score\\", (Object)new int[]{20, 19, 20, 19, 20});\\ntest(\\"score\\", (Object)new int[]{1, 2, 1, 2, 1});\\nstdin = \\"1 3\\\\nPangaea 8 8 8\\";\\ntestMain();\\nstdin = \\"6 3\\\\nLMH 1 2 3\\\\nLHM 4 6 5\\\\nMLH 8 7 9\\\\nMHL 11 12 10\\\\nHLM 15 13 14\\\\nHML 18 17 16\\";\\ntestMain();\\nstdin = \\"6 3\\\\nLLH 1 1 9\\\\nLHL 1 9 1\\\\nHLL 9 1 1\\\\nLHH 1 9 9\\\\n HLH 9 1 9\\\\nHHL 9 9 1\\";\\ntestMain();\\nstdin = \\"2 3\\\\noneLand 1 1 1\\\\ntwentyStan 20 20 20\\";\\ntestMain();\\nstdin = \\"4 4\\\\nmaxRepeat 18 18 7 5\\\\nminRepeat 6 6 12 19\\\\nbothRepeat 4 4 12 12\\\\nfours 4 4 4 4\\";\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(58, '[email protected]', 'java/06-practicemidterm/SnowStats', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Spring 2014 Programming Midterm 2, part 1/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/mid1-s14-prog.pdf\\">\\nthis PDF link</a>. \\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own before using automatic tests\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\npublic class SnowStats {\\n\\\\[\\n/****************************************************************************\\n* Name: Donna Gabai\\n* NetID: dgabai\\n* Precept: P99\\n* Spring14 Exam 1\\n*\\n* Description: Inputs snowfall and temperature for a series of days.\\n* Outputs number of days, total inches of snow and coldest temp.\\n* Dependencies: StdIn, StdOut\\n* ***************************************************************************/\\n\\n public static void main(String[] args) {\\n // start at day zero, no snow, hottest possible temperature\\n int days = 0;\\n double snowSum = 0.0;\\n int lowestTemp = Integer.MAX_VALUE;\\n\\n // read data from standard input and count days\\n // add snowfall for total, keep lowest temp\\n while (!StdIn.isEmpty()) {\\n days++;\\n snowSum = snowSum + StdIn.readDouble();\\n int temp = StdIn.readInt();\\n if (temp < lowestTemp) lowestTemp = temp;\\n }\\n \\n StdOut.println(\\"Number of days: \\" + days);\\n StdOut.println(\\"Total snow: \\" + snowSum);\\n StdOut.println(\\"Coldest temperature: \\" + lowestTemp);\\n }\\n]\\\\\\n}\\n", "tests": "\\nstdin = \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\";\\ntestMain();\\n\\nstdin = \\"8.0 12\\\\n12.0 -5\\\\n0.0 -2\\\\n2.4 6\\\\n0.9 23\\\\n0.1 23\\\\n1.3 39\\";\\ntestMain();\\n\\nstdin = \\"108.0 200\\\\n102.7 200\\\\n10000 200\\";\\ntestMain();\\n\\nstdin = \\"102.0 -199\\\\n100.0 -145\\\\n102.4 -200\\\\n101.9 -119\\\\n104.4 -126\\";\\ntestMain();\\n\\nstdin = \\"0.0 13\\";\\ntestMain();\\n\\nstdin = \\"\\\\n1.6 27\\\\n0.1 -4\\\\n1.5 26\\\\n3.4 77\\\\n7.7 -13\\\\n3.6 75\\\\n6.0 -10\\\\n7.5 49\\\\n6.2 -6\\\\n4.7 -36\\\\n8.1 49\\\\n7.6 -18\\\\n0.8 -25\\\\n2.0 31\\\\n1.1 69\\\\n6.6 27\\\\n9.6 -26\\\\n4.4 -7\\\\n8.6 -11\\\\n3.1 51\\\\n8.0 -26\\\\n3.1 71\\\\n2.3 -4\\\\n6.6 50\\\\n3.0 36\\\\n4.0 62\\\\n1.4 30\\\\n2.8 -4\\\\n5.3 53\\\\n4.5 12\\\\n6.9 -34\\\\n9.5 25\\\\n9.6 31\\\\n6.8 -20\\\\n6.6 36\\\\n9.3 59\\\\n1.8 32\\\\n7.4 8\\\\n0.2 -35\\\\n5.8 14\\\\n3.3 7\\\\n1.4 33\\\\n0.0 0\\\\n2.3 42\\\\n2.1 15\\\\n8.7 40\\\\n3.9 -30\\\\n0.5 76\\\\n3.7 -11\\\\n10.0 74\\\\n9.3 18\\\\n2.3 21\\\\n8.1 23\\\\n3.0 77\\\\n3.0 60\\\\n9.8 3\\\\n7.3 12\\\\n2.8 -11\\\\n0.8 35\\\\n1.6 24\\\\n9.2 -27\\\\n6.2 -16\\\\n0.5 51\\\\n8.4 77\\\\n9.5 -40\\\\n7.0 -2\\\\n6.6 -16\\\\n8.2 -30\\\\n1.5 65\\\\n5.6 52\\\\n1.1 -40\\\\n7.0 71\\\\n8.7 -15\\\\n7.8 -10\\\\n8.2 14\\\\n4.3 -7\\\\n8.6 61\\\\n8.1 -39\\\\n5.7 4\\\\n3.1 53\\\\n1.0 74\\\\n8.0 20\\\\n8.8 -14\\\\n3.3 60\\\\n1.7 16\\\\n2.6 -9\\\\n1.6 1\\\\n7.0 51\\\\n7.2 -21\\\\n6.1 33\\\\n3.5 20\\\\n6.5 9\\\\n5.5 -15\\\\n2.0 39\\\\n0.5 7\\\\n1.2 39\\\\n\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(59, '[email protected]', 'java/06-practicemidterm/HatsPart2', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Fall 2012 Programming Midterm 1, part 2/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/fall13/cos126/docs/mid1-f12-prog.pdf\\">\\nthis PDF link</a>. Please use the alternate URL\\n<pre>\\n<a href=\\"http://www.cs.princeton.edu/~cos126/docs/data/Hats/\\">http://www.cs.princeton.edu/~cos126/docs/data/Hats/</a>\\n</pre> to access\\nthe sample input files.\\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>Because of Websheet formatting, on this page you have to put your header inside the class. On the exam, put it at the top as usual\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own, then copying here for full testing\\n<li>The exam grader is generally less picky about output whitespace than the Websheet grader.\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\n\\\\[\\n/***********************************************************************\\nChristopher Moretti\\ncmoretti\\nP01A/P06\\n\\nRead in list side and permutations of that size.\\nDetermine the max cycle length of each permutation.\\nCompute and print the average max cycle length.\\n\\nRequires StdIn, StdOut\\n***************************************************************************/\\n\\n // determine longest cycle to get own hat back\\n public static int maxCycleLength(int[] arr) {\\n int N = arr.length;\\n int max = 0; // max cycle length\\n int cycle; // current cycle length\\n \\n // for each person\\n for (int i = 0; i < N; i++) {\\n int j = i;\\n cycle = 1; // minimal cycle has 1 person \\n\\n // while person j doesn''t have person i''s hat\\n while (arr[j] != i+1) {\\n j = arr[j] - 1; // new person j to look for\\n cycle++;\\n }\\n \\n if (max < cycle) max = cycle; // new longest cycle\\n }\\n\\n // return longest cycle length\\n return max;\\n }\\n \\n public static void main(String[] args) {\\n // the # of items in the permutation\\n int N = StdIn.readInt();\\n \\n // space to hold permutation\\n int[] arr = new int[N];\\n\\n // running sum for max cycle lengths\\n int sum = 0;\\n\\n // how many derangements have we seen?\\n int count = 0;\\n \\n // Read until there are no more permutations left on StdIn.\\n while (!StdIn.isEmpty()) {\\n // fill array\\n for (int i = 0; i < N; i++) {\\n arr[i] = StdIn.readInt();\\n }\\n\\n // count it and find its max cycle length\\n count++;\\n sum += maxCycleLength(arr);\\n }\\n \\n // compute and print average with the given format\\n StdOut.println(\\"Average max cycle length: \\" + (double) sum / count);\\n }\\n]\\\\\\n", "tests": "\\ntest(\\"maxCycleLength\\", (Object)new int[]{3, 4, 1, 5, 2, 6});\\ntest(\\"maxCycleLength\\", (Object)new int[]{1, 3, 4, 5, 6, 2});\\ntest(\\"maxCycleLength\\", (Object)new int[]{3, 1, 4, 2, 6, 5});\\ntest(\\"maxCycleLength\\", (Object)new int[]{1, 2, 3, 4, 5, 6, 7, 8});\\ntest(\\"maxCycleLength\\", (Object)new int[]{8, 7, 6, 5, 4, 3, 2, 1});\\ntest(\\"maxCycleLength\\", (Object)new int[]{9, 8, 7, 6, 5, 4, 3, 2, 1});\\ntest(\\"maxCycleLength\\", (Object)new int[]{2, 3, 4, 5, 1});\\ntest(\\"maxCycleLength\\", (Object)new int[]{1});\\ntest(\\"maxCycleLength\\", (Object)new int[]{2, 1});\\ntest(\\"maxCycleLength\\", (Object)new int[]{1, 2});\\nstdin = \\"9\\\\n9 8 7 6 5 4 3 2 1\\\\n3 7 6 9 8 2 1 5 4\\";\\ntestMain();\\nstdin = \\"6\\\\n1 2 6 4 3 5\\\\n6 1 5 4 3 2\\";\\ntestMain();\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/docs/data/Hats/5perms9.txt\\";\\ntestMain();\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/docs/data/Hats/1000perms15.txt\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(60, '[email protected]', 'java/06-practicemidterm/FoodPart2', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Spring 2013 Programming Midterm 1, part 1/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/fall13/cos126/docs/mid1-s13-prog.pdf\\">\\nthis PDF link</a>.\\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>Because of Websheet formatting, on this page you have to put your header inside the class. On the exam, put it at the top as usual\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own, then copying here for full testing\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\n\\\\[\\n/******************************************************************* \\n Reference solution for Spring 2013 COS 126 Programming Exam 1\\n Foodlympics Part Two: Gourmet Glory\\n\\n Author: COS 126 Staff\\n Netid: cos126\\n Precepts: lots of them\\n Dependencies: StdIn, StdOut\\n Usage: java FoodPart2 N\\n \\n Description: Reads in names and scores for C countries. Prints out the N\\n top-score countries in order. \\n \\n**************************************************************************/\\n\\n // find the highest value in scores. set this value to 0, and \\n // return the corresponding element of countries.\\n public static String best(String[] countries, int[] scores) {\\n // number of countries\\n int C = countries.length;\\n\\n // bestIndex is the index of the (earliest) max-score country\\n int bestIndex = -1; \\n \\n // max is the maximum score seen so far\\n int max = Integer.MIN_VALUE;\\n \\n // find index of max-score country\\n for (int i = 0; i < C; i++) {\\n if (scores[i] > max) {\\n max = scores[i];\\n bestIndex = i;\\n }\\n }\\n \\n // do required update and return the winner\\n scores[bestIndex] = 0;\\n return countries[bestIndex];\\n }\\n\\n // read in a file of scores, and take N from the command-line.\\n // then print out the top N ranking countries from best to worst.\\n public static void main(String[] args) {\\n\\n int C = StdIn.readInt(); // number of countries\\n int N = Integer.parseInt(args[0]); // how many to rank\\n\\n String[] countries = new String[C];\\n int[] scores = new int[C];\\n\\n // read the rest of the input\\n for (int i = 0; i < C; i++) {\\n countries[i] = StdIn.readString();\\n scores[i] = StdIn.readInt();\\n }\\n \\n // now print the results\\n for (int i = 0; i < N; i++) {\\n String nextRanked = best(countries, scores);\\n StdOut.println(\\"Rank \\" + (i+1) + \\": \\" + nextRanked);\\n }\\n }\\n]\\\\\\n", "tests": "\\ntest(\\"best\\", new String[]{\\"SAA\\", \\"BOH\\"}, new int[]{5, 10});\\ntest(\\"best\\", new String[]{\\"SAA\\", \\"BOH\\"}, new int[]{5, 0});\\ntest(\\"best\\", new String[]{\\"Japan\\", \\"USA\\", \\"Mali\\", \\"Cuba\\", \\"Togo\\"}, new int[]{13, 15, 17, 19, 14});\\ntest(\\"best\\", new String[]{\\"Japan\\", \\"USA\\", \\"Mali\\", \\"Cuba\\", \\"Togo\\"}, new int[]{13, 15, 17, 0, 14});\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/docs/data/Food/naScores.txt\\";\\ntestMain(\\"3\\");\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/docs/data/Food/germanScores.txt\\";\\ntestMain(\\"2\\");\\ntest(\\"best\\", new String[]{\\"Pangaea\\"}, new int[]{10});\\ntest(\\"best\\", new String[]{\\"LO\\", \\"HI\\"}, new int[]{5, 10});\\ntest(\\"best\\", new String[]{\\"HI\\", \\"LO\\"}, new int[]{10, 5});\\ntest(\\"best\\", new String[]{\\"EQ\\", \\"EQUAL\\"}, new int[]{8, 8});\\ntest(\\"best\\", new String[]{\\"big\\", \\"small\\", \\"bigagain\\", \\"smallagain\\"}, new int[]{20, 1, 20, 1});\\ntest(\\"best\\", new String[]{\\"big\\", \\"small\\", \\"bigagain\\", \\"smallagain\\"}, new int[]{0, 1, 20, 1});\\ntest(\\"best\\", new String[]{\\"big\\", \\"small\\", \\"bigagain\\", \\"smallagain\\"}, new int[]{0, 1, 0, 1});\\ntest(\\"best\\", new String[]{\\"big\\", \\"small\\", \\"bigagain\\", \\"smallagain\\"}, new int[]{0, 0, 0, 1});\\nstdin = \\"1\\\\nPangaea 10\\"; testMain(\\"1\\");\\nstdin = \\"2\\\\nA 5\\\\nB 5\\"; testMain(\\"2\\");\\nstdin = \\"2\\\\nA 5\\\\nB 8\\"; testMain(\\"2\\");\\nstdin = \\"2\\\\nA 8\\\\nB 5\\"; testMain(\\"2\\");\\nstdin = \\"3\\\\nA 8\\\\nB 8\\\\nC 1\\"; testMain(\\"3\\");\\nstdin = \\"4\\\\nA 8\\\\nB 5\\\\nC 8\\\\nD 5\\"; testMain(\\"1\\");\\nstdin = \\"4\\\\nA 8\\\\nB 5\\\\nC 8\\\\nD 5\\"; testMain(\\"4\\");\\nstdin = \\"7\\\\nA 8\\\\nB 6\\\\nC 7\\\\nD 5\\\\nE 3\\\\nF 10\\\\nG 9\\"; testMain(\\"3\\");\\nstdin = \\"7\\\\nA 8\\\\nB 6\\\\nC 7\\\\nD 5\\\\nE 3\\\\nF 10\\\\nG 9\\"; testMain(\\"7\\");\\nstdin = \\"9\\\\nA 3\\\\nB 14\\\\nC 15\\\\nD 9\\\\nE 2\\\\nF 6\\\\nG 5\\\\nH 3\\\\nI 5\\"; testMain(\\"1\\");\\nstdin = \\"9\\\\nA 3\\\\nB 14\\\\nC 15\\\\nD 9\\\\nE 2\\\\nF 6\\\\nG 5\\\\nH 3\\\\nI 5\\"; testMain(\\"3\\");\\nstdin = \\"9\\\\nA 3\\\\nB 14\\\\nC 15\\\\nD 9\\\\nE 2\\\\nF 6\\\\nG 5\\\\nH 3\\\\nI 5\\"; testMain(\\"9\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(61, '[email protected]', 'java/06-practicemidterm/SnowMelt', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Spring 2014 Programming Midterm 2, part 2/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/spring14/cos126/docs/mid1-s14-prog.pdf\\">\\nthis PDF link</a>. \\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own before using automatic tests\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\npublic class SnowMelt {\\n\\\\[\\n/****************************************************************************\\n * Name: Donna Gabai\\n * NetID: dgabai\\n * Precept: P99 \\n * Spring14 Exam 1\\n * \\n * Description: Simulates how fast the snow will melt \\n * based on how much salt is used and temp\\n * Dependencies: StdIn, StdOut\\n * ***************************************************************************/\\n \\n // using current snow, temperature and salt solution\\n // how much snow will melt?\\n public static double meltage(double currSnow, int temp, int salt) {\\n double result = Math.pow(1 + currSnow, (temp - 32 + 2*salt)/18.0);\\n result = Math.min(currSnow, result);\\n return result;\\n }\\n \\n // formatted printing of a double[] array\\n public static void printArray(double[] arr) {\\n int N = arr.length;\\n for (int i = 0; i < N; i++)\\n StdOut.printf(\\"%8.3f\\", arr[i]);\\n\\n // new line after all entries printed\\n StdOut.println();\\n }\\n \\n // Part 2B: input data file from standard input\\n // input salt solution ints from command-line\\n // output remaining snow for each day for each salt solution\\n public static void main(String[] args) {\\n // store salt for scenarios\\n int N = args.length;\\n int[] salt = new int[N];\\n for (int i = 0; i < N; i++)\\n salt[i] = Integer.parseInt(args[i]);\\n \\n // array of snow left on ground for each scenario\\n double[] snowLeft = new double[N];\\n \\n // input snow in inches and temp in degrees F for each day\\n while (!StdIn.isEmpty()) {\\n // read data from standard input\\n double newSnow = StdIn.readDouble();\\n int temp = StdIn.readInt();\\n \\n // compute meltage for one day with each salt value\\n for (int i = 0; i < N; i++) {\\n snowLeft[i] = snowLeft[i] + newSnow;\\n double melt = meltage(snowLeft[i], temp, salt[i]);\\n // how much snow left after the melting?\\n snowLeft[i] = snowLeft[i] - melt;\\n }\\n printArray(snowLeft);\\n }\\n }\\n]\\\\\\n}\\n", "tests": "\\ntest(\\"meltage\\", 8.0, 21, 10);\\ntest(\\"meltage\\", 0.0, 0, 0);\\ntest(\\"meltage\\", 7.7, 27, 1);\\ntest(\\"meltage\\", 1.1, 50, 6);\\ntest(\\"meltage\\", 9.0, -20, 19);\\ntest(\\"meltage\\", 3.0, 32, 0);\\ntest(\\"meltage\\", 3.0, 50, 0);\\ntest(\\"meltage\\", 1.0, -4, 0);\\n\\ntest(\\"printArray\\", (Object) new double[]{0.0, 0.0, 0.0});\\ntest(\\"printArray\\", (Object) new double[]{Math.PI, Math.PI/2, Math.sqrt(3), 16.1});\\ntest(\\"printArray\\", (Object) new double[]{4., 5., 6., 7., 8., 9., 10., 11., 12.});\\ntest(\\"printArray\\", (Object) new double[]{0.5});\\ntest(\\"printArray\\", (Object) new double[]{1000, -200, 1, 2, 1});\\n\\nstdin = \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\";\\ntestMain(\\"5\\");\\n\\nstdin = \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\";\\ntestMain(\\"10\\");\\n\\nstdin = \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\";\\ntestMain(\\"2\\");\\n\\nstdin = \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\";\\ntestMain(\\"5\\", \\"10\\");\\n\\nstdin = \\"8.0 12\\\\n12.0 -5\\\\n0.0 -2\\\\n2.4 6\\\\n0.9 23\\\\n0.1 23\\\\n1.3 39\\";\\ntestMain(\\"0\\", \\"3\\", \\"6\\");\\n\\nstdin = \\"0.0 13\\";\\ntestMain(\\"5\\", \\"10\\", \\"20\\");\\n\\nstdin = \\"108.0 200\\\\n102.7 200\\\\n10000 200\\";\\ntestMain(\\"0\\", \\"7\\", \\"14\\");\\n\\nstdin = \\"102.0 -199\\\\n100.0 -145\\\\n102.4 -200\\\\n101.9 -119\\\\n104.4 -126\\";\\ntestMain(\\"3\\", \\"9\\", \\"20\\");\\n\\nstdin = \\"\\\\n1.6 27\\\\n0.1 -4\\\\n1.5 26\\\\n3.4 77\\\\n7.7 -13\\\\n3.6 75\\\\n6.0 -10\\\\n7.5 49\\\\n6.2 -6\\\\n4.7 -36\\\\n8.1 49\\\\n7.6 -18\\\\n0.8 -25\\\\n2.0 31\\\\n1.1 69\\\\n6.6 27\\\\n9.6 -26\\\\n4.4 -7\\\\n8.6 -11\\\\n3.1 51\\\\n8.0 -26\\\\n3.1 71\\\\n2.3 -4\\\\n6.6 50\\\\n3.0 36\\\\n4.0 62\\\\n1.4 30\\\\n2.8 -4\\\\n5.3 53\\\\n4.5 12\\\\n6.9 -34\\\\n9.5 25\\\\n9.6 31\\\\n6.8 -20\\\\n6.6 36\\\\n9.3 59\\\\n1.8 32\\\\n7.4 8\\\\n0.2 -35\\\\n5.8 14\\\\n3.3 7\\\\n1.4 33\\\\n0.0 0\\\\n2.3 42\\\\n2.1 15\\\\n8.7 40\\\\n3.9 -30\\\\n0.5 76\\\\n3.7 -11\\\\n10.0 74\\\\n9.3 18\\\\n2.3 21\\\\n8.1 23\\\\n3.0 77\\\\n3.0 60\\\\n9.8 3\\\\n7.3 12\\\\n2.8 -11\\\\n0.8 35\\\\n1.6 24\\\\n9.2 -27\\\\n6.2 -16\\\\n0.5 51\\\\n8.4 77\\\\n9.5 -40\\\\n7.0 -2\\\\n6.6 -16\\\\n8.2 -30\\\\n1.5 65\\\\n5.6 52\\\\n1.1 -40\\\\n7.0 71\\\\n8.7 -15\\\\n7.8 -10\\\\n8.2 14\\\\n4.3 -7\\\\n8.6 61\\\\n8.1 -39\\\\n5.7 4\\\\n3.1 53\\\\n1.0 74\\\\n8.0 20\\\\n8.8 -14\\\\n3.3 60\\\\n1.7 16\\\\n2.6 -9\\\\n1.6 1\\\\n7.0 51\\\\n7.2 -21\\\\n6.1 33\\\\n3.5 20\\\\n6.5 9\\\\n5.5 -15\\\\n2.0 39\\\\n0.5 7\\\\n1.2 39\\\\n\\";\\ntestMain(\\"2\\", \\"12\\", \\"30\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(62, '[email protected]', 'java/06-practicemidterm/HatsPart1', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>COS 126 Fall 2012 Programming Midterm 1, part 1/2</i><br>\\nPlease see the problem description in <a href=\\"http://www.cs.princeton.edu/courses/archive/fall13/cos126/docs/mid1-f12-prog.pdf\\">\\nthis PDF link</a>. Please use the alternate URL\\n<pre>\\n<a href=\\"http://www.cs.princeton.edu/~cos126/docs/data/Hats/\\">http://www.cs.princeton.edu/~cos126/docs/data/Hats/</a>\\n</pre> to access\\nthe sample input files.\\n<p>\\nThis websheet is intended as a practice exam. However, in a real exam,\\n<ul>\\n<li>You''ll upload via Dropbox\\n<li>You''ll get limited feedback from Dropbox during the exam, and a different full set of test cases for grading\\n<li>Real humans will grade your real exams and also mark you on style and apply partial credit where appropriate\\n<li>Because of Websheet formatting, on this page you have to put your header inside the class. On the exam, put it at the top as usual\\n<li>We recommend coding in DrJava and/or the command-line and doing basic tests on your own, then copying here for full testing\\n<li>The exam grader is generally less picky about output whitespace than the Websheet grader.\\n</ul>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "source_code": "\\\\[\\n/*********************************************************************** \\nChristopher Moretti\\ncmoretti\\nP01A/P06\\n\\nRead in list size and permutations of that size.\\nDetermine if each is a \\"derangement\\". \\nPrint out the first derangement if it exists.\\nPrint out the number of derangements.\\n\\nRequires StdIn and StdOut\\n***********************************************************************/\\n\\n // print the first derangement with the given format\\n private static void printD(int[] r) {\\n StdOut.print(\\"First derangement:\\");\\n for (int i = 0; i < r.length; i++)\\n StdOut.print(\\" \\"+r[i]);\\n StdOut.println();\\n }\\n \\n // return true if r holds a derangement, false otherwise\\n public static boolean isD(int[] r) {\\n for (int i = 0; i < r.length; i++) {\\n if (r[i] == i+1) //i+1 to account for Java 0-based arrays\\n return false;\\n }\\n return true;\\n }\\n\\n public static void main(String[] args) {\\n // the # of items in permutation\\n int N = StdIn.readInt(); \\n\\n // space to hold permutation\\n int[] arr = new int[N]; \\n\\n // how many derangements have we seen?\\n int count = 0; \\n \\n // Read until there are no more permutations left on StdIn.\\n while (!StdIn.isEmpty()) {\\n // fill array\\n for (int i = 0; i < N; i++)\\n arr[i] = StdIn.readInt();\\n\\n // if arr is a derangement, count i\\n // and print it if it''s the first.\\n if (isD(arr)) { \\n if (count == 0) \\n printD(arr); \\n count++; \\n }\\n }\\n\\n // print the count with the given format\\n StdOut.println(\\"Number of derangements: \\" + count);\\n }\\n]\\\\\\n", "tests": "\\ntest(\\"isD\\", (Object)new int[]{3, 4, 1, 5, 2, 6});\\ntest(\\"isD\\", (Object)new int[]{1, 3, 4, 5, 6, 2});\\ntest(\\"isD\\", (Object)new int[]{3, 1, 4, 2, 6, 5});\\ntest(\\"isD\\", (Object)new int[]{1, 2, 3, 4, 5, 6, 7, 8});\\ntest(\\"isD\\", (Object)new int[]{8, 7, 6, 5, 4, 3, 2, 1});\\ntest(\\"isD\\", (Object)new int[]{9, 8, 7, 6, 5, 4, 3, 2, 1});\\ntest(\\"isD\\", (Object)new int[]{1});\\ntest(\\"isD\\", (Object)new int[]{2, 1});\\ntest(\\"isD\\", (Object)new int[]{1, 2});\\nstdin = \\"9\\\\n9 8 7 6 5 4 3 2 1\\\\n3 7 6 9 8 2 1 5 4\\";\\ntestMain();\\nstdin = \\"6\\\\n1 2 6 4 3 5\\\\n6 1 5 4 3 2\\";\\ntestMain();\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/docs/data/Hats/5perms9.txt\\";\\ntestMain();\\nstdinURL = \\"http://www.cs.princeton.edu/~cos126/docs/data/Hats/1000perms15.txt\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(63, '[email protected]', 'java/02-control/Flag', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nThe official flag of COS 126 is a right triangle pointing up-left,\\nwith <code>n</code> rows and <code>n</code> columns, made out of\\nbackslashes, where <code>n</code> is a command-line argument.\\nWrite a program to print it out for any positive integer <code>n</code>:\\nfor example\\n<code>java Flag 5</code> should print out\\n<pre>\\n\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\n\\\\\\\\\\n\\\\\\n</pre>\\nThis tests two things: escaping in strings, and nested loops.\\n", "source_code": "\\npublic static void main(String[] args) {\\n int n = Integer.parseInt(args[0]);\\n for (int i=0; \\\\[i<n; i++]\\\\) {\\n for (int j\\\\[=0; j<n-i; j++]\\\\) {\\n System.out.\\\\[print(\\"\\\\\\\\\\")]\\\\;\\n }\\n System.out.\\\\[println()]\\\\;\\n }\\n}\\n", "tests": "\\ntestMain(\\"5\\");\\ntestMain(randgen.nextInt(10)+10+\\"\\");\\ntestMain(\\"1\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(64, '[email protected]', 'java/02-control/Quadratic', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<p>\\nGiven command-line arguments\\n<code>b</code> and <code>c</code>, print out the \\nroots of <code>x<sup>2</sup> + bx + c = 0</code>. They are given by\\nthe formula\\n$$\\\\Large (-b \\\\pm \\\\sqrt{b^2-4c})/2$$\\nIf the <b>discriminant</b> <code>b<sup>2</sup>-4c</code> is \\nnegative, instead print out <code>There are no roots</code>.\\nWhen there are two roots, print the <b>smaller</b> one first.\\nWhen the discriminant is zero*, print out the single number <code>-b/2</code>:\\nboth roots have this value.\\n<p>\\n*: Because of floating-point inaccuracy, it''s better to check if the discriminant is very close to zero, say within 10<sup>-6</sup>. You could use a condition like <code>Math.abs(disc) < 1E-6</code>. \\n", "source_code": "\\npublic static void main(String[] args) {\\n double b = Double.parseDouble(args[0]);\\n double c = Double.parseDouble(args[1]);\\n\\\\[\\n double disc = (b*b-4*c);\\n\\n if (Math.abs(disc) < 1E-6) {\\n // avoid square roots: sqrt(disc) could cause \\"not a number\\" if disc < 0\\n System.out.println(-b/2);\\n }\\n else if (disc < 0) {\\n System.out.println(\\"There are no roots\\");\\n }\\n else {\\n double root1 = (-b-Math.sqrt(disc))/2;\\n double root2 = (-b+Math.sqrt(disc))/2;\\n System.out.println(root1);\\n System.out.println(root2);\\n }\\n]\\\\\\n}\\n", "tests": "\\ntestMain(-1, -1);\\ntestMain(0, -2);\\ntestMain(0, 2);\\ntestMain(-4, 4);\\ntestMain(-0.1, 0.0025);\\ntestMain(randgen.nextInt(10)+10, randgen.nextInt(20));\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(65, '[email protected]', 'java/02-control/AgeChecker', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>AgeChecker</code>\\n that reads an integer from input, representing\\nsomeone''s age. If the age is 18 or larger, print out <pre>You can vote</pre>\\nIf the age is \\nbetween 0 and 17 inclusive, print out <pre>Too young to vote</pre>\\nIf the age is less than 0, print out <pre>You are a time traveller</pre>\\n", "source_code": "\\npublic static void main(String[] args) {\\n int age = Integer.parseInt(args[0]); \\n\\\\[\\n if (age < 0) {\\n System.out.println(\\"You are a time traveller\\");\\n }\\n else if (age < 18) {\\n System.out.println(\\"Too young to vote\\");\\n }\\n else {\\n System.out.println(\\"You can vote\\");\\n }\\n]\\\\\\n}\\n", "tests": "\\ntestMain(\\"-1\\");\\ntestMain(\\"0\\");\\ntestMain(\\"17\\");\\ntestMain(\\"18\\");\\ntestMain(20+randgen.nextInt(100)+\\"\\");\\ntestMain(-1-randgen.nextInt(100)+\\"\\");\\ntestMain(10+randgen.nextInt(6)+\\"\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(66, '[email protected]', 'java/02-control/ModularSqrt', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>ModularSqrt</code> that takes two command-line\\narguments, <code>remainder</code> and <code>modulus</code>. \\nIt should print \\nout all of the integers <code>i</code> between <code>0</code> and\\n<code>modulus-1</code>\\nwith the property that <code>(i*i) % modulus</code> equals \\n<code>remainder</code>, and a count of how many integers were found. \\nUse the format shown in this example:\\n<code>java ModularSqrt 9 10</code> should print out\\n<pre>\\n3\\n7\\n2 square roots were found\\n</pre>\\n(There''s no need to have correct English grammar: print <tt>1 square roots were found</tt> if\\nexactly 1 is found.)\\n", "source_code": "\\npublic class ModularSqrt {\\n public static void main(String[] args) {\\n int remainder = Integer.parseInt(args[0]);\\n int modulus = Integer.parseInt(args[1]);\\n\\\\[\\n int count = 0;\\n for (int i=0; i<modulus; i++) {\\n if ((i*i) % modulus == remainder) {\\n System.out.println(i);\\n count += 1;\\n }\\n }\\n System.out.println(count + \\" square roots were found\\");\\n]\\\\\\n }\\n}\\n", "tests": "\\ntestMain(\\"9\\", \\"10\\");\\ntestMain(\\"3\\", \\"8\\");\\ntestMain(\\"5\\", \\"10\\");\\ntestMain(\\"1\\", \\"8\\");\\ntestMain(randgen.nextInt(100)+\\"\\", \\"100\\");\\ntestMain(randgen.nextInt(100)+\\"\\", \\"100\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(67, '[email protected]', 'java/02-control/SquareCensus', '{"sharing": "open", "attempts_until_ref": "1", "description": " \\nWrite a program SquareCensus that takes a single command-line argument <code>n</code>,\\nwhich is an integer. First, print out all of the positive square numbers less\\nthan or equal to <code>n</code> (in increasing order). Then, print out their \\nsum. Use the format shown in this example: <code>java SquareCensus 11</code> should output\\n<pre>\\n1\\n4\\n9\\nThe sum is 14\\n</pre>\\n", "source_code": "\\npublic class SquareCensus {\\n public static void main(String[] args) {\\n int n = Integer.parseInt(args[0]);\\n int i = 1;\\n int sum = \\\\[0]\\\\;\\n while (\\\\[i*i <= n]\\\\) {\\n\\\\[\\n System.out.println(i*i);\\n sum += i*i;\\n i += 1;\\n]\\\\\\n }\\n System.out.println(\\"The sum is \\" + sum);\\n }\\n}\\n", "tests": "\\ntestMain(\\"11\\");\\ntestMain(\\"16\\");\\ntestMain(50+randgen.nextInt(50)+\\"\\");\\ntestMain(\\"1\\");\\ntestMain(\\"0\\");\\ntestMain(\\"-1\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(68, '[email protected]', 'java/08-dynamicprogramming/Mario', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<style> .ss {font-family:sans-serif} </style>\\nNintendo''s new minimalist video game controller only has two buttons,\\n<span class=''ss''>down</span>\\n and \\n<span class=''ss''>right</span>.\\nIn the platform launch title Super Mario Multiverse,\\nevery level is a rectangular grid of cells \\nwhere Mario starts in the top-left corner. Some\\ncells of the grid have coins with a value, and other cells\\nare empty. The player has to press <span class=''ss''>down</span>\\n and <span class=''ss''>right</span> in some order until\\nthey get to the bottom-right corner, and their score is the sum total of\\nthe value of \\nall coins they hit along the way. Write a program\\nto find the maximum possible score for any level.\\n\\n<p>\\nWe represent a level by an <tt>int[][] cellValue</tt> where \\n<tt>cellValue[i][j]</tt> is the cell <tt>i</tt>th from the top\\nand <tt>j</tt>th from the left (counting from 0, so the top-left cell is\\n<tt>[0][0]</tt>). A positive value means a coin with that value,\\nand a value of 0 means no coin is in that cell. For example, suppose\\n<tt>cellValue</tt> is the <tt>int[4][5]</tt> described by\\n<pre>\\n{{1, 1, 0, 2, 0},\\n {0, 2, 0, 2, 0},\\n {0, 1, 0, 0, 1},\\n {3, 0, 0, 0, 1}}\\n</pre>\\nMario has lots of possible paths. Remember he must go from the top-left\\nto the bottom-right using only steps <span class=''ss''>right</span>\\n (R) and <span class=''ss''>down</span> (D).\\nIf he goes D-D-D-R-R-R-R, he gets a score of 1+3+1=5. The path\\nR-D-R-R-D-R-D achieves a score of 1+1+2+2+1+1=8, which happens to be \\nthe maximum possible for this room.\\n<p>\\nWrite a static method <code>int maxPath(int[][] cellValue)</code>\\nthat computes the maximum score for a level given in this format. \\nUse dynamic programming: compute, for each position, the best value \\nyou can get if you start in that cell.\\n", "source_code": "\\npublic static int maxPath(int[][] cellValue) {\\n int m = cellValue.length; // height\\n int n = cellValue[0].length; // width\\n\\n // opt[i][j]: max value attainable if starting at position [i][j]\\n int[][] opt = new int[m][n];\\n // base case: corner\\n opt[m-1][n-1] = cellValue[m-1][n-1];\\n // pseudo-base case: right column, have to go down\\n for (int i=m-2; i>=0; i--)\\n opt[i][n-1] = cellValue[i][n-1] + opt[i+1][n-1];\\n // pseudo-base case: bottom row, have to go right\\n for (int j\\\\[=n-2; j>=0; j--]\\\\)\\n \\\\[opt[m-1][j] = cellValue[m-1][j] + opt[m-1][j+1]]\\\\;\\n // general case\\n for (int i\\\\[=m-2; i>=0; i--]\\\\) {\\n for (int j\\\\[=n-2; j>=0; j--]\\\\) {\\n // a choice! take better choice of down and right\\n opt[i][j] = cellValue[i][j] + Math.\\\\[max]\\\\(\\\\[opt[i+1][j]]\\\\,\\n \\\\[opt[i][j+1]]\\\\);\\n }\\n }\\n // value in top-left corner\\n return \\\\[opt[0][0]]\\\\;\\n}\\n\\npublic static void main(String[] args) {\\n int[][] testRoom =\\n {{1, 1, 0, 2, 0},\\n {0, 2, 0, 2, 0},\\n {0, 1, 0, 0, 1},\\n {3, 0, 0, 0, 1}};\\n StdOut.println(maxPath(testRoom));\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"maxPath\\", (Object)new int[][]{{31, 2, 0}, {5, 26, 6}, {0, 4, 33}});\\ntest(\\"maxPath\\", (Object)new int[][]{{0, 2, 31}, {6, 26, 5}, {33, 4, 0}});\\ntest(\\"maxPath\\", (Object)new int[][]{{5, 3, 1}, {0, 3, 4}, {5, 3, 4}, {0, 2, 1}});\\ntest(\\"maxPath\\", (Object)new int[][]{{1, 2, 3, 4}});\\ntest(\\"maxPath\\", (Object)new int[][]{{1}, {2}, {3}, {4}});\\ntest(\\"maxPath\\", (Object)new int[][]{{1, 5, 8, 4, 1, 0, 2, 4, 0, 6}, {8, 3, 6, 8, 6, 4, 6, 2, 8, 0}, {3, 6, 0, 1, 1, 9, 8, 4, 2, 0}, {2, 0, 4, 4, 1, 9, 1, 3, 3, 3}, {2, 0, 4, 8, 9, 6, 5, 0, 8, 2}, {9, 5, 7, 6, 0, 0, 5, 4, 4, 3}, {7, 4, 9, 1, 4, 4, 1, 4, 8, 2}, {6, 1, 4, 7, 0, 8, 5, 8, 3, 8}, {9, 6, 0, 2, 3, 6, 6, 4, 5, 2}, {5, 0, 5, 1, 6, 1, 4, 3, 5, 0}});\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(69, '[email protected]', 'java/08-dynamicprogramming/Knapsack', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nThere are many variants of the <i>knapsack problem</i>. In this one,\\nyou are given a list (an <tt>int</tt> array) of the weights of different\\nitems in a house you are robbing. You also have a knapsack of a fixed\\nweight capacity. You want to choose some of the items and leave the others\\nso that \\n<ol>\\n<li>\\nthe total weight of the items\\nyou select is as large as possible (steal as much as possible), but </li>\\n<li>\\nthe total weight of the items you select\\nmust not be larger than the capacity (or else the knapsack will rip).\\n</li>\\n</ol>\\n\\nFor example, if the item weights are\\n5, 7, 10, and 11, and the capacity is 20, then the largest weight you can\\ntake is 18 (the item of weight 7 and the item of weight 11). No \\nsubset of these 4 items has total weight 19 or 20, so this is the best\\nyou can do.\\n\\n<p>\\nWrite a static method <tt>int maxFits(int[] itemWeights, int capacity)</tt>\\nto compute the maximum weight you can steal. Several recursive approaches\\nare possible, but they are too slow. Instead, use a dynamic programming\\napproach that computes:\\n<ul>\\n<li>\\nIf you steal either no items or only the first item,\\nfor each weight <tt>i=0</tt> … <tt>capacity</tt>, is it possible to\\nsteal a total weight of exactly i?\\n<li>\\nIf you steal only a subset of the first two items,\\nfor each weight <tt>i=0</tt> … <tt>capacity</tt>, is it possible to\\nsteal a total weight of exactly i?\\n</li>\\n<li>Same as before, but only a subset of the first three items?</li>\\n<li>And so on, until you determine all weights that could be stolen\\nusing any subset whatsoever of the items.</li>\\n</ul>\\nThis can be computed using a 2D array of booleans, or a 1D array if\\nyou are careful.\\nFinally,\\nreport the maximum weight up to <tt>capacity</tt> that can be stolen.\\n<p>\\nMany variations of this problem are interesting. What if you can steal multiple copies of any\\nitem?\\nWhat if each item\\nhas a dollar value (unrelated to its weight) and you want to \\nsteal a maximum-value subset? What if there are both weight and size limits\\n(and each item''s size is given)? How do you <i>find</i> the best subset? (See\\nthe next problem <a href=\\"javascript:websheets.load(''java/08-dynamicprogramming/KnapsackBacktrack'')\\">KnapsackBacktrack</a>.)\\n\\n", "source_code": "\\npublic static int maxFits(int[] itemWeights, int capacity) {\\n int numItems = itemWeights.length; // for convenience\\n\\\\[\\n // canMake[j][i]: can we make weight exactly j, using a subset of the\\n // items 0, 1, ..., i-1?\\n boolean[][] canMake = new boolean[capacity+1][numItems+1];\\n\\n // if no items are allowed (i==0), the only weight we can make is 0\\n canMake[0][0] = true;\\n\\n for (int i=1; i<=numItems; i++) {\\n for (int j=0; j<=capacity; j++) {\\n // if we can get a total weight of j using a subset of the first\\n // i items, we can do the same with a subset of the first i-1,\\n // by simply not taking the ith item\\n canMake[j][i] = canMake[j][i-1];\\n\\n // if we take the ith item, to make weight j, the subset of items\\n // up to i must have weight j-itemWeights[i-1]\\n if (j >= itemWeights[i-1] && canMake[j-itemWeights[i-1]][i-1])\\n canMake[j][i] = true;\\n }\\n }\\n \\n // find biggest weight <= capacity that can be made\\n int result = 0;\\n for (int j=0; j<=capacity; j++)\\n if (canMake[j][numItems]) result = j;\\n return result;\\n]\\\\\\n}\\n\\npublic static void main(String[] args) {\\n int[] testWeights = {5, 7, 10, 11};\\n StdOut.println(maxFits(testWeights, 20)); // should be 18 (7+11)\\n StdOut.println(maxFits(testWeights, 100)); // should be 33 (5+7+10+11)\\n StdOut.println(maxFits(testWeights, 33)); // again, 33\\n StdOut.println(maxFits(testWeights, 32)); // 28 (7+10+11)\\n StdOut.println(maxFits(testWeights, 4)); // 0, nothing fits\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"maxFits\\", new int[]{2, 2, 2, 2, 2, 2}, 5);\\ntest(\\"maxFits\\", new int[]{1, 2, 4, 8, 16, 32, 64, 128}, 126);\\ntest(\\"maxFits\\", new int[]{7, 45, 21, 34, 99, 55}, 126);\\ntest(\\"maxFits\\", new int[]{621}, 126);\\ntest(\\"maxFits\\", new int[]{468, 246, 852, 456, 234, 567, 234, 159, 345, 258, 987, 333, 852, 234, 531, 963, 999, 642, 258, 741, 951, 456, 543, 357, 234, 456, 159, 876, 345, 234, 741}, 15000);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(70, '[email protected]', 'java/08-dynamicprogramming/Catalan', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nThe <a href=\\"http://en.wikipedia.org/wiki/Catalan_number\\">Catalan numbers</a>\\nare a fascinating sequence of integers that enumerate binary trees,\\ntriangulations, valid parenthesizations, and other ubiquituous combinatorial\\nfamilies. Their recursive definition is\\n<ul>\\n<li> $C_0 = 1$</li>\\n<li>for $\\\\displaystyle k > 0, C_k = \\\\sum_{i=0}^{k-1} (C_i \\\\times C_{k-i-1})$</li>\\n</li>\\n</ul>\\nIt is straightforward to write this as a recursive static method, \\nprovided as <tt>recursiveCat()</tt> for your reference below,\\nbut it is too slow. Write a static method <tt>dynamicCat(n)</tt>\\nthat computes the <i>n</i>th Catalan number using dynamic programming.\\n<p><i>Hint</i>: you will need nested loops.</p>\\n<p><i>Remark</i>: the code below is not optimal since it\\nre-computes the dynamic programming table over and over, but this is \\nnot a big deal for this exercise. There are also closed formulas\\nfor Catalan numbers.</p>\\n", "source_code": "\\n// this is just for reference. it is too slow for large n\\npublic static long recursiveCat(int n) {\\n if (n==0)\\n return 1;\\n long result = 0;\\n for (int i=0; i<n; i++)\\n result += recursiveCat(i)*recursiveCat(n-i-1);\\n return result;\\n}\\n\\npublic static long dynamicCat(int n) {\\n // intialize an array with indices from 0 to n\\n long[] dp = \\\\[new long[n+1]]\\\\;\\n // set the base case manually\\n \\\\[dp[0] = 1]\\\\;\\n\\n // compute the rest of the sequence\\n for (int k\\\\[=1; k<=n; k++]\\\\) {\\n\\\\[\\n dp[k] = 0; // not necessary, but for clarity\\n for (int i=0; i<k; i++)\\n dp[k] += dp[i]*dp[k-i-1];\\n]\\\\\\n }\\n return dp[n];\\n}\\n\\npublic static void main(String[] args) {\\n for (int i=0; i<=35; i++) {\\n StdOut.println(\\"The \\"+i+\\"th Catalan number is \\"+dynamicCat(i));\\n }\\n}\\n", "tests": "\\ntest(\\"dynamicCat\\", 0);\\ntest(\\"dynamicCat\\", 1);\\ntest(\\"dynamicCat\\", 2);\\ntest(\\"dynamicCat\\", 3);\\ntest(\\"dynamicCat\\", 4);\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(71, '[email protected]', 'java/08-dynamicprogramming/KnapsackBacktrack', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nThis is a continuation of the problem\\n<a href=\\"javascript:websheets.load(''java/08-dynamicprogramming/Knapsack'')\\">Knapsack</a>\\n(read it first). \\nLike in that problem, you will \\nwrite a static method that takes two arguments,\\n<tt>int[] itemWeights, int capacity</tt> representing item weights\\nyou can choose, and the maximum weight you can steal.\\nBut this time, we ask you to <i>find</i> and print the best solution, rather\\nthan just the weight of it. \\n\\n<p>\\nTo help accomplish this, we pre-compute an array <tt>canMake[][]</tt>,\\n a <tt>boolean[capacity+1][numItems+1]</tt> so that <tt>canMake[j][i]</tt>\\n is true if and only if we can make weight exactly <tt>j</tt> using\\n a subset of the items indexed <tt>0, 1, … i-1</tt>.\\n<p>\\nDetermine which items are members of this best solution.\\nPrint out their weights in the order they appear in the input.\\n(We''ll only test the input on instances with unique solutions,\\nso your outputs should exactly match ours.)\\n", "source_code": "\\n// void method, prints out value and description of best solution\\npublic static void printBest(int[] itemWeights, int capacity) {\\n int numItems = itemWeights.length; // for convenience\\n // canMake[j][i]: can we make weight exactly j, using a subset of the\\n // items 0, 1, ..., i-1?\\n boolean[][] canMake = new boolean[capacity+1][numItems+1];\\n\\n /****************************************************************/\\n /*** hidden code here correctly fills out canMake[][] for you ***/\\n /****************************************************************/\\n\\n\\\\hide[\\n canMake = new boolean[capacity+1][numItems+1];\\n\\n // if no items are allowed (i==0), the only weight we can make is 0\\n canMake[0][0] = true;\\n\\n for (int i=1; i<=numItems; i++) {\\n for (int j=0; j<=capacity; j++) {\\n // if we can get a total weight of j using a subset of the first\\n // i items, we can do the same with a subset of the first i-1,\\n // by simply not taking the ith item\\n canMake[j][i] = canMake[j][i-1];\\n\\n // if we take the ith item, to make weight j, the subset of items\\n // up to i must have weight j-itemWeights[i-1]\\n if (j >= itemWeights[i-1] && canMake[j-itemWeights[i-1]][i-1])\\n canMake[j][i] = true;\\n }\\n }\\n]\\\\ \\n // find biggest weight <= capacity that can be made\\n int optWeight = 0;\\n for (int j=0; j<=capacity; j++)\\n if (canMake[j][numItems]) optWeight = j;\\n StdOut.print(\\"Optimal weight is \\" + optWeight);\\n \\n // keep track of which items we must take in the optimal solution\\n boolean[] useItem = new boolean[numItems]; // initially all false\\n \\n // repeatedly reduce the number of items and see if we must use\\n // last item or not. update optWeight to the weight we must select\\n // from amongst the remaining items.\\n while (numItems > 0) { \\n // canMake[optWeight][numItems] is true. what caused it?\\n // it must be that either (a) canMake[optWeight][numItems-1] is true,\\n // or (b) canMake[optWeight-itemWeights[numItems-1]][numItems-1] is true.\\n // track back to whichever one of those is true.\\n if (\\\\[canMake[optWeight][numItems-1]]\\\\) { // case (a)\\n // we will *not* use item numItems-1\\n useItem[numItems-1] = \\\\[false]\\\\;\\n // optWeight does not change\\n }\\n else { // case (b)\\n // we have to use item numItems-1\\n \\\\[useItem[numItems-1] = true]\\\\;\\n // reduce optWeight by that item''s weight\\n optWeight -= \\\\[itemWeights[numItems-1]]\\\\;\\n }\\n // we''ve now reduced the bactracking to a smaller problem\\n numItems--;\\n }\\n // at the end, optWeight and numItems should be 0, and useItem is filled.\\n\\n StdOut.print(\\" and optimal solution uses: \\");\\n for (int i=0; i<useItem.length; i++) {\\n if (useItem[i]) StdOut.print(itemWeights[i]+\\" \\");\\n } \\n StdOut.println();\\n}\\n\\npublic static void main(String[] args) {\\n int[] testWeights = {5, 7, 10, 11};\\n printBest(testWeights, 20); // should be 18 (7+11)\\n printBest(testWeights, 100); // should be 33 (5+7+10+11)\\n printBest(testWeights, 33); // again, 33\\n printBest(testWeights, 32); // 28 (7+10+11)\\n printBest(testWeights, 4); // 0, nothing fits\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"printBest\\", new int[]{1, 2, 4, 8, 16, 32, 64, 128}, 126);\\ntest(\\"printBest\\", new int[]{7, 45, 21, 34, 99, 55}, 126);\\ntest(\\"printBest\\", new int[]{621}, 126);\\ntest(\\"printBest\\", new int[]{468, 246, 852, 456, 234, 567, 234, 159, 345, 258, 987, 333, 852, 234, 531, 963, 999, 642, 258, 741, 951, 456, 543, 357, 234, 456, 159, 876, 345, 234, 741}, 15000);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(72, '[email protected]', 'java/08-dynamicprogramming/PartitionCount', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nHow many ways can you distribute <i>n</i> different objects into <i>k</i>\\nnonempty bundles? Traditionally this number is denoted by \\n$\\\\displaystyle\\\\left\\\\{{n \\\\atop k}\\\\right\\\\},$ for example $\\\\displaystyle\\\\left\\\\{{4 \\\\atop 2}\\\\right\\\\}=7$ because 4 \\nobjects — call them A, B, C, D — can be distributed \\ninto two bundles \\nin the seven ways\\n<div style=''text-align:center''>A-BCD B-ACD C-ABD D-ABC AB-CD AC-BD AD-BC</div>\\nTo determine the value of these numbers, we will use the recurrence relation\\n<ul>\\n<li>for $\\\\displaystyle n,k>0, \\\\left\\\\{{n \\\\atop k}\\\\right\\\\} \\n= k\\\\left\\\\{{n-1 \\\\atop k}\\\\right\\\\}+\\\\left\\\\{{n-1 \\\\atop k-1}\\\\right\\\\}$</li>\\n<li>with the base cases $\\\\displaystyle\\\\left\\\\{{0\\\\atop 0}\\\\right\\\\}=1$ and\\nfor $\\\\displaystyle n>0, \\n\\\\left\\\\{{n \\\\atop 0}\\\\right\\\\}=0$ and for \\n$\\\\displaystyle k>0, \\\\left\\\\{{0 \\\\atop k}\\\\right\\\\}=0$\\n</li>\\n</ul>\\nWrite a static method <code>bundleWays(n, k)</code> that uses\\ndynamic programming to compute $\\\\displaystyle\\\\left\\\\{{n \\\\atop k}\\\\right\\\\}.$\\nUsing a recursive method will be too slow.\\n", "source_code": "\\npublic static long bundleWays(int n, int k) {\\n\\\\[\\n long[][] dp = new long[n+1][k+1];\\n \\n // base cases are automatically set to zero, except this one:\\n dp[0][0] = 1;\\n\\n // compute numbers from bottom-up\\n for (int i=1; i<=n; i++) {\\n for (int j=1; j<=k; j++) {\\n dp[i][j] = j*dp[i-1][j] + dp[i-1][j-1];\\n }\\n }\\n\\n return dp[n][k];\\n]\\\\\\n}\\n\\npublic static void main(String[] args) {\\n for (int n=0; n<=5; n++) {\\n for (int k=0; k<=n; k++)\\n StdOut.printf(\\"{%d %d} = %-3d \\", n, k, bundleWays(n, k));\\n StdOut.println();\\n }\\n}\\n", "tests": "\\ntest(\\"bundleWays\\", 4, 2);\\ntestMain();\\ntest(\\"bundleWays\\", 25, 2);\\ntest(\\"bundleWays\\", 25, 9);\\ntest(\\"bundleWays\\", 25, 10);\\ntest(\\"bundleWays\\", 25, 11);\\ntest(\\"bundleWays\\", 25, 20);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(73, '[email protected]', 'java/11-classes/Name', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nThe <tt>Name</tt> class stores someone''s first initial and last name.\\nComplete the missing line in the constructor.\\n", "source_code": "\\n// instance variables\\nprivate char firstInitial;\\nprivate String lastName;\\n\\n// constructor, takes two parameters\\npublic Name(char firstInit, String lastName) {\\n // instance variable firstInitial copies constructor parameter firstInit\\n firstInitial = firstInit;\\n\\n // instance variable lastName copies constructor parameter lastName\\n \\\\[this.lastName]\\\\ = \\\\[lastName]\\\\;\\n\\n // Hints:\\n\\n // \\"lastName = lastName;\\" won''t work;\\n // it copies the parameter into itself.\\n\\n // \\"String lastName = lastName;\\" won''t work; it tries to create a local \\n // variable in the constructor (rather than affecting the instance).\\n\\n // You will need to use the Java keyword \\"this\\".\\n}\\n\\n// print name of person corresponding to this instance\\npublic void display() {\\n StdOut.println(firstInitial + \\". \\" + lastName);\\n}\\n\\n// test client\\npublic static void main(String[] args) {\\n Name n = new Name(''R'', \\"Sedgewick\\");\\n n.display();\\n}\\n", "tests": "\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(74, '[email protected]', 'java/11-classes/Clicker', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWhen you go in to a bar or place with a seating capacity, often\\nthe person at the front has a \\"clicker\\" to keep track of how many \\npeople go in or out. Build a <tt>Clicker</tt> class to do this; it should \\nhave the following API.\\n<ul>\\n<li><tt>public Clicker() // constructor, make new clicker with value 0</tt>\\n<li><tt>public void inc() // add one to the current value</tt>\\n<li><tt>public void dec() // subtract one from the current value</tt>\\n<li><tt>public int curr() // return the current value</tt>\\n</ul>\\nNegative clicker values should be permitted.\\n", "source_code": "\\n// private instance variable(s) you will use are declared here:\\n\\\\[\\nprivate int value; // currently held value\\n]\\\\\\n\\n// constructor, make new clicker with value 0\\npublic Clicker() {\\n\\\\[\\n value = 0;\\n]\\\\\\n}\\n// add one to the current value\\npublic void inc() {\\n\\\\[\\n value++;\\n]\\\\\\n}\\n\\n// subtract one from the current value\\n\\\\[\\npublic void dec() {\\n value--;\\n}\\n]\\\\\\n\\n// return the current value\\n\\\\[\\npublic int curr() {\\n return value;\\n}\\n]\\\\\\n\\n// testing suite\\npublic static void main(String[] args) {\\n Clicker myClick = new Clicker();\\n StdOut.println(myClick.curr()); // should be 0\\n myClick.inc();\\n myClick.inc();\\n StdOut.println(myClick.curr()); // should be 2\\n myClick.dec();\\n myClick.dec();\\n myClick.dec();\\n StdOut.println(myClick.curr()); // should be -1\\n\\n Clicker clickMore = new Clicker();\\n StdOut.println(clickMore.curr()); // should be 0\\n clickMore.inc();\\n clickMore.inc();\\n clickMore.inc();\\n StdOut.println(clickMore.curr()); // should be 3\\n\\n // the next line won''t work if you used static variables\\n StdOut.println(myClick.curr()); // should still be -1\\n}\\n", "tests": "\\nsaveAs = \\"attendance\\";\\ntestConstructor();\\ntestOn(\\"attendance\\", \\"curr\\");\\ntestOn(\\"attendance\\", \\"inc\\");\\ntestOn(\\"attendance\\", \\"inc\\");\\ntestOn(\\"attendance\\", \\"curr\\");\\ntestOn(\\"attendance\\", \\"dec\\");\\ntestOn(\\"attendance\\", \\"curr\\");\\ntestOn(\\"attendance\\", \\"curr\\");\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(75, '[email protected]', 'java/11-classes/Vector', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>Booksite section 3.4.</i> This class is an implementation of a vector of real numbers.\\nIt should be immutable: once the client\\n initializes a <tt>Vector</tt>, they cannot change any of its fields\\n either directly or indirectly. \\nFor example, the instance method <tt>double cartesian(int i)</tt> will return the <tt>i</tt>th coordinate,\\nbut we will never allow the client to directly access the array in which we store the data, because\\nwe don''t want the client to be able to change it.\\n", "source_code": "\\npublic class Vector {\\n \\n private\\\\[int N]\\\\; // length of the vector\\n private double[] data; // array of vector''s components\\n\\n // create the zero vector of length N\\n public Vector(int N) {\\n this.N = N;\\n this.data = new double[N];\\n }\\n\\n // create a vector from an array\\n public Vector(double[] d) {\\n \\\\[N = d.length;]\\\\ // initialize the length\\n\\n // make defensive copy so that client can''t alter our copy of data[]\\n\\\\[\\n this.data = new double[N]; // using \\"this\\" on these lines is optional\\n for (int i = 0; i < N; i++)\\n this.data[i] = d[i];\\n\\\\show:\\n double[] data = d; //<-- this isn''t it!\\n\\n\\n]\\\\\\n }\\n\\n // return this + that\\n public Vector plus(Vector that) {\\n if (this.N != that.N) \\n throw new RuntimeException(\\"Dimensions don''t agree\\");\\n Vector c = new Vector(N);\\n for (int i = 0; i < N; i++)\\n c.data[i] = this.data[i] + that.data[i];\\n return c;\\n }\\n\\n // return this - that\\n public Vector minus(Vector that) {\\n if (this.N != that.N) \\n throw new RuntimeException(\\"Dimensions don''t agree\\");\\n Vector c = new Vector(N);\\n for (int i = 0; i < N; i++)\\n c.data[i] = this.data[i] - that.data[i];\\n return c;\\n }\\n\\n // create and return a new object whose value is (this * factor)\\n public Vector times(double factor) {\\n Vector c = new Vector(N);\\n for (int i = 0; i < N; i++)\\n c.data[i] = factor * data[i];\\n return c;\\n }\\n\\n // return the corresponding unit vector\\n public Vector direction() {\\n if (this.magnitude() == 0.0) \\n throw new RuntimeException(\\"Zero-vector has no direction\\");\\n return this.times(1.0 / this.magnitude());\\n }\\n\\n // return the inner product of Vectors this and that\\n public double dot(Vector that) {\\n\\\\[\\n if (this.N != that.N) \\n throw new RuntimeException(\\"Dimensions don''t agree\\");\\n double sum = 0.0;\\n for (int i = 0; i < N; i++)\\n sum = sum + (this.data[i] * that.data[i]);\\n return sum;\\n\\\\show:\\n return 0; // fill this in!\\n\\n\\n\\n\\n \\n]\\\\\\n // remark: is used with \\"this\\" in the magnitude() method\\n }\\n\\n // return the Euclidean norm of this Vector\\n public double magnitude() {\\n // magnitude is dot product with self, square rooted\\n return Math.sqrt(this.dot(this));\\n }\\n\\n // return the corresponding coordinate\\n public double cartesian(int i) {\\n return data[i];\\n }\\n\\n // return a string representation of the vector\\n // e.g. (1.0, 2.0, 6.0); format specifiers not required\\n public String toString() {\\n\\\\[\\n String s = \\"(\\";\\n for (int i = 0; i < N; i++) {\\n s += data[i];\\n if (i < N-1) s+= \\", \\"; \\n }\\n return s + \\")\\";\\n\\\\show:\\n return \\"\\"; // fill this in!\\n\\n\\n\\n\\n \\n]\\\\\\n }\\n\\n // partial test client\\n public static void main(String[] args) {\\n System.out.println(\\"Immutability test:\\");\\n // is it really immutable?\\n double[] c = {3.0, 4.0};\\n Vector v = new Vector(c);\\n System.out.println(\\"v = \\" + v); // should be (3.0, 4.0)\\n c[0] = 0;\\n System.out.println(\\"v = \\" + v); // should still be (3.0, 4.0)!!\\n }\\n}\\n", "tests": "\\n\\ndefaultOptions.cloneForStudent = false;\\ndouble[] nums = new double[]{3, -4};\\nsaveAs = \\"nums\\";\\nstore(nums);\\nsaveAs = \\"velocity\\";\\ntestConstructor(var(\\"nums\\"));\\ndefaultOptions.cloneForStudent = true;\\n\\ntestOn(\\"velocity\\", \\"cartesian\\", 0);\\ntestOn(\\"velocity\\", \\"cartesian\\", 1);\\nremark(\\"Setting <tt>nums[0] = 100</tt> to check for aliasing…\\");\\nnums[0] = 100;\\ntestOn(\\"velocity\\", \\"cartesian\\", 0);\\n\\n\\ntestOn(\\"velocity\\", \\"magnitude\\");\\ntestOn(\\"velocity\\", \\"toString\\");\\ntestOn(\\"velocity\\", \\"dot\\", var(\\"velocity\\"));\\ntestMain();\\nsaveAs = \\"x\\";\\ntestConstructor(new double[]{1, 2, 3, 4});\\ntestOn(\\"x\\", \\"toString\\");\\nsaveAs = \\"y\\";\\ntestConstructor(new double[]{5, 2, 4, 1});\\ntestOn(\\"y\\", \\"toString\\");\\nsaveAs = \\"sum\\";\\ntestOn(\\"x\\", \\"plus\\", var(\\"y\\"));\\ntestOn(\\"sum\\", \\"toString\\");\\nsaveAs = \\"scaled\\";\\ntestOn(\\"x\\", \\"times\\", 10.0);\\ntestOn(\\"scaled\\", \\"toString\\");\\ntestOn(\\"x\\", \\"magnitude\\");\\ntestOn(\\"x\\", \\"dot\\", var(\\"y\\"));\\nsaveAs = \\"yx\\";\\ntestOn(\\"x\\", \\"minus\\", var(\\"y\\"));\\ntestOn(\\"yx\\", \\"magnitude\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(76, '[email protected]', 'java/11-classes/CountingSort', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<b>You have to solve the <a href=''javascript:websheets.load(\\"java/11-classes/Clicker\\")''>Clicker</a> websheet before this one will work.</b> \\n<p>\\nWrite a program <tt>CountingSort</tt>, a client of <tt><a href=\\"javascript:websheets.load(''java/11-classes/Clicker'')\\">Clicker</a></tt>, \\nthat sorts a list of single-digit numbers.\\nOn standard input, you will get a list of numbers like\\n<pre>\\n0 2 4 3 2 2 9 8 1 0\\n</pre>\\nYour program should use an array of ten <tt>Clicker</tt> objects to keep track of how many of each digit you saw. At the end, print out each number the number of times it was seen, in this case it would be\\n<pre>\\n0 0 1 2 2 2 3 4 8 9\\n</pre>\\nRemember that <tt>Clicker</tt> has the following API:\\n<ul>\\n<li><tt>public Clicker() // constructor, make new clicker with value 0</tt>\\n<li><tt>public void inc() // add one to the current value</tt>\\n<li><tt>public void dec() // subtract one from the current value</tt>\\n<li><tt>public int curr() // return the current value</tt>\\n</ul>\\n", "dependencies": "[\\"java/11-classes/Clicker\\"]", "source_code": "\\npublic static void main(String[] args) {\\n Clicker[] counts = \\\\[new Clicker[10];]\\\\ // array of Clickers\\n\\n // initialize them all\\n\\\\[\\n for (int i=0; i<10; i++) {\\n counts[i] = new Clicker(); // initialize one\\n }\\n]\\\\\\n\\n // read each digit\\n while (!StdIn.isEmpty()) {\\n int digit = StdIn.readInt();\\n // increment the right clicker\\n\\\\[\\n counts[digit].inc();\\n]\\\\\\n }\\n\\n // print out each number once for each time it was seen\\n for (int i=0; i<10; i++) {\\n while (counts[i].curr() > 0) {\\n StdOut.print(i+\\" \\");\\n counts[i].dec();\\n }\\n }\\n StdOut.println();\\n}\\n", "tests": "\\nstdin = \\"0 2 4 3 2 2 9 8 1 0\\";\\ntestMain();\\nstdin = \\"6\\";\\ntestMain();\\nstdin = \\"3 4 5 5 5 4 3 4 4 5 3 4 3 5 4\\";\\ntestMain();\\nstdin = \\"0 1 3 6 0 0 7 4 3 5 6 7 8 7 4 3 2 2 3 4 5 6 8 9 8 5 1 1 1 1 2 2 3 6 8 7 9 0 0 5\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(77, '[email protected]', 'java/11-classes/Recorder', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nMake a short recorder that can store a message to be played back. It should have the following API:\\n<ul>\\n<li><tt>public Recorder(String initialMsg) // create new recorder w/this message initially\\n<li><tt>public String playback() // return the saved message\\n<li><tt>public void record(String newMsg) // save this message instead</tt>\\n</ul>\\n", "source_code": "\\n// private instance variable representing the message\\nprivate \\\\[String]\\\\ savedMsg;\\n\\n// constructor\\npublic Recorder(\\\\[String initialMsg]\\\\) {\\n // save the initial message\\n \\\\[savedMsg = initialMsg;]\\\\\\n}\\n\\n// accessor: get back the saved message\\n \\\\[public]\\\\ String \\\\[playback()]\\\\ {\\n return \\\\[savedMsg]\\\\;\\n}\\n\\n// mutator: replace the saved message\\n\\\\[\\npublic void record(String newMsg) {\\n // now the new message is saved (the old one is forgotten)\\n savedMsg = newMsg;\\n}\\n]\\\\\\n\\n// test client\\npublic static void main(String[] args) {\\n Recorder r = new Recorder(\\"hello\\");\\n StdOut.println(\\"The recorded message is: \\" + r.playback());\\n StdOut.println(\\"Let''s play it again: \\" + r.playback());\\n r.record(\\"bonjour\\");\\n StdOut.println(\\"The new message is: \\" + r.playback()); \\n Recorder card = new Recorder(\\"happy birthday!\\");\\n StdOut.println(\\"The new recorder says: \\" + card.playback()); \\n StdOut.println(\\"The old one still says: \\" + r.playback()); \\n}\\n", "tests": "\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(78, '[email protected]', 'java/11-classes/CountingSort_nodep', '{"sharing": "open", "attempts_until_ref": "1", "description": "Write a program <tt>CountingSort</tt>, a client of <tt><a href=\\"javascript:websheets.load(''java/11-classes/Clicker'')\\">Clicker</a></tt>, \\nthat sorts a list of single-digit numbers.\\nOn standard input, you will get a list of numbers like\\n<pre>\\n0 2 4 3 2 2 9 8 1 0\\n</pre>\\nYour program should use an array of ten <tt>Clicker</tt> objects to keep track of how many of each digit you saw. At the end, print out each number the number of times it was seen, in this case it would be\\n<pre>\\n0 0 1 2 2 2 3 4 8 9\\n</pre>\\nRemember that <tt>Clicker</tt> has the following API:\\n<ul>\\n<li><tt>public Clicker() // constructor, make new clicker with value 0</tt>\\n<li><tt>public void inc() // add one to the current value</tt>\\n<li><tt>public void dec() // subtract one from the current value</tt>\\n<li><tt>public int curr() // return the current value</tt>\\n</ul>\\n", "classname": "CountingSort", "source_code": "\\npublic static void main(String[] args) {\\n Clicker[] counts = \\\\[new Clicker[10];]\\\\ // array of Clickers\\n\\n // initialize them all\\n\\\\[\\n for (int i=0; i<10; i++) {\\n counts[i] = new Clicker(); // initialize one\\n }\\n]\\\\\\n\\n // read each digit\\n while (!StdIn.isEmpty()) {\\n int digit = StdIn.readInt();\\n // increment the right clicker\\n\\\\[\\n counts[digit].inc();\\n]\\\\\\n }\\n\\n // print out each number once for each time it was seen\\n for (int i=0; i<10; i++) {\\n while (counts[i].curr() > 0) {\\n StdOut.print(i+\\" \\");\\n counts[i].dec();\\n }\\n }\\n StdOut.println();\\n}\\n\\\\hide[\\npublic static class Clicker {\\n // private instance variable(s) you will use are declared here:\\n private int value; // currently held value\\n \\n // constructor, make new clicker with value 0\\n public Clicker() {\\n value = 0;\\n }\\n // add one to the current value\\n public void inc() {\\n value++;\\n }\\n \\n // subtract one from the current value\\n public void dec() {\\n value--;\\n }\\n \\n // return the current value\\n public int curr() {\\n return value;\\n }\\n \\n // testing suite\\n public static void main(String[] args) {\\n Clicker myClick = new Clicker();\\n StdOut.println(myClick.curr()); // should be 0\\n myClick.inc();\\n myClick.inc();\\n StdOut.println(myClick.curr()); // should be 2\\n myClick.dec();\\n myClick.dec();\\n myClick.dec();\\n StdOut.println(myClick.curr()); // should be -1\\n \\n Clicker clickMore = new Clicker();\\n StdOut.println(clickMore.curr()); // should be 0\\n clickMore.inc();\\n clickMore.inc();\\n clickMore.inc();\\n StdOut.println(clickMore.curr()); // should be 3\\n \\n // the next line won''t work if you used static variables\\n StdOut.println(myClick.curr()); // should still be -1\\n }\\n}\\n]\\\\\\n", "tests": "\\nstdin = \\"0 2 4 3 2 2 9 8 1 0\\";\\ntestMain();\\nstdin = \\"6\\";\\ntestMain();\\nstdin = \\"3 4 5 5 5 4 3 4 4 5 3 4 3 5 4\\";\\ntestMain();\\nstdin = \\"0 1 3 6 0 0 7 4 3 5 6 7 8 7 4 3 2 2 3 4 5 6 8 9 8 5 1 1 1 1 2 2 3 6 8 7 9 0 0 5\\";\\ntestMain();\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(79, '[email protected]', 'java/11-classes/CombinationLock', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nCreate a ''combination lock'' which has a <tt>String</tt> password that you can change,\\nwhich you can lock and unlock. It should have this API:\\n<ul>\\n<style>li {margin-bottom: 9pt;} </style>\\n<li><tt>\\n// construct new lock with this initial password, initially unlocked<br>\\npublic CombinationLock(String initpass) \\n</tt>\\n<li><tt>// is this lock currently locked?<br>public boolean isLocked()</tt>\\n<li><tt>// if current password equals attempt, unlock (no effect if already unlocked)<br>\\npublic void tryUnlock(String attempt)</tt>\\n<li><tt>// make this lock become locked (no effect if already locked)<br>public void lock()</tt>\\n<li><tt>// if locked, print \\"ERROR: LOCKED\\" else change password to newpass<br>\\npublic void changePassword(String newpass)</tt>\\n</ul>\\nMake sure you use <tt>.equals()</tt> to compare strings in <tt>tryUnlock()</tt>, not the <tt>==</tt> operator. \\n<i>Note: in practice, passwords are not stored directly, but only as <a href=\\"http://en.wikipedia.org/wiki/Cryptographic_hash_function#Password_verification\\">hashes</a>.", "source_code": "\\\\[\\nprivate boolean locked; // is it locked right now?\\nprivate String password; // current password\\n\\n// construct new lock with this initial password, initially unlocked\\npublic CombinationLock(String initpass) {\\n password = initpass; // save password\\n locked = false; // initially unlocked\\n}\\n\\n// is this lock currently locked? \\npublic boolean isLocked() {\\n return locked;\\n}\\n\\n// if current password equals attempt, unlock (no effect if already unlocked)\\npublic void tryUnlock(String attempt) {\\n if (attempt.equals(password))\\n locked = false;\\n}\\n\\n// make this lock become locked (no effect if already locked)\\npublic void lock() {\\n locked = true;\\n}\\n\\n// if locked, print \\"ERROR: LOCKED\\" else change password to newpass\\npublic void changePassword(String newpass) {\\n if (locked) \\n StdOut.println(\\"ERROR: LOCKED\\");\\n else\\n password = newpass;\\n}\\n]\\\\\\n", "tests": "\\nsaveAs = \\"myLock\\";\\ntestConstructor(\\"0000\\");\\ntestOn(\\"myLock\\", \\"isLocked\\");\\ntestOn(\\"myLock\\", \\"lock\\");\\ntestOn(\\"myLock\\", \\"changePassword\\", \\"my-new-password\\");\\ntestOn(\\"myLock\\", \\"isLocked\\");\\ntestOn(\\"myLock\\", \\"tryUnlock\\", \\"2014\\");\\ntestOn(\\"myLock\\", \\"isLocked\\");\\ntestOn(\\"myLock\\", \\"tryUnlock\\", \\"0000\\");\\ntestOn(\\"myLock\\", \\"isLocked\\");\\ntestOn(\\"myLock\\", \\"changePassword\\", \\"hello123\\");\\ntestOn(\\"myLock\\", \\"isLocked\\");\\ntestOn(\\"myLock\\", \\"lock\\");\\ntestOn(\\"myLock\\", \\"isLocked\\");\\ntestOn(\\"myLock\\", \\"tryUnlock\\", \\"0000\\");\\ntestOn(\\"myLock\\", \\"isLocked\\");\\ntestOn(\\"myLock\\", \\"tryUnlock\\", \\"hello123\\");\\ntestOn(\\"myLock\\", \\"isLocked\\");\\ntestOn(\\"myLock\\", \\"lock\\");\\ntestOn(\\"myLock\\", \\"isLocked\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(80, '[email protected]', 'java/11-classes/Interval', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nCreate a class to model intervals of the real line. Each interval has a minimum and a maximum, and contains\\nall of the real numbers between its minimum and its maximum.\\n(This kind of object has applications in\\ngeometry, scheduling, and text editing.)\\nFor example, the interval [3, 6] from 3 to 6 contains 3, π, 5, and 6, but it does not contain 6.21.\\n(All intervals we deal with will include both endpoints.) \\nYour code must produce the following API:\\n<pre>\\npublic Interval(double lo, double hi) // construct interval from lo to hi; but \\n // throw a RuntimeException if lo > hi\\nString toString() // return text representation, e.g. \\"[3, 6]\\"\\nboolean contains(double x) // does this interval contain x?\\nboolean intersects(Interval other) // do these intervals contain a common point?\\nboolean subsetOf(Interval other) // is this interval a subset of the other?\\nboolean supersetOf(Interval other) // is this interval a superset of the other?\\n</pre>\\nFor <tt>subsetOf</tt>, the containment doesn''t have to be strict. For example\\n[3, 4] is a subset of [3, 4.5], and every interval is a subset of itself.\\n", "source_code": "\\n// instance variables\\n\\\\[\\ndouble lo; // minimum value in this Interval\\ndouble hi; // maximum value in this Interval\\n]\\\\\\n// constructor\\n\\\\[\\npublic Interval(double lo, double hi) {\\n if (hi < lo)\\n throw new RuntimeException(\\"Empty interval!\\");\\n\\n // copy data from constructor parameters to instance vars\\n this.lo = lo;\\n this.hi = hi;\\n}\\n]\\\\\\n// text representation\\npublic String toString() {\\n // if you want, use String.format(\\"%.6e\\", ...);\\n\\\\[\\n return String.format(\\"[%.6e, %.6e]\\", lo, hi);\\n]\\\\\\n}\\n// other instance methods\\n\\\\[\\n// is x in this interval?\\npublic boolean contains(double x) {\\n return x >= lo && x <= hi;\\n}\\n\\n// do these intervals intersect?\\npublic boolean intersects(Interval other) {\\n if (this.lo > other.hi) return false; // this is to the right of other\\n if (other.lo > this.hi) return false; // other is to the right of this\\n return true; // otherwise, they intersect\\n}\\n\\n// is other a subset of this interval?\\npublic boolean subsetOf(Interval other) {\\n return other.lo <= lo && other.hi >= hi;\\n}\\n]\\\\\\n// use \\"this\\" to just reuse previous logic\\npublic boolean supersetOf(Interval other) {\\n return other.subsetOf(this);\\n}\\n\\n// test client\\npublic static void main(String[] args) {\\n // counting years BCE to avoid negative signs\\n Interval mesozoic = new Interval(66E6, 252E6);\\n Interval jurassic = new Interval(145E6, 201E6);\\n StdOut.println(\\"The Mesozoic is \\" + mesozoic.toString());\\n StdOut.println(\\"The Jurassic is \\" + jurassic); // implicit toString\\n StdOut.println(mesozoic.intersects(jurassic)); // true\\n StdOut.println(jurassic.subsetOf(mesozoic)); // true\\n}\\n", "tests": "\\ntestMain();\\nsaveAs = \\"persianEmpire\\"; testConstructor(-550.0, 651.0);\\ntestOn(\\"persianEmpire\\", \\"toString\\");\\ntestOn(\\"persianEmpire\\", \\"contains\\", 126.0);\\ntestOn(\\"persianEmpire\\", \\"contains\\", 6126.0);\\nsaveAs = \\"tangDynasty\\"; testConstructor(623.0, 907.0);\\ntestOn(\\"tangDynasty\\", \\"contains\\", 126.0);\\ntestOn(\\"persianEmpire\\", \\"intersects\\", var(\\"tangDynasty\\"));\\ntestOn(\\"persianEmpire\\", \\"subsetOf\\", var(\\"persianEmpire\\"));\\ntestOn(\\"persianEmpire\\", \\"intersects\\", var(\\"persianEmpire\\"));\\nsaveAs = \\"alfredTheGreat\\"; testConstructor(849.0, 899.0);\\ntestOn(\\"alfredTheGreat\\", \\"contains\\", 899.0);\\ntestOn(\\"alfredTheGreat\\", \\"supersetOf\\", var(\\"tangDynasty\\"));\\ntestOn(\\"alfredTheGreat\\", \\"subsetOf\\", var(\\"tangDynasty\\"));\\ntestOn(\\"alfredTheGreat\\", \\"supersetOf\\", var(\\"persianEmpire\\"));\\ntestOn(\\"persianEmpire\\", \\"intersects\\", var(\\"alfredTheGreat\\"));\\nexpectException = true; testConstructor(2013.0, -2013.0);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(81, '[email protected]', 'java/11-classes/Monomial', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nCreate a class Monomial that represents functions of the form $x \\\\mapsto ax^b$, \\nwhere <i>a</i> is a real number and <i>b</i> is an integer. It should have the following API:\\n<pre>\\npublic Monomial(double coeff, int exp)// constructor, create a new monomial a*x^b\\npublic double evaluate(double x) // return the value of a*x^b\\npublic String toString() // return the String \\"a*x^b\\"\\n</pre>\\nWe will test your code by running a pre-defined <tt>main</tt> method \\nthat takes a list of command-line arguments and evaluates them on several\\nmonomials.\\n", "source_code": "\\n// private instance variables\\n\\\\[\\nprivate double a;\\nprivate int b;\\n]\\\\\\n\\n// public methods (API)\\n\\\\[\\n// constructor, create a new monomial a*x^b\\npublic Monomial(double coeff, int exp) {\\n a = coeff;\\n b = exp;\\n}\\n\\n// return the value of a*x^b\\npublic double evaluate(double x) {\\n return a*Math.pow(x, b);\\n}\\n\\n// return the String \\"a*x^b\\"\\n]\\\\ \\n\\\\[public String]\\\\ toString() {\\n // use the rounding to 3 decimals indicated below\\n return String.format(\\"%.3f\\", \\\\[a]\\\\) + \\\\[\\"*x^\\" + b]\\\\;\\n}\\n\\n// test main: print out a table of several monomials'' values, evaluated for\\n// different values of x specified as command-line arguments\\npublic static void main(String[] args) {\\n Monomial negativeX = new Monomial(-1.0, 1);\\n Monomial squaredX = new Monomial(1.0, 2);\\n Monomial half = new Monomial(0.5, 0);\\n Monomial scaledRecip = new Monomial(-12.6, -1);\\n \\n // print out a header row. toString() is called implicitly!\\n StdOut.printf(\\"%12s%12s%12s%12s%14s\\\\n\\", \\n \\"x\\", negativeX, squaredX, half, scaledRecip); \\n\\n for (int i=0; i<args.length; i++) {\\n // print out a row of the table\\n double x = Double.parseDouble(args[i]);\\n StdOut.printf(\\"%12.3f%12.3f%12.3f%12.3f%14.3f\\\\n\\", \\n x, \\n negativeX.evaluate(x), \\n squaredX.evaluate(x),\\n half.evaluate(x),\\n scaledRecip.evaluate(x)); \\n }\\n}\\n", "tests": "\\nsaveAs = \\"mono\\";\\ntestConstructor(4.0, 3);\\ntestOn(\\"mono\\", \\"toString\\");\\ntestOn(\\"mono\\", \\"evaluate\\", 4.5);\\ntestMain(1, 2, 6, 126);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(82, '[email protected]', 'java/05-staticmethods/Positive', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a class <code>Positive</code> with a static method <code>isPositive()</code>\\nthat takes one integer argument, and returns the boolean value <code>true</code> if \\nthe argument is positive, and <code>false</code> otherwise.", "source_code": "\\n\\npublic static \\\\[boolean]\\\\ \\\\[isPositive]\\\\(\\\\[int]\\\\ \\\\[x]\\\\) {\\n\\\\[\\n return (x > 0);\\n]\\\\\\n}\\n\\n// basic tests\\npublic static void main (String[] args) {\\n StdOut.println(\\"126 is positive? \\" + isPositive(126));\\n StdOut.println(\\"-126 is positive? \\" + isPositive(-126));\\n StdOut.println(\\"0 is positive? \\" + isPositive(0));\\n StdOut.println(\\"1 or -1 is positive? \\" \\n + (isPositive(-1) || isPositive(1)));\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"isPositive\\", randgen.nextInt(100)+1);\\ntest(\\"isPositive\\", -randgen.nextInt(100)-1);\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(83, '[email protected]', 'java/05-staticmethods/Summer', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program <code>Summer</code> whose API contains\\ntwo overloaded (same-name) public static methods\\n<ul>\\n<li>\\n<code>sum(double[] a)</code>,\\nwhich returns the sum of the elements of <code>a</code>\\n</li>\\n<li>\\n<code>sum(int[] a)</code>,\\nwhich returns the sum of the elements of <code>a</code>\\n</li>\\n</ul>\\n", "source_code": "\\n\\\\[\\npublic static double sum(double[] a) {\\n double result = 0;\\n for (int i=0; i < a.length; i++)\\n result += a[i]; \\n return result;\\n}\\n\\npublic static int sum(int[] a) {\\n int result = 0;\\n for (int i=0; i < a.length; i++)\\n result += a[i]; \\n return result;\\n}\\n]\\\\\\n// basic tests\\npublic static void main(String[] args) {\\n StdOut.println(sum(new int[]{1, 2, 6}));\\n StdOut.println(sum(new double[]{Math.PI, Math.E, Math.log(2)}));\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"sum\\", (Object)new int[]{-5, -4, -3, -2, -1});\\ntest(\\"sum\\", (Object)new double[]{1E10, 1E11, 1E12});\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(84, '[email protected]', 'java/05-staticmethods/Boxed', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a class <code>Boxed</code> whose API has two public static methods:\\n<ul>\\n<li>Write a method <code>repeat()</code> that takes a string argument and an integer argument,\\nand returns the <code>String</code> obtained by repeating the string that many times.\\nFor example <code>repeat(\\"hots\\", 2)</code> should return <code>\\"hotshots\\"</code>\\n</li>\\n<li>Using <code>repeat()</code>, write a method <code>boxedPrint()</code> that takes a string argument, and prints\\nit out surrounded by a box of asterisks. \\nFor example, <code>boxedPrint(\\"Hello, World!\\")</code> should cause the following\\ntext to be sent to standard output:\\n<pre>\\n***************\\n*Hello, World!*\\n***************\\n</pre>\\nTo get\\nthe <b>length</b> of a String <code>stringVar</code>, use <code>stringVar.length()</code>.\\n</li>\\n</ul>\\n", "source_code": "\\npublic static\\\\[String]\\\\repeat(\\\\[String S, int times]\\\\) {\\n\\\\[\\n String result = \\"\\";\\n for (int i=0; i<times; i++)\\n result += S;\\n return result;\\n]\\\\\\n}\\n\\npublic static\\\\[void]\\\\boxedPrint(\\\\[String S]\\\\) {\\n\\\\[\\n StdOut.println(repeat(\\"*\\", S.length()+2));\\n StdOut.println(\\"*\\"+S+\\"*\\");\\n StdOut.println(repeat(\\"*\\", S.length()+2));\\n]\\\\\\n}\\n\\n//basic tests\\npublic static void main(String[] args) {\\n StdOut.println(repeat(\\"jar\\", 2));\\n StdOut.println(repeat(\\"he\\", 4));\\n boxedPrint(\\"Hello, World!\\");\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"repeat\\", \\"meow\\", 4);\\ntest(\\"repeat\\", \\"nothing\\", 0);\\ntest(\\"boxedPrint\\", \\"|||stars and stripes|||\\");\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(85, '[email protected]', 'java/05-staticmethods/Find', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<div><i>This exercise practices using arrays as arguments, \\nand using more than one <code>return</code> statement.\\n</i></div>\\n<div>Write a class <code>Find</code> with a method <code>find()</code>\\nthat takes two arguments, an integer <code>needle</code>\\nand an array of integers <code>haystack</code>. If <code>needle</code>\\nis one of the elements of <code>haystack</code>, then return the\\nindex at which it appears<sup>*</sup>. (For example, if the initial\\nelement of <code>haystack</code> equals <code>needle</code>, you should\\nreturn <code>0</code> since <code>haystack[0] == needle</code>.)\\nOtherwise, if <code>needle</code>\\nis not one of the elements of the array, return <code>-1</code>.\\n</div>\\n<div><sup>*</sup>: if it occurs multiple times, return the lowest-indexed\\nposition</div>", "source_code": "\\npublic static int find(\\\\[int]\\\\ needle, \\\\[int[]]\\\\ haystack) {\\n int n = haystack.length;\\n for (\\\\[int i=0; i<n; i++]\\\\) {\\n // check if this element of haystack equals needle\\n if (\\\\[ haystack[i] == needle ]\\\\) \\n // quit immediately with this index\\n return \\\\[i]\\\\;\\n }\\n // if we get this far, the needle was not found\\n return -1;\\n}\\n\\npublic static void main(String[] args) {\\n int[] arr = {1, 2, 6};\\n System.out.println(\\"index of 1 in arr: \\" + find(1, arr)); // should be 0\\n System.out.println(\\"index of 2 in arr: \\" + find(2, arr)); // should be 1\\n System.out.println(\\"index of 6 in arr: \\" + find(6, arr)); // should be 2\\n System.out.println(\\"index of 4 in arr: \\" + find(4, arr)); // should be -1\\n}\\n", "tests": "\\ntestMain();\\ntest(\\"find\\", 9, new int[]{4, 9, 6, 9, 8});\\ntest(\\"find\\", 126, new int[]{});\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(86, '[email protected]', 'java/05-staticmethods/Yarra', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<div>Part 1. Write a method <code>reverse1()</code> that takes a String array\\nas an argument, and returns a\\n<i>new</i> String array which holds the reverse of the original. \\n<b>This method should not alter the original array</b>. \\n</div>\\n<div>Part 2. \\nWrite a function <code>reverse2()</code> to\\nreverse the elements in a String array passed to the method. The\\nmethod should not return anything. Hint: you can use the code from page 89 or\\nBooksite Ex. 1.4.4. (Web Exercise 2.1.35)", "source_code": "\\npublic \\\\[static String[]]\\\\ reverse1(\\\\[String[] a]\\\\) {\\n\\\\[\\n int n = a.length; // just for convenience\\n String[] result = new String[n];\\n for (int i=0; i<n; i++)\\n result[i] = a[n-i-1]; // map 0 to n-1, 1 to n-2, ...\\n return result;\\n]\\\\\\n}\\n\\npublic \\\\[static void]\\\\ reverse2(\\\\[String[] a]\\\\) {\\n\\\\[\\n int n = a.length; // just for convenience\\n // swap 0 with n-1, 1 with n-2, ...\\n for (int i=0; i < n/2; i++) {\\n String tmp = a[i];\\n a[i] = a[n-i-1];\\n a[n-i-1] = tmp;\\n }\\n]\\\\\\n}\\n\\n// basic tests\\npublic static void main(String[] args) {\\n String[] test = {\\"this\\", \\"is\\", \\"a\\", \\"test\\"};\\n String[] tset = reverse1(test);\\n StdOut.println(\\"after calling reverse1, test is: \\"\\n + java.util.Arrays.toString(test));\\n StdOut.println(\\"after calling reverse1, tset is: \\" \\n + java.util.Arrays.toString(tset));\\n String[] second = {\\"another\\", \\"test\\", \\"for\\", \\"you\\", \\"here\\"};\\n reverse2(second);\\n StdOut.println(\\"after calling reverse2, second is: \\" \\n + java.util.Arrays.toString(second));\\n}\\n", "tests": "\\n testMain();\\n test(\\"reverse1\\", (Object)new String[]{\\"calling\\", \\"reverse1\\", \\"directly\\"});\\n test(\\"reverse2\\", (Object)new String[]{\\"reverse2\\", \\"return\\", \\"type\\", \\"ok?\\"});\\n", "lang": "Java"}', '2015-07-02 22:07:04', 'save', 'open'),
(87, '[email protected]', 'cpp/hello', '{"description":"\\nFix this program so that it outputs <pre>Hello, world!</pre>\\nfollowed by a newline character.\\n","sharing":"open","lang":"C++","source_code":"\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n // print greeting\\n\\\\[\\n cout << \\"Hello, world!\\" << endl;\\n\\\\show:\\n cout << Hello, << // bugs!\\n cout << world!\\n]\\\\\\n return \\\\[0]\\\\;\\n}\\n","tests":"[\\n {}\\n]\\n","attempts_until_ref":"1"}', '2015-07-03 07:07:58', 'preview', 'open'),
(88, '[email protected]', 'cpp/scratch', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUse this as a scratchpad.\\n", "example": true, "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\n#include <cstdlib>\\n#include <ctime>\\nusing namespace std;\\n\\n\\\\[\\nint main() {\\n\\n}\\n\\\\show:\\nint main() {\\n\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(89, '[email protected]', 'cpp/eggs', '{"remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "sharing": "open", "attempts_until_ref": "1", "description": "\\nEggs are pacakged in cartons holding 1 dozen eggs and then boxes\\nthat store 5 cartons each. Given a number of eggs by the user, compute\\nhow many cartons and boxes the pacakger will need.\\n", "example": "False", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"12\\"},\\n {\\"stdin\\": \\"60\\"},\\n {\\"stdin\\": \\"61\\"},\\n {\\"stdin\\": \\"119\\"},\\n {\\"stdin\\": \\"120\\"},\\n {\\"stdin\\": \\"1\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std; \\n\\nint main() {\\n // Declare a variable to store the number of eggs\\n // since we must declare a variable before storing to it\\n \\\\[ int eggs; ]\\\\\\n\\n // Output a prompt to ask for the number of eggs\\n cout << \\"How many eggs do you have?\\" << endl;\\n // Read in the number of eggs\\n \\\\[ cin >> eggs; // read input ]\\\\\\n\\n int num_cartons, num_boxes;\\n\\n // Write code to compute the number of boxes & cartons needed\\n \\\\[\\n num_cartons = eggs / 12;\\n if(eggs % 12 != 0){\\n num_cartons++;\\n }\\n num_boxes = num_cartons / 5;\\n if(num_cartons % 5 != 0){\\n num_boxes++;\\n }\\n ]\\\\\\n\\n cout << \\"You need \\" << num_boxes << \\" boxes and \\" << num_cartons << \\" cartons\\" << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(90, '[email protected]', 'cpp/style/examples/hi', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nA very concise \\"Hello, World!\\" program.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nint main(){std::cout<<\\"Hello, world!\\"<<std::endl;}"}', '2015-07-02 22:07:04', 'save', 'open'),
(91, '[email protected]', 'cpp/style/examples/greetings', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nA very verbose \\"Hello, World!\\" program.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n/* \\n This program takes no input, and outputs a greeting.\\n By David Pritchard (dpritcha)\\n*/\\n\\n#include <iostream>\\nusing namespace std; // access cout and endl\\n\\nint main(int argc, char *argv[]) {\\n cout << \\"Hello, world!\\";\\n cout << endl; // end the line\\n return 0; // by convention\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(92, '[email protected]', 'cpp/arrays/echo', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that takes an input <tt>n</tt>, \\nthen <tt>n</tt> more <tt>string</tt> inputs.\\nYou may assume <tt>n</tt> is less than 100.\\nPrint out all of the strings, one per line, and then print them \\nall out again. For example if the input is\\n<pre>\\n3\\nrepeat\\nme\\nplz\\n</pre>\\nthen the output should be\\n<pre>\\nrepeat\\nme\\nplz\\nrepeat\\nme\\nplz\\n</pre>\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"3\\\\nrepeat\\\\nme\\\\nplz\\"},\\n {\\"stdin\\": \\"6\\\\nwe\\\\nwill\\\\nwe\\\\nwill\\\\nrock\\\\nyou\\"},\\n {\\"stdin\\": \\"1\\\\nabracadabra\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n int n;\\n cin >> n;\\n\\n string words[100];\\n\\n // fill out the array\\n for (int i=0; i<n; i++)\\n cin >> words[i];\\n\\n // output twice\\n for (int i=0; i<n; i++)\\n cout << words[i] << endl;\\n for (int i=0; i<n; i++)\\n cout << words[i] << endl;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(93, '[email protected]', 'cpp/arrays/distinct', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that takes an input <tt>n</tt>, \\nthen <tt>n</tt> more <tt>int</tt> inputs.\\nYou may assume <tt>n</tt> is less than 100.\\nIf all the numbers are distinct, print <tt>\\"distinct\\"</tt>.\\nOtherwise, print out <tt>\\"not distinct\\"</tt>.\\n<br>For example if the input is\\n<pre>\\n3\\n45 67 45\\n</pre>\\nthen the output should be <tt>not distinct</tt>.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"3\\\\n45 67 45\\"},\\n {\\"stdin\\": \\"6\\\\n5 4 8 2 3 9\\"},\\n {\\"stdin\\": \\"6\\\\n5 4 8 2 8 9\\"},\\n {\\"stdin\\": \\"1\\\\n103\\"},\\n {\\"stdin\\": \\"10\\\\n34 65 32 87 79 43 24 43 12 21\\"},\\n {\\"stdin\\": \\"10\\\\n34 65 32 87 79 43 24 37 12 21\\"},\\n {\\"stdin\\": \\"10\\\\n1 1 1 1 1 1 1 1 1 1\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int n;\\n cin >> n;\\n\\n int vals[100];\\n\\n // fill out the array\\n for (int i=0; i<n; i++)\\n cin >> vals[i];\\n\\n\\\\[\\n bool all_distinct = true;\\n\\n for (int i=0; i<n; i++) {\\n for (int j=i+1; j<n; j++) {\\n if (vals[i] == vals[j]) {\\n all_distinct = false;\\n }\\n }\\n }\\n \\n if (all_distinct)\\n cout << \\"distinct\\";\\n else\\n cout << \\"not distinct\\";\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(94, '[email protected]', 'cpp/arrays/examples/arraybad', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of unpredictable behaviour.\\n", "example": "True", "cppflags_add": "[\\"-Wno-array-bounds\\"]", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n \\n\\\\show:\\n int arr[3]; // declare an array\\n int thirteen = 13; // never changes\\n\\n cout << \\"Badness: reading out of bounds!\\" << endl;\\n cout << arr[3] << endl;\\n cout << arr[-1] << endl;\\n\\n cout << \\"Worse: writing out of bounds!\\" << endl;\\n arr[-1] = 34;\\n cout << \\"thirteen is now: \\" << thirteen << endl;\\n\\n cout << \\"Writing out of bounds. C++ reports nothing :(\\" << endl;\\n arr[3] = 103;\\n cout << arr[3] << endl;\\n\\n cout << \\"Let''s crash the program!\\" << endl;\\n arr[340912983] = 78676;\\n cout << \\"This line won''t execute.\\" << endl;\\n\\n return 0;\\n]\\\\\\n}\\n", "tests": "[\\n {}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:04', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(95, '[email protected]', 'cpp/arrays/strlen', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nDefine a function <tt>strlen</tt> that takes a single character array as input, \\n<tt>src</tt>. <tt>src</tt> is a null-terminated character array. Return\\nthe number of non-null characters in the string. Example: \\"hi\\" should return\\n2 while \\"\\" should return 0.\\n", "lang": "C++func", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// return the length (# non-null characters) of the C-string\\n// (null-terminated character array) passed as an argument\\n \\\\[int]\\\\ strlen(\\\\[char src[]]\\\\)\\n{\\n\\\\[\\n int x = 0;\\n while (src[x] != ''\\\\0'') {\\n x++;\\n }\\n return x;\\n]\\\\\\n}\\n", "tests": "[\\n [\\"check-function\\", \\"strlen\\", \\"int\\", [\\"char[]\\"]],\\n [\\"call-function\\", \\"strlen\\", [\\"\\\\\\"hi\\\\\\"\\"]],\\n [\\"call-function\\", \\"strlen\\", [\\"\\\\\\"\\\\\\"\\"]],\\n [\\"call-function\\", \\"strlen\\", [\\"\\\\\\"hello world\\\\\\"\\"]],\\n [\\"call-function\\", \\"strlen\\", [\\"\\\\\\"Walk your bike!\\\\\\"\\"]]\\n]\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(96, '[email protected]', 'cpp/arrays/mergearrays', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nComplete the function <tt>merge()</tt> to merge two arrays of \\nlength <tt>n</tt>, passed as <tt>src1</tt> and <tt>src2</tt> into\\nan output array <tt>dest</tt>. You should alternate items from the\\nsrc1 array and the src2 array. \\n<br>For example is the src1 array and src2 array contents are<br>\\n<pre>\\n1 3 5\\n2 4 6\\n</pre>\\nthen the dest array should contain\\n\\n<pre>\\n1 2 3 4 5 6\\n</pre>\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid merge(int src1[], int src2[], int len, int dest[])\\n{\\n\\\\[\\n int oi = 0;\\n for(int i=0; i < len; i++){\\n dest[oi++] = src1[i];\\n dest[oi++] = src2[i];\\n }\\n]\\\\\\n\\n}\\nint main() {\\n int a1[] = {1, 3, 5};\\n int a2[] = {2, 4, 6};\\n int a3[6];\\n \\n // These are 0-length arrays to make sure you coded things correctly\\n int *a4 = NULL, *a5 = NULL, *a6 = NULL;\\n \\n // test your function\\n merge(a1, a2, 3, a3);\\n\\n // pass in 0-length arrays\\n merge(a4, a5, 0, a6); \\n \\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(97, '[email protected]', 'cpp/arrays/arrayprint', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWhy doesn''t this print out the contents of an array?\\n", "cppflags_add": "[\\"-Wno-array-bounds\\"]", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nint main() {\\n int arr[3];\\n arr[0] = 5;\\n arr[1] = 10;\\n arr[2] = 15;\\n\\\\[\\n for (int i=0; i<3; i++)\\n cout << arr[i] << \\" \\";\\n\\\\show:\\n cout << arr;\\n return 0;\\n]\\\\\\n}\\n", "tests": "[\\n {}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:04', 'save', 'open'),
(98, '[email protected]', 'cpp/arrays/pow2', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that takes an input <tt>n</tt>, and \\nfills out the array <tt>pows</tt> with the first \\n<tt>n</tt> powers of 2.\\n<br>For example, <tt>pows[0]</tt> should be 1, <tt>pows[1]</tt> should be 2,\\n<tt>pows[2]</tt> should be 4, etc.\\n<br>Hint: you can''t use <tt>pow</tt>, but what is the pattern in the numbers?\\n<br>The printing code is provided for you.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"4\\"},\\n {\\"stdin\\": \\"10\\"},\\n {\\"stdin\\": \\"32\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int n;\\n cin >> n;\\n\\n // declare an array called \\"pows\\"\\n int pows[100]; // works for inputs up to 100\\n\\n // fill out the array\\n\\\\[\\n pows[0] = 1;\\n for (int i=1; i<n; i++)\\n pows[i] = pows[i-1]*2;\\n]\\\\\\n\\n // output\\n for (int i=0; i<n; i++)\\n cout << \\"2^\\" << i << \\" is \\" << pows[i] << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(99, '[email protected]', 'cpp/arrays/strcpy', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>strcpy()</tt> that takes a ''src'' character array and\\n''dest'' character array as input. <tt>src</tt> and <tt>dest</tt> are null-terminated character arrays. Return the <tt>src</tt> array.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"strcpy\\", \\"char*\\", [\\"char[]\\", \\"char[]\\"]],\\n [\\"call-function\\", \\"strcpy\\", [\\"\\\\\\"hi world\\\\\\"\\", \\"\\\\\\" \\\\\\"\\"]],\\n [\\"call-function\\", \\"strcpy\\", [\\"\\\\\\"hi\\\\\\"\\", \\"\\\\\\" \\\\\\"\\"]],\\n [\\"call-function\\", \\"strcpy\\", [\\"\\\\\\"\\\\\\"\\", \\"\\\\\\" \\\\\\"\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// Copy the characters from the src array to the destination array.\\n// The arguments are passed as src followed by dest and both are\\n// character arrays (C-Strings). By definition of the C-Library, the\\n// strcpy() function should return the src array.\\n\\n \\\\[ char* ]\\\\ strcpy( \\\\[ char* src, char* dest ]\\\\ ) {\\n // return the src array\\n\\\\[\\n int i=0;\\n while( src[i] ){\\n dest[i] = src[i]; i++;\\n }\\n dest[i] = 0;\\n]\\\\\\n return src;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(100, '[email protected]', 'cpp/arrays/examples/2darray', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWhat order will the data be stored in? \\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std; // access cout and endl\\n\\nint main() {\\n cout << boolalpha;\\n int grid[][] = {{11, 12, 13},\\n {21, 22, 23},\\n {31, 32, 33}};\\n\\\\[\\n\\n\\\\show:\\n // how can we determine the order in memory?\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(101, '[email protected]', 'cpp/functions/overload', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine two functions named <tt>rangesize</tt>.\\n<ol>\\n<li>\\n<tt>int rangesize(int start, int end)</tt> <br> This function should return the number of integers in the set \\n$\\\\{\\\\textrm{start}, \\\\textrm{start}+1, \\\\dotsc, \\\\textrm{end}\\\\}$, which is <tt>end - start + 1</tt>.\\n<li>\\n<tt>double rangesize(double start, double end)</tt> <br> This function should return the length of the \\ninterval $[\\\\textrm{start},\\\\textrm{end}]$ of real numbers, which is <tt>end - start</tt>.\\n</ol>\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n\\\\[\\nint rangesize(int start, int end) {\\n return end-start+1;\\n}\\n\\ndouble rangesize(double start, double end) {\\n return end-start;\\n}\\n]\\\\\\n\\nint main() {\\n cout << showpoint;\\n cout << rangesize(10, 20) << endl; // 11\\n cout << rangesize(3.4, 6.2) << endl; // 2.8\\n cout << rangesize(8, 30) << endl; // 23\\n cout << rangesize(8.0, 30.0) << endl; // 22.0\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(102, '[email protected]', 'cpp/functions/examples/return2', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWhat is printed?\\n", "example": "True", "source_code": "\\n#include <iostream>\\nusing namespace std; \\n\\nstring example(int z) {\\n if (z == 103) return \\"yay\\";\\n return \\"boo\\";\\n}\\n\\nint main() {\\n cout << example(103);\\n}\\n", "tests": "[\\n {}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:04', 'save', 'open'),
(103, '[email protected]', 'cpp/functions/abs_func', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nFix the compiler error to get a working definition of abs(),\\nthe absolute value function.", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// return the absolute value of x\\nint abs(int x) {\\n\\\\[\\n if (x > 0) {\\n return x;\\n }\\n else {\\n return -x;\\n }\\n\\\\show:\\n if (x > 0) {\\n return x;\\n }\\n if (x <= 0) {\\n return -x;\\n }\\n]\\\\\\n} \\n\\n// test it\\nint main() {\\n cout << abs(3) << endl;\\n cout << abs(-7) << endl;\\n return 0;\\n}\\n\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(104, '[email protected]', 'cpp/functions/draw_square', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>drawSquare</tt> that takes an integer and char parameter\\nand prints a square:\\nthe integer indicates the side length of the square to draw, and\\nthe character indicates what character to use to draw the square.\\nSee the example below.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"drawSquare\\", \\"void\\", [\\"int\\", \\"char\\"]],\\n [\\"call-function\\", \\"drawSquare\\", [\\"3\\", \\"''*''\\"]],\\n [\\"call-function\\", \\"drawSquare\\", [\\"10\\", \\"''+''\\"]],\\n [\\"call-function\\", \\"drawSquare\\", [\\"30\\", \\"''-''\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// prints an ASCII square to stdout (monitor) \\n// of side length, s, using character, c\\n// e.g. calling drawSquare(4, ''*'') should yield\\n// ****\\n// * *\\n// * *\\n// ****\\n\\n \\\\[ void ]\\\\ drawSquare (\\\\[ int s, char c ]\\\\) {\\n\\\\[\\n for(int i=0; i < s; i++){\\n for(int j=0; j < s; j++){\\n if(i==0 || i == s-1 || j==0 || j==s-1){\\n cout << c;\\n }\\n else {\\n cout << \\" \\";\\n }\\n }\\n cout << endl;\\n }\\n\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(105, '[email protected]', 'cpp/functions/orderit', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWhy is the compiler complaining? How can we fix it?\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n\\\\[\\nint mystery() {\\n return 42;\\n}\\n\\nint main() {\\n cout << mystery();\\n return 0;\\n}\\n\\\\show:\\nint main() {\\n cout << mystery();\\n return 0;\\n}\\n\\nint mystery() {\\n return 42;\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(106, '[email protected]', 'cpp/functions/examples/reset_bad', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWhat is printed?\\n", "example": "True", "source_code": "\\n#include <iostream>\\nusing namespace std; \\n\\nvoid reset(int x) {\\n x = 0;\\n}\\n\\nint main() {\\n int number = 33;\\n reset(number);\\n cout << number;\\n}\\n", "tests": "[\\n {}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:04', 'save', 'open'),
(107, '[email protected]', 'cpp/functions/vowels', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\n<b>Note:</b> For this exercise, we''ll use C++ <tt>string</tt> objects. \\nTo get the <i>k</i>th <tt>char</tt> from a <tt>string s</tt>, \\nwrite <tt>s[k]</tt>, like an array.\\n<p>\\nComplete the method\\n<tt>int frequency(string haystack, char needle)</tt>\\nso that it returns the number of times that the character <tt>needle</tt>\\noccurred in <tt>haystack</tt>. For example <tt>frequency(\\"hello\\", ''l'')</tt>\\nshould return 2.\\n<p>\\nThen, define a function <tt>vowel_count</tt> that takes a <tt>string</tt>\\nargument and returns the number of vowels it contains. Assume the vowels are:\\na, e, i, o, and u. For example <tt>vowel_count(\\"hello\\")</tt> should be 2. \\nHint: use <tt>frequency</tt>. \\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"frequency\\", \\"int\\", [\\"string\\", \\"char\\"]],\\n [\\"check-function\\", \\"vowel_count\\", \\"int\\", [\\"string\\"]],\\n [\\"call-function\\", \\"frequency\\", [\\"\\\\\\"hello\\\\\\"\\", \\"''l''\\"]],\\n [\\"call-function\\", \\"frequency\\", [\\"\\\\\\"goodbye\\\\\\"\\", \\"''l''\\"]],\\n [\\"call-function\\", \\"vowel_count\\", [\\"\\\\\\"supercalifragilisticexpialidocious\\\\\\"\\"]],\\n [\\"call-function\\", \\"vowel_count\\", [\\"\\\\\\"facetious\\\\\\"\\"]],\\n [\\"call-function\\", \\"vowel_count\\", [\\"\\\\\\"phhhht\\\\\\"\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// return the number of times that needle occurs in haystack\\nint frequency(string haystack, char needle) {\\n int n = haystack.length(); // this is how you get length of C++ string\\n int result = 0;\\n\\n // loop to count the occurrences \\n for (int i=0; i<n; i++) {\\n if (haystack[i] \\\\[== needle]\\\\) // look at ith character\\n \\\\[result++;]\\\\\\n }\\n\\n return result;\\n} \\n\\n// return the number of vowels in the given string\\n\\\\[\\nint vowel_count(string text) {\\n return frequency(text, ''a'') + frequency(text, ''e'') + \\n frequency(text, ''i'') + frequency(text, ''o'') + frequency(text, ''u'');\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(108, '[email protected]', 'cpp/functions/remove_factor', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>remove_factor</tt> that takes two integer arguments, \\n<tt>x</tt> and <tt>p</tt>. <tt>x</tt> should be a non-zero positive integer and \\n<tt>p</tt> should be a positive integer bigger than 1. The function should\\nreturn how many times p is a factor of x. For example if x=40 and p=2, then you should\\nreturn 3 since 40 = 2<sup>3</sup> × 5 \\n (i.e. 2 occurs as a factor of 40 three times)\\n<p>\\n<b>Note: don''t use <tt>cout</tt></b> in your code. \\nJust <tt>return</tt> the appropriate value. The grader will \\nautomatically add print statements as it sees fit.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"remove_factor\\", \\"int\\", [\\"int\\", \\"int\\"]],\\n [\\"call-function\\", \\"remove_factor\\", [\\"40\\", \\"3\\"]],\\n [\\"call-function\\", \\"remove_factor\\", [\\"32\\", \\"2\\"]],\\n [\\"call-function\\", \\"remove_factor\\", [\\"1024\\", \\"2\\"]],\\n [\\"call-function\\", \\"remove_factor\\", [\\"54\\", \\"3\\"]],\\n [\\"call-function\\", \\"remove_factor\\", [\\"49\\", \\"7\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// return how many times p is a factor of x\\n \\\\[ int ]\\\\ remove_factor(\\\\[ int x, int p ]\\\\) {\\n // return the correct value\\n\\\\[\\n int num=0;\\n while(x%p == 0){\\n num++;\\n x = x/p;\\n }\\n return num;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(109, '[email protected]', 'cpp/var-expr/quadratic', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nGiven integer inputs\\n<code>a</code>, <code>b</code> and <code>c</code>, print out the \\nroots of <code>ax<sup>2</sup> + bx + c = 0</code>. They are given by\\nthe formula\\n$$\\\\Large \\\\frac{-b \\\\pm \\\\sqrt{b^2-4ac}}{2a}$$\\nA starter solution is given, but it is buggy! Fix it.\\n\\n<p>Note that we won''t be able to detect imaginary roots until\\nnext week when we have <tt>if</tt> statements.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"1 -6 8\\"},\\n {\\"stdin\\": \\"2 8 8\\"},\\n {\\"stdin\\": \\"1 -1 -1\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cmath>\\n\\nusing namespace std;\\n\\nint main()\\n{\\n int a, b, c;\\n\\n cout << \\"Enter the integer coefficients separated by spaces: \\" << endl;\\n cin >> a >> b >> c;\\n\\\\[\\n int det = b*b - 4*a*c;\\n double r1 = (-b + sqrt(det)) / (2 * a);\\n double r2 = (-b - sqrt(det)) / (2 * a);\\n\\\\show:\\n int det = b*b - 4*a*c; // GOOD IDEA: reuse complex subexpression as variable\\n int r1 = -b + sqrt(det) / 2 * a;\\n int r2 = -b - sqrt(det) / 2 * a;\\n]\\\\\\n cout << \\"The roots are: \\" << r1 << \\" and \\" << r2 << endl;\\n\\n return 0;\\n}"}', '2015-07-02 22:07:04', 'save', 'open'),
(110, '[email protected]', 'cpp/var-expr/examples/tacos', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of taking input.\\n", "example": "True", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"7\\"},\\n {\\"stdin\\": \\"-4\\"},\\n {\\"stdin\\": \\"5 this stuff is ignored\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std; \\n\\nint main() {\\n cout << \\"How many tacos do you want to buy? \\";\\n int tacos; // must declare before reading!\\n cin >> tacos; // read input\\n cout << \\"That will cost \\" << tacos * 3 << \\" dollars.\\";\\n cout << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(111, '[email protected]', 'cpp/var-expr/examples/variable', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of variables.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int x = 5; // declare variable called x, set equal to 5\\n cout << x * 2; // print out two times x\\n\\n x = 6; // change x. type not needed\\n cout << x * 2; // what is printed?\\n\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(112, '[email protected]', 'cpp/var-expr/4swap', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThis program reads in 4 strings, representing the top, bottom, left, right \\ncolors of the sides\\nof a square. Your program should <i>rotate the square 90 degrees clockwise</i>\\nand output the top, bottom, left, right colors after the rotation. \\n<p>\\nFor example if the input is <tt>red green blue yellow</tt> then the rotation\\nlooks like this:\\n<div><img src=\\"http://cscircles.cemc.uwaterloo.ca/websheets/images/FourSwap.ipe.png\\"></div>\\nand the output should be <tt>blue yellow green red</tt>.\\n<p>\\nHint: use a variant of the <i>swap idiom</i>.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"red green blue yellow\\"},\\n {\\"stdin\\": \\"fuschia vermilion salmon ochre\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nint main() {\\n string top, bottom, left, right;\\n cin >> top >> bottom >> left >> right;\\n // now do something clever to update the variables!\\n\\\\[\\n string t = top;\\n top = left;\\n left = bottom;\\n bottom = right;\\n right = t;\\n]\\\\\\n cout << top << \\" \\" << bottom << \\" \\" << left << \\" \\" << right;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(113, '[email protected]', 'cpp/var-expr/examples/optest', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUse this to test out different operators.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nint main() {\\n cout << boolalpha << showpoint;\\n\\n \\\\[int]\\\\ x = \\\\[5]\\\\; // declare a variable\\n \\\\[int]\\\\ y = \\\\[6]\\\\; // declare another variable\\n cout << (x \\\\[+]\\\\ y); // try an operator!\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(114, '[email protected]', 'cpp/var-expr/hello', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nFix this program so that it outputs <pre>Hello, world!</pre>\\nfollowed by a newline character.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n cout << \\"Hello, world!\\" << endl;\\n\\\\show:\\n cout << Hello, <<\\n cout << world!\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(115, '[email protected]', 'cpp/var-expr/math', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that takes integer inputs\\n<code>x</code> and <code>y</code>, and outputs 4 lines containing:\\n<ul>\\n<li>Their difference\\n<li>Their average\\n<li>The integer quotient of <tt>x</tt> divided by <tt>y</tt>\\n</ul>\\nFor example, if the input is <tt>20 3</tt>, the output should be\\n<pre>\\n17\\n11.5\\n6\\n</pre>\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"20 3\\"},\\n {\\"stdin\\": \\"5 4\\"},\\n {\\"stdin\\": \\"100 4\\"},\\n {\\"stdin\\": \\"3 20\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\n\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n int x, y;\\n cin >> x >> y;\\n\\n cout << abs(x-y) << endl;\\n cout << (x+y)/2.0 << endl;\\n cout << x / y << endl;\\n]\\\\\\n return 0;\\n}"}', '2015-07-02 22:07:04', 'save', 'open'),
(116, '[email protected]', 'cpp/var-expr/examples/maxplus', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWhat is bigger than the biggest integer?\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int x = 2147483647; // max integer\\n cout << x + 1; // what is this?\\n\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(117, '[email protected]', 'cpp/var-expr/examples/funccall', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of making function calls.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cmath>\\n#include <algorithm>\\nusing namespace std; \\n\\nint main() {\\n cout << cos(0) << endl;\\n cout << sqrt(2) << endl;\\n cout << max(34, 56) << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(118, '[email protected]', 'cpp/var-expr/types', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of variables, using my cat.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n cout << boolalpha;\\n\\\\show:\\n ;\\n]\\\\\\n int age = 9; // years\\n double mass = 5.6; // kilograms\\n char initial = ''B'';\\n string hair = \\"Longhair\\";\\n bool male = false;\\n cout << age << \\" \\" << mass << \\" \\" \\n << initial << \\" \\" << hair << \\" \\" << male;\\n // something''s funny! we can fix it: see page 444 of the textbook\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(119, '[email protected]', 'cpp/var-expr/examples/showpoint', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing the <tt>showpoint</tt> output manipulator.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cmath>\\n#include <algorithm>\\nusing namespace std; \\n\\nint main() {\\n cout << 2.5 * 4 << endl; // what data type and output do you expect?\\n cout << showpoint; // change a flag\\n cout << 2.5 * 4; // try again\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(120, '[email protected]', 'cpp/var-expr/quiz', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nAn example of integer division.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std; \\n\\nint main() {\\n\\\\[\\n cout << (double) 12 / 15 * 100; // what was my percent score on the quiz?\\n\\\\show:\\n cout << (12 / 15) * 100; // what was my percent score on the quiz?\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(121, '[email protected]', 'cpp/templates/strset', '{"attempts_until_ref": "1", "sharing": "open", "description": "Fill in the blanks to create an appropriate Comparator \\nobject functor that can compare the strings pointed to by the two arguments.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"0\\"},\\n {\\"stdin\\": \\"1\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\n#include <set>\\n\\nusing namespace std;\\n\\n// C++ set and map want to compare keys with a \\n// ''<'' operation. Comparator objects need\\n// an operator() with 2 arguments of the key type\\nstruct StrPtrComp {\\n\\\\[ bool operator() ]\\\\(string* s1, string* s2)\\n {\\n\\\\[\\n return *s1 < *s2;\\n]\\\\\\n }\\n};\\n\\nint main()\\n{\\n const int SIZE = 8;\\n string* ptrarray[SIZE];\\n ptrarray[0] = new string(\\"Hello\\");\\n ptrarray[1] = new string(\\"Hola\\");\\n ptrarray[2] = new string(\\"An-yeong\\");\\n ptrarray[3] = new string(\\"Ni hao\\");\\n ptrarray[4] = new string(\\"Bonjour\\");\\n ptrarray[5] = new string(\\"Head nod\\");\\n ptrarray[6] = new string(\\"Hello\\");\\n ptrarray[7] = new string(\\"Hola\\");\\n // 0 = use default comparator, 1 = your StrPtrComp\\n int choice;\\n cin >> choice;\\n if(choice == 0){\\n set<string*> myset;\\n for(int i=0; i < SIZE; i++){\\n myset.insert(ptrarray[i]);\\n }\\n cout << \\"Set has \\" << myset.size() << \\" keys!\\" << endl;\\n }\\n else {\\n StrPtrComp comp;\\n set<string*, StrPtrComp> myset(comp);\\n for(int i=0; i < SIZE; i++){\\n myset.insert(ptrarray[i]);\\n }\\n cout << \\"Set has \\" << myset.size() << \\" keys!\\" << endl;\\n }\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(122, '[email protected]', 'cpp/templates/vecsum', '{"attempts_until_ref": "1", "sharing": "open", "description": "Define a function <tt>vecsum</tt> \\nto \\"add\\" all of the entries in a vector.\\nThe function will also need to give the initializing value \\n<tt>init</tt> for\\nthe sum (for example, if adding numbers, you want to start the sum at\\nzero).\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <vector>\\n#include <iostream>\\nusing namespace std;\\n\\ntemplate <typename T>\\nT vecsum(T init, vector<T> v) {\\n \\\\[T]\\\\ result = init;\\n\\n // add all entries of v into result\\n\\\\[\\n for (int i=0; i<v.size(); i++)\\n result += v[i];\\n]\\\\\\n return result;\\n}\\n\\nint main() {\\n // primes is 2 3 5\\n vector<int> primes;\\n primes.push_back(2); primes.push_back(3); primes.push_back(5);\\n cout << vecsum(0, primes) << endl;\\n // should give 0 + 2 + 3 + 5 which is 10\\n\\n vector<string> words;\\n words.push_back(\\"Ice\\"); words.push_back(\\"Cream\\");\\n cout << vecsum(string(\\"\\"), words) << endl; \\n // should give \\"\\" + \\"Ice\\" + \\"Cream\\" which is \\"IceCream\\"\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(123, '[email protected]', 'cpp/references/reverse_ref', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a function that reverses a vector that is passed in by reference.\\nE.g., if <tt>vec</tt> contains 2, 0, 1, 5 in that order, after calling\\n<tt>reverse(vec)</tt>, it should contain 5, 1, 0, 2 in that order. \\n<br>\\nCall the <tt>swap</tt> function defined previously to help you.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"1 0 3\\"},\\n {\\"stdin\\": \\"4 8 15 16 23 42\\"},\\n {\\"stdin\\": \\"9 6 7 1 1 1 1\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <vector>\\nusing namespace std;\\n\\n// assume this is defined for you\\nvoid swap(int& a, int& b)\\\\fake[;]\\\\ \\n\\\\hide[\\n{\\n int tmp = a;\\n a = b;\\n b = tmp;\\n}\\n]\\\\\\n// for testing: print contents of vector\\nvoid print_vec(vector<int> V)\\\\fake[;]\\\\ \\n\\\\hide[\\n{\\n for (int i=0; i<V.size(); i++)\\n cout << V[i] << \\" \\";\\n cout << endl;\\n}\\n]\\\\\\n\\n// complete this function to reverse a vector\\nvoid reverse(\\\\[vector<int>& v]\\\\) {\\n\\\\[\\n for (int i=0; i<v.size()/2; i++)\\n swap(v[i], v[v.size()-i-1]);\\n]\\\\\\n}\\n\\nint main() {\\n vector<int> test;\\n int x;\\n while (cin >> x) test.push_back(x);\\n cout << \\"Before reverse: \\"; print_vec(test);\\n reverse(test);\\n cout << \\"After reverse: \\"; print_vec(test);\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(124, '[email protected]', 'cpp/references/swap_ref', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPerforming a swap using pass-by-reference.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid exchange(\\\\[int& a, int& b]\\\\) {\\n\\\\[\\n int tmp = a;\\n a = b;\\n b = tmp;\\n]\\\\\\n}\\n\\nint main() {\\n int x = 103;\\n int y = 99;\\n exchange(x, y);\\n cout << \\"x is \\" << x << \\", y is \\" << y << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(125, '[email protected]', 'cpp/references/vector_sum', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nIn this exercise we improve an order of growth by using references.\\nThis program computes the millionth <i>harmonic number</i>,\\n$$H_{1000000} = 1/1 + 1/2 + \\\\cdots + 1/1000000.$$\\nIt adds the numbers in reverse order to get more numerical stability. \\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <vector>\\nusing namespace std;\\n\\n// function to get Kth entry from end of vector\\n// K=0 is last entry, K=1 is second-last, etc\\ndouble kth_last_entry(\\\\[vector<double>& vec\\\\show:vector<double> vec]\\\\, int K) {\\n return vec[vec.size()-K-1];\\n}\\n\\nint main() {\\n // create array 1/1, 1/2, ... 1/1000000\\n vector<double> values;\\n for (int i=1; i<=1000000; i++)\\n values.push_back(1.0/i);\\n \\n // add it in reverse order\\n double sum = 0;\\n for (int K=0; K<1000000; K++)\\n sum += kth_last_entry(values, K);\\n cout << sum << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(126, '[email protected]', 'cpp/references/examples/reset_ref', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nResetting a variable using pass-by-reference syntax.\\n", "example": "True", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid reset(int& x) // pass a _reference_ (pointer)\\n{\\n x = 0; // writes to address passed in\\n}\\n\\nint main() {\\n int num = 103;\\n reset(num); // pass by _reference_ (implicit pointer)\\n cout << num;\\n}\\n", "tests": "[\\n {}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:04', 'save', 'open'),
(127, '[email protected]', 'cpp/dynamic_prog/mario', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\n<style> .ss {font-family:sans-serif} </style>\\nNintendo''s new minimalist video game controller only has two buttons,\\n<span class=''ss''>down</span>\\n and \\n<span class=''ss''>right</span>.\\nIn the platform launch title Super Mario Multiverse,\\nevery level is a square grid of cells \\nwhere Mario starts in the top-left corner. Some\\ncells of the grid have coins with a value, and other cells\\nare empty. The player has to press <span class=''ss''>down</span>\\n and <span class=''ss''>right</span> in some order until\\nthey get to the bottom-right corner, and their score is the sum total of\\nthe value of \\nall coins they hit along the way. Write a program\\nto find the maximum possible score for any level.\\n\\n<p>\\nWe represent a level by an integer <tt>n</tt> giving the square room size,\\nthen an <tt>n</tt>-by-<tt>n</tt> grid <tt>cellValue</tt> where \\n<tt>cellValue[i][j]</tt> is the cell <tt>i</tt>th from the top\\nand <tt>j</tt>th from the left.\\nA positive value means a coin with that value,\\nand a value of 0 means no coin is in that cell. \\n\\n<p>\\nFor example, suppose the input is\\n<pre>\\n5\\n1 1 0 2 0\\n0 2 0 2 0\\n0 1 0 0 1\\n3 0 0 0 1\\n0 0 0 0 0\\n</pre>\\nMario has lots of possible paths. Remember he must go from the top-left\\nto the bottom-right using only steps <span class=''ss''>right</span>\\n (R) and <span class=''ss''>down</span> (D).\\nIf he goes D-D-D-R-R-R-R-D, he gets a score of 1+3+1=5. The path\\nR-D-R-R-D-R-D-D achieves a score of 1+1+2+2+1+1=8, which happens to be \\nthe maximum possible for this room.\\n<p>\\nWrite a function <code>int maxPath(int n, int** cellValue)</code>\\nthat computes the maximum score for a level given in this format. \\nUse dynamic programming: compute, for each position, the best value \\nyou can get if you start in that cell.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"5\\\\n1 1 0 2 0\\\\n0 2 0 2 0\\\\n0 1 0 0 1\\\\n3 0 0 0 1\\\\n0 0 0 0 0\\"},\\n {\\"stdin\\": \\"3\\\\n31 2 0\\\\n5 26 6\\\\n0 4 33\\"},\\n {\\"stdin\\": \\"3\\\\n0 2 31\\\\n6 26 5\\\\n33 4 0\\"},\\n {\\"stdin\\": \\"4\\\\n5 3 1 0\\\\n0 3 4 0\\\\n5 3 4 0\\\\n0 2 1 0\\"},\\n {\\"stdin\\": \\"2\\\\n1 2\\\\n3 4\\"},\\n {\\"stdin\\": \\"10\\\\n1 5 8 4 1 0 2 4 0 6\\\\n8 3 6 8 6 4 6 2 8 0\\\\n3 6 0 1 1 9 8 4 2 0\\\\n2 0 4 4 1 9 1 3 3 3\\\\n2 0 4 8 9 6 5 0 8 2\\\\n9 5 7 6 0 0 5 4 4 3\\\\n7 4 9 1 4 4 1 4 8 2\\\\n6 1 4 7 0 8 5 8 3 8\\\\n9 6 0 2 3 6 6 4 5 2\\\\n5 0 5 1 6 1 4 3 5 0\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <algorithm>\\nusing namespace std;\\n\\nint maxPath(int n, int** cellValue) {\\n // opt[i][j]: max value attainable if starting at position [i][j]\\n int opt[n][n]; // bad style!\\n\\n // base case: corner\\n opt[n-1][n-1] = cellValue[n-1][n-1];\\n // pseudo-base case: right column, have to go down\\n for (int i=n-2; i>=0; i--)\\n opt[i][n-1] = cellValue[i][n-1] + opt[i+1][n-1];\\n // pseudo-base case: bottom row, have to go right\\n for (int j\\\\[=n-2; j>=0; j--]\\\\)\\n \\\\[opt[n-1][j] = cellValue[n-1][j] + opt[n-1][j+1]]\\\\;\\n // general case\\n for (int i\\\\[=n-2; i>=0; i--]\\\\) {\\n for (int j\\\\[=n-2; j>=0; j--]\\\\) {\\n // a choice! take better choice of down and right\\n opt[i][j] = cellValue[i][j] + \\\\[max]\\\\(\\\\[opt[i+1][j]]\\\\,\\n \\\\[opt[i][j+1]]\\\\);\\n }\\n }\\n // value in top-left corner\\n return \\\\[opt[0][0]]\\\\;\\n}\\n\\nint main() {\\n int n;\\n cin >> n;\\n int** coins = new int*[n];\\n for (int i=0; i<n; i++) coins[i] = new int[n];\\n for (int i=0; i<n; i++)\\n for (int j=0; j<n; j++)\\n cin >> coins[i][j];\\n cout << maxPath(n, coins);\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(128, '[email protected]', 'cpp/dynamic_prog/maxprod_memo', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a memoized recursive function to compute <i>maxprod(N)</i>.\\n", "lang": "C++", "tests": "[\\n {\\"args\\": [\\"6\\"]},\\n {\\"args\\": [\\"7\\"]},\\n {\\"args\\": [\\"8\\"]},\\n {\\"args\\": [\\"20\\"]},\\n {\\"args\\": [\\"60\\"]},\\n {\\"args\\": [\\"100\\"]},\\n {\\"args\\": [\\"101\\"]},\\n {\\"args\\": [\\"102\\"]},\\n {\\"args\\": [\\"500\\"]},\\n {\\"args\\": [\\"1812\\"]}\\n]\\n", "source_code": "\\n#include <algorithm>\\n#include <iostream>\\n#include <iomanip>\\n#include <vector>\\nusing namespace std;\\n\\ndouble maxprod(int n, vector<double>& memory) {\\n // check if answer was already computed\\n if (\\\\[memory[n] != 0]\\\\)\\n return \\\\[memory[n]]\\\\;\\n\\n // else save answer \\n if (\\\\[n <= 3]\\\\)\\n memory[n] = \\\\[n]\\\\;\\n else\\n memory[n] = \\\\[max(2*maxprod(n-2, memory), 3*maxprod(n-3, memory))]\\\\;\\n\\n return memory[n];\\n}\\n\\nint main(int argc, char* argv[]) {\\n int N = atoi(argv[1]);\\n vector<double> memory(N+1, \\\\[0]\\\\); // sets initial value for vector\\n cout << setprecision(20) << maxprod(N, memory) << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(129, '[email protected]', 'cpp/dynamic_prog/maxprod_dp', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a dynamic programming function to compute <i>maxprod(N)</i>.\\n", "lang": "C++", "tests": "[\\n {\\"args\\": [\\"6\\"]},\\n {\\"args\\": [\\"7\\"]},\\n {\\"args\\": [\\"8\\"]},\\n {\\"args\\": [\\"20\\"]},\\n {\\"args\\": [\\"60\\"]},\\n {\\"args\\": [\\"100\\"]},\\n {\\"args\\": [\\"101\\"]},\\n {\\"args\\": [\\"102\\"]},\\n {\\"args\\": [\\"500\\"]},\\n {\\"args\\": [\\"1812\\"]}\\n]\\n", "source_code": "\\n#include <algorithm>\\n#include <iostream>\\n#include <iomanip>\\n#include <vector>\\nusing namespace std;\\n\\ndouble maxprod(int n) {\\n vector<double> memory(n+1); // indices from 0 to n \\n\\\\[\\n for (int i=1; i<=3; i++)\\n memory[i] = i;\\n for (int i=4; i<=n; i++)\\n memory[i] = max(memory[i-2]*2, memory[i-3]*3);\\n return memory[n];\\n]\\\\\\n}\\n\\nint main(int argc, char* argv[]) {\\n int N = atoi(argv[1]);\\n cout << setprecision(20) << maxprod(N) << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(130, '[email protected]', 'cpp/dynamic_prog/maxprod_rec', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a recursive function to compute <i>maxprod(N)</i>.\\n", "lang": "C++", "tests": "[\\n {\\"args\\": [\\"6\\"]},\\n {\\"args\\": [\\"7\\"]},\\n {\\"args\\": [\\"8\\"]},\\n {\\"args\\": [\\"20\\"]},\\n {\\"args\\": [\\"60\\"]}\\n]\\n", "source_code": "\\n#include <algorithm>\\n#include <iostream>\\nusing namespace std;\\n\\nlong maxprod(int n) {\\n if (\\\\[n <= 3]\\\\)\\n return \\\\[n]\\\\;\\n else\\n return \\\\[max(2*maxprod(n-2), 3*maxprod(n-3))]\\\\;\\n}\\n\\nint main(int argc, char* argv[]) {\\n cout << maxprod(atoi(argv[1])) << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(131, '[email protected]', 'cpp/dynamic_prog/starbucks', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThis program should read from cin a data file of the format\\n<pre>\\ncardvalue\\nN\\nprice1 price2 ... priceN\\n</pre>\\nwhere all values are integers. You have a gift card worth <tt>cardvalue</tt>,\\nand the store sells items costing <tt>price1</tt>, <tt>price2</tt>, ... <tt>priceN</tt>.\\nPrint out the maximum amount that you can spend without exceeding <tt>cardvalue</tt>.\\n<p>\\nFor example, if the input is\\n<pre>\\n100\\n5\\n40 23 88 32 20\\n</pre>\\nthen the output should be <tt>95</tt>, which you can attain by buying the items worth 40, 23 and 32.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"100\\\\n5\\\\n40 23 88 32 20\\"},\\n {\\"stdin\\": \\"200\\\\n5\\\\n40 23 88 32 20\\"},\\n {\\"stdin\\": \\"90\\\\n5\\\\n40 23 88 32 20\\"},\\n {\\"stdin\\": \\"10\\\\n5\\\\n40 23 88 32 20\\"},\\n {\\"stdin\\": \\"1000\\\\n5\\\\n40 23 88 32 20\\"},\\n {\\"stdin\\": \\"10000\\\\n10\\\\n1826 2048 1141 1386 455 1729 619 1287 1273 1569\\"},\\n {\\"stdin\\": \\"80000\\\\n20\\\\n12271 13721 22971 14621 35441 19951 27871 12441 33161 29551 13711 11711 13601 38691 12321 15351 26011 34292 16051 14190\\"}\\n]\\n", "source_code": "\\n#include <algorithm>\\n#include <iostream>\\n#include <vector>\\nusing namespace std;\\n\\nint main(int argc, char* argv[]) {\\n // read the input\\n int cardvalue, N;\\n cin >> cardvalue >> N;\\n int price[N]; // bad style, VLA\\n for (int i=0; i<N; i++) cin >> price[i]; \\n\\n // declare the dynamic programming table\\n // first index: remaining cash\\n // second index: items left to consider\\n int best_spend[cardvalue+1][N+1]; // bad style, VLA\\n \\n for (int limit=0; limit<=cardvalue; limit++) {\\n for (int items_left=0; items_left<=N; items_left++) {\\n // compute best_spend[limit][items_left]\\n int result = 0;\\n // try not buying this item\\n\\\\[\\n if (items_left > 0)\\n result = max(result, best_spend[limit][items_left-1]);\\n]\\\\\\n // try buying this item\\n\\\\[\\n if (items_left > 0 && limit >= price[N-items_left]) {\\n int p = price[N-items_left];\\n result = max(result, p + best_spend[limit - p][items_left-1]);\\n }\\n]\\\\\\n best_spend[limit][items_left] = result;\\n }\\n }\\n // print out entry for full card value and all items\\n cout << \\\\[best_spend[cardvalue][N]]\\\\ << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(132, '[email protected]', 'cpp/F14/discriminant', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nDefine a function <tt>discriminant(a, b, c)</tt> that takes\\nthree <tt>double</tt> arguments, and returns the value of\\n$$b^2-4ac$$\\n<b>Note: don''t use <tt>cout</tt></b> in your code. \\nJust <tt>return</tt> the appropriate value. The grader will \\nautomatically add print statements as it sees fit.\\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"discriminant\\", \\"double\\", [\\"double\\", \\"double\\", \\"double\\"]],\\n [\\"call-function\\", \\"discriminant\\", [\\"1\\", \\"1\\", \\"1\\"]],\\n [\\"call-function\\", \\"discriminant\\", [\\"1\\", \\"4\\", \\"4\\"]],\\n [\\"call-function\\", \\"discriminant\\", [\\"2\\", \\"3\\", \\"5\\"]],\\n [\\"call-function\\", \\"discriminant\\", [\\"1.4\\", \\"0.2\\", \\"3.9\\"]],\\n [\\"call-function\\", \\"discriminant\\", [\\"-5.4\\", \\"2.02\\", \\"7.3\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// declare the return type, function name, and arguments\\n\\\\[double]\\\\ discriminant (double a, \\\\[double b, double c]\\\\) {\\n // return the computed value\\n\\\\[\\n return b*b-4*a*c;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(133, '[email protected]', 'cpp/F14/printseconds', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nThis program should read in an integer number of \\nhours and minutes from the user\\n(placing them in the <code>hr</code> and <code>min</code> variables). You\\nshould then compute the equivalent number of seconds in the <code>sec</code>\\nvariable. The answer will be output to the screen.\\n", "lang": "C++", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int hr, min, sec;\\n cout << \\"Enter hours and minutes separated by a space: \\" << endl;\\n\\n // now receive the hours and minutes as input from the user,\\n // and use them to compute the number of seconds\\n\\\\[\\n cin >> hr >> min;\\n sec = 3600*hr + 60*min;\\n]\\\\\\n\\n cout << \\"That translates to \\" << sec << \\" seconds!\\" << endl;\\n return 0;\\n}\\n", "tests": "[\\n {\\"stdin\\": \\"0 40\\"},\\n {\\"stdin\\": \\"20 1\\"}\\n]\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(134, '[email protected]', 'cpp/F14/lambert', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\n<i>Lambert''s W function</i> is a mathematical function\\nwith a <a href=\\"https://cs.uwaterloo.ca/research/tr/1993/03/W.pdf\\">diverse\\nrange of applications in math and science</a>. It is an inverse function\\nto $x = w \\\\times \\\\mathrm{e}^w$. In other words, for a given $x$, the value\\nof the Lambert function $W(x)$ is defined as the real number satisfying\\n$$x = W(x) \\\\times \\\\mathrm{e}^{W(x)}.$$\\n\\n<p>\\nFor example, <i>W</i>(126) is approximately 3.5651 since 126 = 3.5651 × e<sup>3.5651</sup>.\\n\\n<p>\\nUse binary search to define a static method <tt>W(double x)</tt> that \\nevaluates the Lambert function at <i>x</i>. You may assume $x \\\\ge 0$. \\nTo help get the binary search\\nstarted, you may use the fact that $0 \\\\le W(x) \\\\le \\\\max(1, \\\\ln(x))$.\\nTerminate the binary search when \\nthe search endpoints differ by 10<sup>-8</sup> or less.\\n\\n<p>\\n<i>Hint</i>: you will need <a href=\\"http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#exp-double-\\">several</a>\\n<a href=\\"http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#log-double-\\">methods</a>\\nfrom the <tt>Math</tt> library.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"126\\"},\\n {\\"stdin\\": \\"2.718281828459045\\"},\\n {\\"stdin\\": \\"23423.348\\"},\\n {\\"stdin\\": \\"1E25\\"},\\n {\\"stdin\\": \\"1E-5\\"}\\n]\\n", "source_code": "\\n#include <cmath>\\n#include <iostream>\\nusing namespace std;\\n\\n// evaluate Lambert''s W function at x. Assumes x >= 0.\\ndouble W(double x) {\\n // we know that W(x) >= 0 and W(x) <= max(1, ln(x))\\n double lo = 0;\\n \\\\[double hi = max(1.0, log(x));]\\\\\\n\\n // continue until search endpoints differ by 1E-8 or less\\n while (\\\\[hi - lo >= 1E-8]\\\\) {\\n // evaluate midpoint times e^midpoint\\n\\\\[\\n double mid = (lo + hi) / 2;\\n double midval = mid * exp(mid);\\n]\\\\\\n\\n // if this value is smaller than x, search above, else search below\\n\\\\[\\n if (midval < x)\\n lo = mid;\\n else\\n hi = mid;\\n]\\\\\\n }\\n return lo; // return some point in final range\\n}\\n\\nint main() {\\n double x;\\n cin >> x;\\n cout << W(x);\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(135, '[email protected]', 'cpp/streams/examples/cinfail', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nFailing. The input will be <tt>eleventeen</tt>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"eleventeen\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\nint main() {\\n cout << boolalpha;\\n\\n cout << \\"Fail before read? \\" << cin.fail() << endl;\\n\\n int i;\\n cin >> i;\\n\\n cout << \\"Fail after read? \\" << cin.fail() << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(136, '[email protected]', 'cpp/streams/examples/cinchar', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWhat will be printed if the input is <pre>hi 5s 4 every1</pre>\\n", "example": "True", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"hi 5s 4 every1\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\nint main() {\\n char buf[80];\\n char ch;\\n int i;\\n cin >> buf; cout << buf << endl;\\n cin >> i; cout << i << endl;\\n cin >> ch; cout << ch << endl;\\n cin >> ch; cout << ch << endl;\\n cin >> i; cout << i << endl;\\n cin >> buf; cout << buf << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(137, '[email protected]', 'cpp/streams/cinlen', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a <i>file size calculator</i>: it should tell you how long\\nits input <tt>cin</tt> was. For instance, if <tt>word.txt</tt> contains\\n<tt>Hello</tt>, then <tt>./cinlen < word.txt</tt> should print <tt>5</tt>.\\n<p>\\nYou will need to use <tt>get</tt> and <tt>fail</tt>. Remember that <tt>fail</tt> returns <tt>true</tt> <i>after</i> reading past the end of the file.\\n", "lang": "C++", "cppflags_add": "[\\"-Wno-unused-variable\\"]", "tests": "[\\n {\\"stdin\\": \\"Hello\\"},\\n {\\"stdin\\": \\"2 spaces\\"},\\n {\\"stdin\\": \\"/==\\\\\\\\\\\\n|oo|\\\\n\\\\\\\\==/\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstring>\\nusing namespace std;\\n\\nint main() {\\n int result = 0;\\n while (\\\\[!cin.fail()]\\\\) {\\n\\\\[\\n // get the next character\\n char ch = (char) cin.get();\\n if (!cin.fail())\\n result++;\\n]\\\\\\n }\\n cout << \\\\[result]\\\\ << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(138, '[email protected]', 'cpp/streams/examples/getline_eg', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing <tt>getline(ifstream, string)</tt>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"first line\\\\nsecond line\\\\na very long long long long long long line\\\\nanother line\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nint main() {\\n int i=0;\\n while (true) {\\n i++;\\n string text;\\n getline(cin, text); // buffer to write to, then buffer size\\n if (cin.fail()) return 0;\\n cout << \\"Line \\" << i << \\", \\" << text.length() << \\" chars: \\";\\n cout << text << endl;\\n }\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(139, '[email protected]', 'cpp/streams/examples/buffer', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nHow can we force immediate printing?\\n<p><i>The goal here is to get the program to produce the output <tt>Hi!</tt> before it crashes.\\nInitially, for a reason that will be explained in class, nothing is being output.</i>\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n cout << \\"Hi!\\" << endl;\\n \\\\show:\\n cout << \\"Hi!\\\\n\\";\\n while (true) {\\n }\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(140, '[email protected]', 'cpp/streams/examples/getline', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing <tt>cin.getline()</tt>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"first line\\\\n2nd line\\\\n extra spaces \\\\n\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstring>\\nusing namespace std;\\n\\nint main() {\\n int i=0;\\n while (true) {\\n i++;\\n char text[20];\\n cin.getline(text, 20); // buffer, size\\n cout << i << \\"th line (length \\" \\n << strlen(text) << \\"): \\"\\n << text << endl;\\n if (strlen(text)==0)\\n return 0;\\n }\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(141, '[email protected]', 'cpp/streams/examples/first5', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing <tt>cin.get()</tt>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"hi mom\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstring>\\nusing namespace std;\\n\\nint main() {\\n for (int i=0; i<5; i++) {\\n char ch = (char) cin.get();\\n cout << i << \\"th char: \\" \\n << ch << endl;\\n }\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(142, '[email protected]', 'cpp/random/examples/randdigits', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program that prints out the sum of 1000 random digits.\\n<p>\\nA correct program should usually output totals between 4400 and 4600.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\n#include <ctime>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n srand(time(0)); \\n int total = 0;\\n for (int i=0; i<1000; i++) {\\n int random_digit = rand() % 10;\\n total += random_digit;\\n }\\n cout << total;\\n\\\\show:\\n srand(time(0)); \\n int total = 0;\\n int random_digit = rand() % 10;\\n for (int i=0; i<1000; i++) {\\n total += random_digit;\\n }\\n cout << total;\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(143, '[email protected]', 'cpp/random/examples/seedtime', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing <tt>srand()</tt>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\n#include <ctime>\\nusing namespace std;\\n\\nint main() {\\n srand(time(0)); \\n cout << rand() << endl;\\n cout << rand() << endl;\\n cout << rand() << endl;\\n cout << rand() << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(144, '[email protected]', 'cpp/random/examples/seed', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing <tt>srand()</tt>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\nint main() {\\n srand(103); \\n cout << \\"First two numbers in list 103: \\";\\n cout << rand() << \\" \\";\\n cout << rand() << endl;\\n\\n srand(1003); \\n cout << \\"First two numbers in list 1003: \\";\\n cout << rand() << \\" \\";\\n cout << rand() << endl;\\n\\n srand(103); \\n cout << \\"First two numbers in list 103 again: \\";\\n cout << rand() << \\" \\";\\n cout << rand() << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(145, '[email protected]', 'cpp/classes/examples/location_eg', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of <tt>struct</tt>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\nusing namespace std;\\n\\nstruct Location { // define a new data type, Location\\n int row; // each Location has a row\\n int col; // each Location has a col\\n};\\n\\nvoid print_location(Location loc); // TODO\\n\\nint main() {\\n\\\\[\\n\\n\\\\show:\\n Location home; // construct a Location\\n home.row = 5;\\n home.col = 10;\\n\\n Location north_of_home = home; // copy it\\n north_of_home.row -= 1;\\n\\n print_location(home);\\n print_location(north_of_home);\\n]\\\\\\n}\\n\\nvoid print_location(Location loc) {\\n cout << \\"row \\" << loc.row << \\", column \\" << loc.col << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(146, '[email protected]', 'cpp/classes/recorder', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nMake a short recorder that can store a message to be played back. It should have the following API:\\n<ul>\\n<li><tt>Recorder(string initialMsg) // create new recorder w/this message initially\\n<li><tt>string playback() // return the saved message\\n<li><tt>void record(string newMsg) // save this message instead</tt>\\n</ul>\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <string>\\n#include <iostream>\\nusing namespace std;\\n\\n// normally this would go in recorder.h\\nclass Recorder {\\npublic:\\n Recorder(string initialMsg);\\n string playback();\\n void record(string newMsg);\\nprivate:\\n string savedMsg;\\n};\\n\\n// normally this would go in recorder.cpp\\n// constructor\\nRecorder::Recorder(\\\\[string initialMsg]\\\\) {\\n // save the initial message\\n \\\\[savedMsg = initialMsg;]\\\\\\n}\\n\\n// accessor: get back the saved message\\nstring Recorder::\\\\[playback()]\\\\ {\\n return \\\\[savedMsg]\\\\;\\n}\\n\\n// mutator: replace the saved message\\n\\\\[\\nvoid Recorder::record(string newMsg) {\\n // now the new message is saved (the old one is forgotten)\\n savedMsg = newMsg;\\n}\\n]\\\\\\n\\n// test client\\nint main() {\\n Recorder r(\\"hello\\");\\n cout << \\"The recorded message is: \\" << r.playback() << endl;\\n cout << \\"Let''s play it again: \\" << r.playback() << endl;\\n r.record(\\"bonjour\\");\\n cout << \\"The changed message is: \\" << r.playback() << endl; \\n Recorder card(\\"happy birthday!\\");\\n cout << \\"The new recorder says: \\" << card.playback() << endl; \\n cout << \\"The old one still says: \\" + r.playback() << endl; \\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(147, '[email protected]', 'cpp/classes/the_count', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCalling a member function from inside of another member function.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// counter.h\\nclass Counter {\\npublic:\\n Counter();\\n void add_one();\\n void add_one_and_print();\\nprivate:\\n int value;\\n};\\n\\n// counter.cpp\\nCounter::Counter() {\\n value = 0;\\n}\\n\\nvoid Counter::add_one() {\\n value++;\\n}\\n \\nvoid Counter::add_one_and_print() {\\n // how do we call a method on the current object?\\n \\\\[add_one();\\\\show:the_count.add_one();]\\\\\\n cout << value << endl;\\n}\\n\\n// test code\\nint main() {\\n Counter the_count;\\n the_count.add_one_and_print();\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(148, '[email protected]', 'cpp/classes/location_eq', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nComparing <tt>struct</tt>s.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\nusing namespace std;\\n\\nstruct Location { // define a new data type, Location\\n int row; // each Location has a row\\n int col; // each Location has a col\\n};\\n\\nint main() {\\n cout << boolalpha;\\n Location home; // construct a Location\\n home.row = 5; home.col = 10;\\n\\n Location north_of_home = home; // copy it\\n north_of_home.row -= 1;\\n\\n Location home_again = north_of_home; // copy it\\n home_again.row += 1;\\n\\n // compare them\\n\\\\[\\n // if you did this a lot, you might want to make a function!\\n cout << (home.row == north_of_home.row &&\\n north_of_home.row == north_of_home.col) << endl;\\n cout << (home.row == home_again.row &&\\n home.col == home_again.col) << endl;\\n\\\\show:\\n cout << (home == north_of_home) << endl;\\n cout << (home == home_again) << endl;\\n]\\\\\\n}\\n\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(149, '[email protected]', 'cpp/classes/clicker', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWhen you go in to a bar or place with a seating capacity, often\\nthe person at the front has a \\"clicker\\" to keep track of how many \\npeople go in or out. Build a <tt>Clicker</tt> class to do this; it should \\nhave the following API.\\n<ul>\\n<li><tt>Clicker() // constructor, make new clicker with value 0</tt>\\n<li><tt>void inc() // add one to the current value</tt>\\n<li><tt>void dec() // subtract one from the current value</tt>\\n<li><tt>int curr() // return the current value</tt>\\n</ul>\\nNegative clicker values should be permitted.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// normally this would go in clicker.h\\nclass Clicker {\\npublic:\\n Clicker(); // constructor\\n void inc(); // 3 member functions\\n void dec();\\n int curr();\\nprivate:\\n// private instance variable(s) you will use are declared here:\\n\\\\[\\n int value;\\n]\\\\\\n};\\n\\n// constructor, make new clicker with value 0\\nClicker::Clicker() {\\n\\\\[\\n value = 0;\\n]\\\\\\n}\\n// add one to the current value\\nvoid Clicker::inc() {\\n\\\\[\\n value++;\\n]\\\\\\n}\\n\\n// subtract one from the current value\\n\\\\[\\nvoid Clicker::dec() {\\n value--;\\n}\\n]\\\\\\n\\n// return the current value\\n\\\\[\\nint Clicker::curr() {\\n return value;\\n}\\n]\\\\\\n\\n// testing suite\\nint main() {\\n Clicker myClick;\\n cout << myClick.curr() << endl; // should be 0\\n myClick.inc();\\n myClick.inc();\\n cout << myClick.curr() << endl; // should be 2\\n myClick.dec();\\n myClick.dec();\\n myClick.dec();\\n cout << myClick.curr() << endl; // should be -1\\n\\n Clicker clickMore;\\n cout << clickMore.curr() << endl; // should be 0\\n clickMore.inc();\\n clickMore.inc();\\n clickMore.inc();\\n cout << clickMore.curr() << endl; // should be 3\\n\\n // check that both clickers have separate variables\\n cout << myClick.curr(); // should still be -1\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(150, '[email protected]', 'cpp/classes/ruleof3', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nA memory bug.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nclass TwoInts {\\nprivate:\\n int* data;\\n\\npublic:\\n TwoInts(int first, int second) {\\n data = new int[2];\\n data[0] = first;\\n data[1] = second;\\n }\\n\\n ~TwoInts() {\\n delete[] data;\\n }\\n\\n\\\\[\\n TwoInts(const TwoInts& c) {\\n data = new int[2];\\n data[0] = c.data[0]; data[1] = c.data[1];\\n } \\n\\\\show:\\n ;// todo?\\n]\\\\\\n\\n int get_first() { return data[0]; }\\n int get_second() { return data[1]; }\\n};\\n\\nint biggest_of(TwoInts pair) {\\n return max(pair.get_first(), pair.get_second());\\n}\\n\\nint main() {\\n TwoInts nums(10, 33);\\n cout << nums.get_first() << \\" \\" << nums.get_second() << endl;\\n cout << biggest_of(nums) << endl;\\n cout << nums.get_first() << \\" \\" << nums.get_second() << endl;\\n}\\n\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(151, '[email protected]', 'cpp/classes/location_reset', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nAn example of <tt>struct</tt> with pass-by-value.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\nusing namespace std;\\n\\nstruct Location { // define a new data type, Location\\n int row; // each Location has a row\\n int col; // each Location has a col\\n};\\n\\n\\\\[\\nvoid reset_location(Location* loc) {\\n loc->row = 0;\\n loc->col = 0;\\n}\\n\\\\show:\\nvoid reset_location(Location loc) {\\n loc.row = 0;\\n loc.col = 0;\\n}\\n]\\\\\\n\\nvoid print_location(Location loc);\\n\\nint main() {\\n Location home; // construct a Location\\n home.row = 5;\\n home.col = 10;\\n\\n\\\\[\\n reset_location(&home);\\n\\\\show:\\n reset_location(home);\\n]\\\\\\n print_location(home);\\n}\\n\\nvoid print_location(Location loc) {\\n cout << \\"row \\" << loc.row << \\", column \\" << loc.col << endl;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(152, '[email protected]', 'cpp/classes/examples/colorcopy', '{"sharing": "open", "attempts_until_ref": "1", "description": "Example of <tt>=</tt> with objects.", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <cmath>\\n#include <iostream>\\nusing namespace std;\\n\\n\\\\hide[\\nclass color {\\n public:\\n int red;\\n int green;\\n int blue;\\n};\\n\\n]\\\\\\nint main() {\\n color my_fav_color;\\n my_fav_color.red = 1;\\n my_fav_color.blue = 0;\\n my_fav_color.green = 3;\\n \\n color your_fav_color = my_fav_color;\\n your_fav_color.green = 4;\\n\\n cout << my_fav_color.green << endl; // 3 or 4?\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(153, '[email protected]', 'cpp/classes/norm', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a two-dimensional <tt>Point</tt> class. \\n<p>\\nThe method <tt>p.dot(q)</tt> should compute the dot product $p \\\\cdot q = p_x \\\\times q_x + p_y \\\\times q_y$.\\n<p>\\nThe method <tt>p.norm()</tt> should compute the norm of $p$, defined as $\\\\sqrt{p \\\\cdot p}$.\\n", "cppflags_remove": "[\\"-Wshadow\\"]", "source_code": "\\n#include <iostream>\\n#include <cmath>\\nusing namespace std;\\n\\n// point.h\\nclass Point {\\npublic:\\n Point(double x, double y);\\n double dot(Point other);\\n double norm();\\nprivate:\\n double x;\\n double y;\\n};\\n\\n// point.cpp\\nPoint::Point(double x, double y) {\\n // parameter names same as data members :(\\n this->x = x; // woohoo\\n\\\\[\\n this->y = y;\\n]\\\\\\n}\\n\\ndouble Point::dot(Point other) {\\n return x * other.x + y * other.y;\\n}\\n\\ndouble Point::norm() {\\n // square root of dot product with self\\n\\\\[\\n return sqrt(this->dot(*this));\\n]\\\\\\n}\\n\\n// test code\\nint main() {\\n Point p(3, 4);\\n Point q(2, 0);\\n cout << p.dot(q) << endl;\\n cout << p.norm() << endl;\\n cout << q.norm() << endl;\\n}\\n", "tests": "[\\n {}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:04', 'save', 'open'),
(154, '[email protected]', 'cpp/classes/combolock', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a ''combination lock'' which has a <tt>string</tt> password that you can change,\\nwhich you can lock and unlock. It should have this API:\\n<ul>\\n<style>li {margin-bottom: 9pt;} </style>\\n<li><tt>\\n// construct new lock with this initial password, initially unlocked<br>\\nCombinationLock(string initpass) \\n</tt>\\n<li><tt>// is this lock currently locked?<br>bool isLocked()</tt>\\n<li><tt>// if current password equals attempt, unlock (no effect if already unlocked)<br>\\nvoid tryUnlock(string attempt)</tt>\\n<li><tt>// make this lock become locked (no effect if already locked)<br>void lock()</tt>\\n<li><tt>// if locked, print \\"ERROR: LOCKED\\" else change password to newpass<br>\\nvoid changePassword(string newpass)</tt>\\n</ul>\\n\\n<i>Note: in practice, passwords are not stored directly, but only as <a href=\\"http://en.wikipedia.org/wiki/Cryptographic_hash_function#Password_verification\\">hashes</a>.", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\\\[\\nclass CombinationLock {\\npublic:\\n CombinationLock(string initpass);\\n void tryUnlock(string attempt);\\n bool isLocked();\\n void lock();\\n void changePassword(string newpass);\\nprivate:\\n bool locked; // is it locked right now?\\n string password; // current password\\n};\\n\\n// construct new lock with this initial password, initially unlocked\\nCombinationLock::CombinationLock(string initpass) {\\n password = initpass; // save password\\n locked = false; // initially unlocked\\n}\\n\\n// is this lock currently locked? \\nbool CombinationLock::isLocked() {\\n return locked;\\n}\\n\\n// if current password equals attempt, unlock (no effect if already unlocked)\\nvoid CombinationLock::tryUnlock(string attempt) {\\n if (attempt == password)\\n locked = false;\\n}\\n\\n// make this lock become locked (no effect if already locked)\\nvoid CombinationLock::lock() {\\n locked = true;\\n}\\n\\n// if locked, print \\"ERROR: LOCKED\\" else change password to newpass\\nvoid CombinationLock::changePassword(string newpass) {\\n if (locked) \\n cout << \\"ERROR: LOCKED\\" << endl;\\n else\\n password = newpass;\\n}\\n]\\\\\\n\\nint main() {\\n cout << boolalpha;\\n CombinationLock myLock(\\"0000\\");\\n cout << myLock.isLocked() << endl; // false\\n myLock.lock();\\n cout << myLock.isLocked() << endl; // true\\n myLock.changePassword(\\"new-pass\\"); // -- ERROR: LOCKED\\n cout << myLock.isLocked() << endl; // true\\n myLock.tryUnlock(\\"2014\\"); // -- shouldn''t unlock, password is 0000\\n cout << myLock.isLocked() << endl; // true\\n myLock.tryUnlock(\\"0000\\"); // -- unlocks!\\n cout << myLock.isLocked() << endl; // false\\n myLock.changePassword(\\"hello123\\"); // -- password change OK\\n cout << myLock.isLocked() << endl; // false\\n myLock.lock();\\n cout << myLock.isLocked() << endl; // true\\n myLock.tryUnlock(\\"0000\\"); // -- shouldn''t unlock, wrong password now\\n cout << myLock.isLocked() << endl; // true\\n myLock.tryUnlock(\\"hello123\\"); // -- unlocks!\\n cout << myLock.isLocked() << endl; // false\\n myLock.lock();\\n cout << myLock.isLocked() << endl; // true\\n return 0;\\n}\\n"}', '2015-07-02 22:07:04', 'save', 'open'),
(177, '[email protected]', 'cpp/cs103/lec-intro/usc', '{"sharing": "open", "choices": "[[\\"A CS faculty member at USC won an Academy Award in 2010.\\", true], [\\"There is a way to securely transmit a credit card number between strangers even if a thief hears their conversation.\\", true], [\\"The \\\\\\"moon landing\\\\\\" actually took place in the USC Computer Science building, using a green screen.\\", false]]", "description": "\\nWhich of the following statements are true?\\n<i>Select all correct answers.</i>\\n", "lang": "multichoice"}', '2015-07-02 22:07:04', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(205, '[email protected]', 'cpp/passing/swap_elements', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>void swap_elements(int arr[], int i, int j)</tt> \\nthat takes an array <tt>arr</tt>,\\nand swaps the elements at positions <tt>i</tt> and <tt>j</tt>.\\n<p>You should <b>not</b> use cin or cout, that part is done for you\\nin order to facilitate testing.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"3 0 1\\\\n2014 9 17\\"},\\n {\\"stdin\\": \\"8 5 7\\\\n99 11 17 71 39 0 93 38\\"},\\n {\\"stdin\\": \\"8 3 3\\\\n99 11 17 71 39 0 93 38\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid swap_elements(int arr[], int i, int j) {\\n\\\\[\\n int tmp = arr[i];\\n arr[i] = arr[j];\\n arr[j] = tmp;\\n]\\\\\\n}\\n\\nint main() {\\n // read n, i, j, then n inputs\\n int the_inputs[100];\\n int n, i, j;\\n cin >> n >> i >> j;\\n for (int k=0; k<n; k++) cin >> the_inputs[k];\\n cout << \\"Before calling your function, the array contains: \\";\\n for (int k=0; k<n; k++) cout << the_inputs[k] << \\" \\";\\n cout << endl;\\n\\n // call YOUR function\\n swap_elements(the_inputs, i, j);\\n\\n // is the output correct?\\n cout << \\"After calling your function, the array contains: \\";\\n for (int k=0; k<n; k++) cout << the_inputs[k] << \\" \\";\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(206, '[email protected]', 'cpp/passing/product', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a function <tt>product1</tt> that takes a <tt>double</tt> pointer\\nindicating the start of an array, and an <tt>int</tt> indicating the \\nlength of the array. It should return the product of all the numbers\\nin the array. Do the same thing again with another function <tt>product2</tt>,\\nusing a different approach.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// compute product by treating a as an array\\ndouble product1(double* a, int n) {\\n double running_product = 1;\\n for (int i=0; i<n; i++) {\\n \\\\[running_product *= a[i];]\\\\\\n }\\n return running_product;\\n}\\n\\n// compute product by increasing a by one position at a time\\ndouble product2(double* a, int n) {\\n double running_product = 1;\\n while (n > 0) {\\n // multiply in the next number\\n running_product *= \\\\[*a]\\\\;\\n a++; // increase the pointer by one position\\n n--; // one less number to go\\n }\\n return running_product;\\n}\\n\\nint main() {\\n double sample_inputs[3] = {2.5, -1.0, 3.0};\\n // product of all the numbers?\\n cout << product1(sample_inputs, 3) << endl;\\n // try another way\\n cout << product2(sample_inputs, 3) << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(207, '[email protected]', 'cpp/passing/replace_first', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>void replace_first(int arr[], int n, int target, \\nint replacement)</tt> \\nthat takes an array <tt>arr</tt> of length <tt>n</tt>,\\nfinds the <i>first</i> entry whose value equals <tt>target</tt>, and\\nchanges its value to <tt>replacement</tt>. If no such entry exists, do nothing.\\n<p>You should <b>not</b> use cin or cout, that part is done for you\\nin order to facilitate testing.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"3 9 10\\\\n2014 9 17\\"},\\n {\\"stdin\\": \\"8 39 103\\\\n99 11 17 71 39 0 93 38\\"},\\n {\\"stdin\\": \\"8 39 103\\\\n99 11 17 71 39 0 39 38\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid replace_first(int arr[], int n, int target, int replacement) {\\n\\\\[\\n for (int i=0; i<n; i++) {\\n if (arr[i] == target) {\\n arr[i] = replacement;\\n return; // don''t change any more!\\n }\\n }\\n]\\\\\\n}\\n\\nint main() {\\n // read n, t, r, then n inputs\\n int the_inputs[100];\\n int n, t, r;\\n cin >> n >> t >> r;\\n for (int i=0; i<n; i++) cin >> the_inputs[i];\\n cout << \\"Before calling your function, the array contains: \\";\\n for (int i=0; i<n; i++) cout << the_inputs[i] << \\" \\";\\n cout << endl;\\n\\n // call YOUR function\\n replace_first(the_inputs, n, t, r);\\n\\n // is the output correct?\\n cout << \\"After calling your function, the array contains: \\";\\n for (int i=0; i<n; i++) cout << the_inputs[i] << \\" \\";\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(208, '[email protected]', 'cpp/passing/reset_array', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>void reset_array(int arr[], int n)</tt> \\nthat takes an array <tt>arr</tt> of length <tt>n</tt>, \\nand resets all of its entries to zero.\\n<p>You should <b>not</b> use cin or cout, that part is done for you\\nin order to facilitate testing.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"3\\\\n2014 9 17\\"},\\n {\\"stdin\\": \\"8\\\\n99 11 17 71 39 0 93 38\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid reset_array(int arr[], int n) {\\n\\\\[\\n for (int i=0; i<n; i++)\\n arr[i] = 0;\\n]\\\\\\n}\\n\\nint main() {\\n int the_inputs[100];\\n int n;\\n // read n, then n inputs\\n cin >> n;\\n for (int i=0; i<n; i++) cin >> the_inputs[i];\\n // call YOUR function\\n reset_array(the_inputs, n);\\n // is the output correct?\\n cout << \\"After calling your function, the array contains: \\";\\n for (int i=0; i<n; i++) cout << the_inputs[i] << \\" \\";\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(209, '[email protected]', 'cpp/recursion/basen_combos', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nComplete the following program to print out all possible combinations\\nof a given base and number of digits. E.g. <tt>./bincombos</tt> with input <tt>4 2</tt>\\nshould print out\\n<pre>\\n00\\n01\\n02\\n03\\n10\\n11\\n12\\n13\\n20\\n21\\n22\\n23\\n30\\n31\\n32\\n33\\n</pre>\\nWith input <tt>2 3</tt> it should print out\\n<pre>\\n000\\n001\\n010\\n011\\n100\\n101\\n110\\n111\\n</pre>\\nWith input <tt>10 1</tt> it should print out\\n<pre>\\n0\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n</pre>\\nTo do this,\\nfill out the recursive function\\n <tt>basen_combos(int base, char arr[], int current, int len)</tt>.\\nIt should try setting <tt>current</tt> to each possible value,\\n in turn and using recursion to go through all the options of the remaining digits.\\n<p>\\nUse the base case to check that a particular combination is ready for printing.\\n<p>\\nUse the recursive case to set the current digit place and recurse to the next\\ndigit.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"2 3\\"},\\n {\\"stdin\\": \\"4 2\\"},\\n {\\"stdin\\": \\"10 1\\"},\\n {\\"stdin\\": \\"8 2\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid basen_combos(int base, char* array, int current, int len) {\\n // Code for base case (i.e. end of array)\\n // When do we know there are no more digits to show\\n // and what should we do if that is the case\\n\\\\[\\n if(current == len){\\n array[len] = ''\\\\0'';\\n cout << array << endl;\\n }\\n]\\\\\\n // Code for recursive case\\n // If we''re not at the last digit, then set that\\n // digit location to each of its possible values and\\n // each time you change the value use recursion to \\n // generate all the combinations of digits after it\\n // \\n // Remember to make the char version of digit x, use ''0''+x\\n\\\\[\\n else {\\n for(int i=0; i < base; i++){\\n array[current] = ''0''+i;\\n basen_combos(base, array, current+1, len);\\n }\\n } \\n]\\\\\\n}\\n\\nint main() {\\n // read target, n, then n sorted inputs\\n int base, numDigits;\\n cin >> base >> numDigits;\\n\\n // allocate an array to hold the current combo + null char\\n char* arr = new char[numDigits+1];\\n \\n // Call the function to generate all binary combos\\n basen_combos(base, arr, 0, numDigits);\\n\\n delete [] arr;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(210, '[email protected]', 'cpp/recursion/kettles', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program <code>Kettles</code> with a recursive static method\\n<code>sing(n)</code> which prints the famous \\"kettles of tea\\" song.\\nFor example, when <code>n</code> is 3, calling <code>sing(3)</code>\\nshould print out\\n<pre>\\n3 kettles of tea on the wall\\n3 kettles of tea\\ntake one down, pass it around\\n2 kettles of tea on the wall!\\n2 kettles of tea on the wall\\n2 kettles of tea\\ntake one down, pass it around\\n1 kettles of tea on the wall!\\n1 kettles of tea on the wall\\n1 kettles of tea\\ntake one down, pass it around\\nno more kettles of tea on the wall!\\n</pre>\\n<div>\\n<i>To sing this song, first sing the first four lines, and then sing\\nthe song for a smaller value of n (unless you are done).</i>\\nThis is the strategy that you can turn into\\na recursive method.\\n</div>\\nNote that we require your song to say <code>1 kettles</code>\\ninstead of the grammatically correct <code>1 kettle</code>. Fixing this \\nis left as a challenge for the thirsty.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"3\\"},\\n {\\"stdin\\": \\"1\\"},\\n {\\"stdin\\": \\"9\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// sings a well-known song about n kettles\\nvoid sing(int n) {\\n // print three lines\\n\\\\[\\n cout << n << \\" kettles of tea on the wall\\" << endl;\\n cout << n << \\" kettles of tea\\" << endl;\\n cout << \\"take one down, pass it around\\" << endl;\\n]\\\\\\n if (n > 1) {\\n // sing fourth line, with exclamation point!\\n\\\\[\\n cout << n-1 << \\" kettles of tea on the wall!\\" << endl;\\n]\\\\\\n // call sing recursively on remaining kettles\\n sing(\\\\[n-1]\\\\);\\n }\\n else { \\n // sing the final line, with exclamation point!\\n\\\\[\\n cout << \\"no more kettles of tea on the wall!\\" << endl;\\n]\\\\\\n }\\n}\\n\\nint main() {\\n int n;\\n cin >> n;\\n sing(n);\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(211, '[email protected]', 'cpp/recursion/monkey_recurse', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nUsing recursion,\\ncreate a method <tt>printAll()</tt>\\nthat prints out all names in the list, one per line.\\nYou will need to define a helper function.\\n", "verboten": "[\\"for\\", \\"while\\", \\"do\\"]", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll();\\n void addStart(string newName); // implementation not shown\\n private: \\n void helpPrintAll(Node* n); // PRIVATE\\n Node* first;\\n};\\n\\\\hide[\\n// add a new node, containing this name, at the start of the list\\nvoid MonkeyChain::addStart(string newName) {\\n Node* newFirst = new Node(newName);\\n Node* oldFirst = first;\\n first = newFirst;\\n first->next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n}\\n]\\\\\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// private helper\\nvoid MonkeyChain::helpPrintAll(Node* n) {\\n\\\\[\\n if (n != NULL) {\\n cout << n->name << endl;\\n helpPrintAll(n->next);\\n }\\n]\\\\\\n}\\n\\nvoid MonkeyChain::printAll() {\\n\\\\[\\n helpPrintAll(first);\\n]\\\\\\n}\\n\\n\\nint main() {\\n MonkeyChain mc;\\n mc.threeKongs();\\n mc.printAll(); cout << endl;\\n\\n // test on 5 monkeys\\n mc.addStart(\\"King Kong\\");\\n mc.addStart(\\"Bubbles\\");\\n mc.printAll(); \\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(212, '[email protected]', 'cpp/recursion/binary_search', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nFill out the method <tt>bsearch(int target, int arr[], int n)</tt> \\nto return -1 if <tt>arr</tt> doesn''t contain <tt>target</tt>, \\nand otherwise return <tt>i</tt> where <tt>target == arr[i]</tt>.\\n<p>The <tt>main()</tt>, filled out for you, reads sample cases\\ncontaining the target, n, and list of numbers in the array.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"68\\\\n15\\\\n2 8 15 29 33 34 39 59 60 67 68 80 89 92 98\\"},\\n {\\"stdin\\": \\"67\\\\n15\\\\n2 8 15 29 33 34 39 59 60 67 68 80 89 92 98\\"},\\n {\\"stdin\\": \\"50\\\\n15\\\\n2 8 15 29 33 34 39 59 60 67 68 80 89 92 98\\"},\\n {\\"stdin\\": \\"25\\\\n4\\\\n10 20 30 40\\"},\\n {\\"stdin\\": \\"1\\\\n15\\\\n2 8 15 29 33 34 39 59 60 67 68 80 89 92 98\\"},\\n {\\"stdin\\": \\"10\\\\n8\\\\n3 8 21 43 78 100 102 105\\"},\\n {\\"stdin\\": \\"100\\\\n8\\\\n3 8 21 43 78 100 102 105\\"},\\n {\\"stdin\\": \\"1000\\\\n8\\\\n3 8 21 43 78 100 102 105\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint bsearch(int target, int arr[], int n) {\\n // each iteration, \\n // look for ''target'' in ''arr[first]..arr[last]''\\n int first = 0;\\n int last = n-1;\\n \\n while (true) {\\n // empty range\\n if (first>last) {\\n return -1;\\n }\\n\\n if (first==last) {\\n // we''re done, for better or worse\\n\\\\[\\n if (target == arr[first])\\n return first;\\n else\\n return -1;\\n]\\\\\\n }\\n\\n int mid = (last+first)/2;\\n // did we find it?\\n if (\\\\[target == arr[mid]]\\\\) {\\n \\\\[return mid;]\\\\\\n }\\n // continue the search in the appropriate half\\n else if (target > arr[mid]) {\\n \\\\[first = mid+1;]\\\\\\n }\\n else {\\n \\\\[last = mid-1;]\\\\\\n }\\n }\\n}\\n\\nint main() {\\n // read target, n, then n sorted inputs\\n int target, n;\\n cin >> target >> n;\\n int* arr = new int[n];\\n for (int i=0; i<n; i++)\\n cin >> arr[i];\\n\\n cout << bsearch(target, arr, n);\\n\\n delete [] arr;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(213, '[email protected]', 'cpp/recursion/countup', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a recursive function <tt>countup(int n)</tt> that prints out\\n<tt>Blastoff!</tt>, followed by the numbers from 1 to n. For example\\n<tt>countup(5)</tt> should print out\\n<pre>\\nBlastoff!\\n1\\n2\\n3\\n4\\n5\\n</pre>\\n", "verboten": "[\\"#include\\", \\"for\\", \\"while\\"]", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"countup\\", \\"void\\", [\\"int\\"]],\\n [\\"call-function\\", \\"countup\\", [\\"5\\"]],\\n [\\"call-function\\", \\"countup\\", [\\"10\\"]],\\n [\\"call-function\\", \\"countup\\", [\\"1\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n\\\\[\\nvoid countup(int n) {\\n // base case\\n if (n == 0) {\\n cout << \\"Blastoff!\\" << endl;\\n }\\n // recursive case\\n else {\\n // recursive call\\n countup(n-1);\\n\\n cout << n << endl;\\n }\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(214, '[email protected]', 'cpp/recursion/zero_sum', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\n<div>\\nIs it possible to assign + and – signs to the numbers\\n<pre>\\n1434 3243 343 5 293 3408 123 487 93 12 2984 29\\n</pre>\\nso that the sum is 0? With recursion, we can try all possible combinations\\nof + and – for each number to find out. There are $2^n$ ways to assign\\n+ or – signs to $n$ numbers, and recursion can accomplish this by making\\ntwo recursive calls (one for +, one for –) at each of $n$ levels.\\nEach branch of the recursive call tree will keep a running sum of the numbers\\nit has assigned signs so far. \\n<p>To implement this in C++,\\nwrite a recursive function\\n<pre>bool canMakeZero(int partialSum, int* nums, int numsLeft)</pre>\\nwhich tries every assignment of +/– signs\\n<pre>partialSum ± nums[0] ± nums[1] ± … ± nums[numsLeft-1]</pre> \\nand returns <tt>true</tt> <b>when any one of the combinations'' sum is zero</b>.\\n</ol>\\n<p>\\nNote that our original question is:\\n<pre>\\nint nums[12] = {1434, 3243, 343, 5, 293, 3408, 123, 487, 93, 12, 2984, 29};\\ncanMakeZero(0, nums, 12); // call helper function starting with partialSum=0\\n</pre>\\n<p>\\nMake each recursive call pass the pointer <tt>nums+1</tt> in place of \\n<tt>nums</tt>, and pass <tt>numsLeft-1</tt> in place of <tt>numsLeft</tt>.\\nHow do the recursive calls combine? What is the base case?\\n", "lang": "C++", "tests": "[\\n {},\\n {\\"args\\": [\\"1\\", \\"1\\", \\"1\\", \\"1\\", \\"1\\", \\"1\\"]},\\n {\\"args\\": [\\"1\\", \\"1\\", \\"1\\", \\"1\\", \\"1\\", \\"1\\", \\"1\\"]},\\n {\\"args\\": [\\"1\\", \\"2\\", \\"3\\", \\"4\\", \\"5\\", \\"6\\"]},\\n {\\"args\\": [\\"1\\", \\"2\\", \\"3\\", \\"4\\", \\"5\\", \\"6\\", \\"7\\"]},\\n {\\"args\\": [\\"1000\\", \\"100000\\", \\"100\\", \\"111111\\", \\"10\\", \\"1\\", \\"10000\\"]},\\n {\\"args\\": [\\"1000\\", \\"100000\\", \\"100\\", \\"111111\\", \\"10\\", \\"1\\", \\"1000\\"]},\\n {\\"args\\": [\\"9\\", \\"16\\", \\"25\\"]},\\n {\\"args\\": [\\"0\\", \\"0\\", \\"0\\"]},\\n {\\"args\\": [\\"1435\\", \\"3243\\", \\"343\\", \\"5\\", \\"293\\", \\"3408\\", \\"123\\", \\"487\\", \\"93\\", \\"12\\", \\"2984\\", \\"29\\"]},\\n {\\"args\\": [\\"1434\\", \\"3253\\", \\"343\\", \\"5\\", \\"293\\", \\"3408\\", \\"123\\", \\"487\\", \\"93\\", \\"22\\", \\"2984\\", \\"29\\"]},\\n {\\"args\\": [\\"129\\", \\"435\\", \\"843\\", \\"234\\", \\"456\\", \\"238\\", \\"587\\", \\"910\\"]}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\n#include <cstdlib>\\nusing namespace std;\\n\\nbool canMakeZero(int runningSum, int* nums, int numsLeft) {\\n\\\\[\\n // we''ve given a sign to all numbers\\n if (numsLeft == 0) {\\n if (runningSum == 0) \\n return true; // hit the runningSum\\n else\\n return false; // missed the runningSum\\n }\\n\\n // try both possibilities, propagating any hit\\n if (canMakeZero(runningSum + nums[0], nums+1, numsLeft-1))\\n return true;\\n\\n if (canMakeZero(runningSum - nums[0], nums+1, numsLeft-1))\\n return true;\\n\\n // neither recursive call found a solution\\n return false;\\n]\\\\\\n}\\n\\nint main(int argc, char* argv[]) {\\n cout << boolalpha;\\n if (argc < 2) { // default tests\\n int testArr[] = {1434,3243,343,5,293,3408,123,487,93,12,2984,29};\\n // should print true because\\n // -1434+3243-343-5-293-3408-123-487-93-12+2984-29 = 0\\n cout << canMakeZero(0, testArr, 12) << endl; // true\\n int testArr2[] = {1, 2};\\n // no way to make zero\\n cout << canMakeZero(0, testArr2, 2) << endl; // false\\n }\\n else {\\n int n = argc-1;\\n int* testArr = new int[n];\\n for (int i=0; i<n; i++) testArr[i] = atoi(argv[i+1]);\\n cout << canMakeZero(0, testArr, n);\\n delete testArr;\\n }\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(215, '[email protected]', 'cpp/recursion/bin_combo_str', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nComplete the following program to print out all possible binary combinations\\nof a given number of digits. E.g. <tt>./bincombos</tt> with input <tt>1</tt>\\nshould print out\\n<pre>\\n0\\n1\\n</pre>\\nWith input 2 it should print out\\n<pre>\\n0<b>0</b>\\n0<b>1</b>\\n1<i>0</i>\\n1<i>1</i>\\n</pre>\\nwhere the bold/italics is added just to show the relation to the previous case (don''t try to add it).\\nWith input 3 it should likewise print out\\n<pre>\\n0<b>00</b>\\n0<b>01</b>\\n0<b>10</b>\\n0<b>11</b>\\n1<i>00</i>\\n1<i>01</i>\\n1<i>10</i>\\n1<i>11</i>\\n</pre>\\nTo do this,\\nfill out the recursive function\\n <tt>void bincombos(string prefix, int len)</tt>.\\nIt should try appending a ''0'' or ''1'' to the prefix in turn, \\nusing recursion to go through\\nall the options of the remaining bits. For instance when n=2,\\nyou want the recursive call tree to look like this:\\n<pre>\\n (\\"\\", 2)\\n / \\\\\\n (\\"0\\", 2) (\\"1\\", 2)\\n / \\\\ / \\\\ \\n(\\"00\\", 2) (\\"01\\", 2) (\\"10\\", 2) (\\"11\\", 2)\\n</pre>\\nso it will print out\\n<pre>\\n00\\n01\\n10\\n11\\n</pre>\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"0\\"},\\n {\\"stdin\\": \\"1\\"},\\n {\\"stdin\\": \\"2\\"},\\n {\\"stdin\\": \\"3\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid bincombos(string prefix, int len) {\\n // base case: we don''t have to add any more 0s and 1s\\n // the prefix is a complete string, so print it and quit\\n\\\\[\\n if (prefix.length() == len) {\\n cout << prefix << endl;\\n return;\\n }\\n]\\\\\\n\\n // recursive case: try adding 0 or 1 as the next digit,\\n // then continue trying all possibilities after that\\n\\\\[\\n bincombos(prefix + \\"0\\", len);\\n bincombos(prefix + \\"1\\", len);\\n]\\\\\\n}\\n\\nint main() {\\n // what size combos do we want?\\n int numBits;\\n cin >> numBits;\\n\\n // start the recursion\\n\\\\[\\n bincombos(\\"\\", numBits);\\n]\\\\\\n\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(216, '[email protected]', 'cpp/recursion/factorial', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a recursive method <code>factorial(n)</code>\\nthat returns n × (n-1) × (n-2) × … × 3 × 2 × 1. For example, <code>factorial(4)</code> should return 24 since that is the value of 4 × 3 × 2 × 1.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"4\\"},\\n {\\"stdin\\": \\"1\\"},\\n {\\"stdin\\": \\"5\\"},\\n {\\"stdin\\": \\"6\\"},\\n {\\"stdin\\": \\"10\\"},\\n {\\"stdin\\": \\"20\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n \\\\[long]\\\\ factorial(\\\\[int n]\\\\) {\\n // base case\\n if (\\\\[n == 0]\\\\) \\n return \\\\[1]\\\\;\\n\\n // reduction step\\n // note that n! = n * (n-1) * ... * 2 * 1 = n * ((n-1) * ... * 2 * 1)\\n return \\\\[n]\\\\ * factorial(\\\\[n-1]\\\\);\\n}\\n\\nint main() {\\n int n;\\n cin >> n;\\n cout << factorial(n);\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(217, '[email protected]', 'cpp/recursion/textfractal', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nA ruler''s pattern makes shorter marks each time you divide the length\\nin half. Mimic this with a static method <code>printRuler(n)</code> that\\nprints a ruler like this whose longest line has length <code>n</code>.\\nFor example <code>printRuler(2)</code> should print out\\n<pre>\\n-\\n--\\n-\\n</pre>\\nand <code>printRuler(3)</code> should print out\\n<pre>\\n-\\n--\\n-\\n---\\n-\\n--\\n-\\n</pre>\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"1\\"},\\n {\\"stdin\\": \\"2\\"},\\n {\\"stdin\\": \\"3\\"},\\n {\\"stdin\\": \\"4\\"},\\n {\\"stdin\\": \\"5\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid printRuler(int n) {\\n // return if we''re in the base case. \\n\\\\[\\n if (n == 0) return;\\n]\\\\\\n // otherwise, make two recursive calls, with a length-n line in between\\n printRuler(\\\\[n-1]\\\\);\\n\\\\[\\n for (int i=0; i<n; i++)\\n cout << ''-'';\\n cout << endl;\\n printRuler(n-1);\\n]\\\\\\n}\\n\\nint main() {\\n int n;\\n cin >> n;\\n printRuler(n);\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(218, '[email protected]', 'cpp/recursion/evaluate', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <code>evaluate()</code> that evaluates\\na mathematical expression (a string) consisting of\\nintegers, +, *, and parentheses.\\n<p>\\nFor example,\\n<ul>\\n<li><tt>evaluate(\\"11+23\\");</tt> returns 34\\n<li><tt>evaluate(\\"(1+1)*5\\");</tt> returns 10\\n</ul>\\nBy definition, it must use\\n recursion to evaluate two halves of the expression and\\ncombine them. The string manipulation and logic are filled in, but\\nyou need to add two recursive calls and a base case.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"11+19\\"},\\n {\\"stdin\\": \\"(1+1)*5\\"},\\n {\\"stdin\\": \\"2*2+3*3\\"},\\n {\\"stdin\\": \\"(2*(1+6*2+2)+6*6+2*2*(1+2+6))+6*2*2\\"},\\n {\\"stdin\\": \\"103+456*789\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\n// cstdlib is for atoi\\nusing namespace std;\\n\\nint evaluate(string expression) {\\n // here -1 means ''not found yet''\\n int plusPos = -1; // position of last ''+'' outside of parentheses\\n int timesPos = -1; // position of last ''*'' outside of parentheses\\n\\n // scan expression, looking for operators outside of parentheses\\n int level = 0; // current nesting depth\\n for (int i=0; i<expression.length(); i++) {\\n char ch = expression[i];\\n\\n // look for operator\\n if (ch==''+'' && level==0) plusPos = i;\\n if (ch==''*'' && level==0) timesPos = i;\\n \\n // count level of parentheses\\n if (ch==''('') level++;\\n if (ch=='')'') level--;\\n }\\n \\n // recurse on lowest-precedence operator\\n\\n if (plusPos != -1) {\\n // break down, e.g. \\"3*4+5*6\\" => \\"3*4\\" and \\"5*6\\"\\n string exprLeft = expression.substr(0, plusPos);\\n string exprRight = expression.substr(plusPos+1);\\n int valueLeft = evaluate(exprLeft);\\n int valueRight = evaluate(exprRight);\\n return valueLeft + valueRight;\\n }\\n else if (timesPos != -1) {\\n // break down, e.g. \\"(3+4)*(5+6)\\" => \\"(3+4)\\" and \\"(5+6)\\"\\n string exprLeft = expression.substr(0, timesPos);\\n string exprRight = expression.substr(timesPos+1);\\n\\\\[\\n int valueLeft = evaluate(exprLeft);\\n int valueRight = evaluate(exprRight);\\n return valueLeft * valueRight;\\n]\\\\\\n }\\n else if (expression[0]==''('') {\\n // everything was in a matched pair of parentheses\\n // break down, e.g. \\"(3*4)\\" => \\"3*4\\"\\n return evaluate(expression.substr(1, expression.length()-1));\\n }\\n else {\\n // base case: just a number like \\"12\\". convert expression to int.\\n // don''t make any recursive calls\\n // 1. convert C++ string to C string\\n const char* num_cstr = expression.c_str();\\n // 2. convert C string to integer and return it\\n return \\\\[atoi]\\\\(num_cstr);\\n }\\n}\\n\\nint main() {\\n string expr;\\n cin >> expr;\\n cout << evaluate(expr);\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(219, '[email protected]', 'cpp/recursion/list_max', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nUsing recursion,\\ncreate a method <tt>maximum()</tt>\\nthat finds the maximum element in a linked list of integers.\\nYou will need to declare and define a helper function.\\n", "verboten": "[\\"for\\", \\"while\\", \\"do\\"]", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"1 0 3\\"},\\n {\\"stdin\\": \\"3 0 1\\"},\\n {\\"stdin\\": \\"1 3 0\\"},\\n {\\"stdin\\": \\"9 4 4 0 19\\"},\\n {\\"stdin\\": \\"2923 2 20 43 298\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <algorithm>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n int value;\\n Node(int initialValue); // constructor for nodes\\n};\\n\\nNode::Node(int initialValue) {value = initialValue; next = NULL;}\\n\\nclass IntChain {\\n public:\\n IntChain();\\n int maximum(); \\n void addStart(int newValue);\\n private: \\n\\\\[\\n int helpMax(Node* n); // compute max from here to end\\n]\\\\\\n Node* first;\\n};\\n\\nIntChain::IntChain() {first = NULL;}\\n\\\\hide[\\n// add a new node, containing this name, at the start of the list\\nvoid IntChain::addStart(int newValue) {\\n Node* newFirst = new Node(newValue);\\n Node* oldFirst = first;\\n first = newFirst;\\n first->next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n}\\n]\\\\\\n\\n// private helper\\n\\\\[\\nint IntChain::helpMax(Node* n) {\\n if (n->next == NULL) {\\n return n->value; // nothing to reverse\\n }\\n else {\\n return max(n->value, helpMax(n->next));\\n }\\n}\\n]\\\\\\n\\nint IntChain::maximum() {\\n\\\\[\\n return helpMax(first);\\n]\\\\\\n}\\n\\nint main() {\\n IntChain c;\\n int x;\\n while (cin >> x) c.addStart(x);\\n cout << c.maximum();\\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(220, '[email protected]', 'cpp/recursion/bincombos', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nComplete the following program to print out all possible binary combinations\\nof a given number of digits. E.g. <tt>./bincombos</tt> with input <tt>1</tt>\\nshould print out\\n<pre>\\n0\\n1\\n</pre>\\nWith input 2 it should print out\\n<pre>\\n0<b>0</b>\\n0<b>1</b>\\n1<i>0</i>\\n1<i>1</i>\\n</pre>\\nwhere the bold/italics emphasize the relation to the previous case.\\n<i>You shouldn''t try to add bold/italics.</i> With input 3 it should likewise print out\\n<pre>\\n0<b>00</b>\\n0<b>01</b>\\n0<b>10</b>\\n0<b>11</b>\\n1<i>00</i>\\n1<i>01</i>\\n1<i>10</i>\\n1<i>11</i>\\n</pre>\\nTo do this,\\nfill out the recursive function\\n <tt>bincombos(char arr[], int current, int len)</tt>.\\nIt should try setting <tt>current</tt> to each possible value,\\nsetting that bit to ''0'' and ''1'' in turn and using recursion to go through\\nall the options of the remaining bits.\\n<p>\\nUse the base case to check that a particular combination is ready for printing.\\n<p>\\nUse the recursive case to set the current bit place and recurse to the next\\nbit.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"0\\"},\\n {\\"stdin\\": \\"1\\"},\\n {\\"stdin\\": \\"2\\"},\\n {\\"stdin\\": \\"3\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid bincombos(char* array, int current, int len) {\\n // Code for base case (i.e. end of array)\\n // When do we know there are no more bits to show\\n // and what should we do if that is the case\\n\\\\[\\n if(current == len){\\n array[len] = ''\\\\0'';\\n cout << array << endl;\\n }\\n]\\\\\\n // Code for recursive case\\n // If we''re not at the last bit, then set that\\n // bit location to each of its possible values and\\n // each time you change the value use recursion to \\n // generate all the combinations of bits after it\\n\\\\[\\n else {\\n array[current] = ''0'';\\n bincombos(array, current+1, len);\\n array[current] = ''1'';\\n bincombos(array, current+1, len);\\n } \\n]\\\\\\n}\\n\\nint main() {\\n // read target, n, then n sorted inputs\\n int numBits;\\n cin >> numBits;\\n\\n // allocate an array to hold the current combo + null char\\n char* arr = new char[numBits+1];\\n \\n // Call the function to generate all binary combos\\n bincombos(arr, 0, numBits);\\n\\n delete [] arr;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(221, '[email protected]', 'cpp/recursion/examples/countdown', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing a recursive function.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid countdown(int n) {\\n // base case\\n if (n == 0) {\\n cout << \\"Blastoff!\\" << endl;\\n }\\n // recursive case\\n else {\\n cout << n << endl;\\n // recursive call\\n countdown(n-1);\\n }\\n}\\n\\nint main() {\\n countdown(5);\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(222, '[email protected]', 'cpp/recursion/examples/countdown_inf', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing a recursive function.\\n", "example": "True", "lang": "C++", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid countdown(int n) {\\n // whoops!\\n\\\\[\\n if (n == 0)\\n\\\\show:\\n if (n == 100) // whoops!\\n]\\\\\\n {\\n cout << \\"Blastoff!\\" << endl;\\n }\\n // recursive case\\n else {\\n cout << n << endl;\\n // recursive call\\n countdown(n-1);\\n }\\n}\\n\\nint main() {\\n countdown(5);\\n}\\n", "tests": "[\\n {}\\n]\\n", "remarks": "The purpose of this example is to use wwhen discussing the meaning of ''stack overflow'' and the goal of a base case."}', '2015-07-02 22:07:05', 'save', 'open'),
(223, '[email protected]', 'cpp/recursion/binsearch', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nFill out the method <tt>bsearch(int target, int arr[], int n)</tt> \\nto return -1 if <tt>arr</tt> doesn''t contain <tt>target</tt>, \\nand otherwise return <tt>i</tt> where <tt>target == arr[i]</tt>.\\n<p>The <tt>main()</tt>, filled out for you, reads sample cases\\ncontaining the target, n, and list of numbers in the array.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"68\\\\n15\\\\n2 8 15 29 33 34 39 59 60 67 68 80 89 92 98\\"},\\n {\\"stdin\\": \\"67\\\\n15\\\\n2 8 15 29 33 34 39 59 60 67 68 80 89 92 98\\"},\\n {\\"stdin\\": \\"50\\\\n15\\\\n2 8 15 29 33 34 39 59 60 67 68 80 89 92 98\\"},\\n {\\"stdin\\": \\"25\\\\n4\\\\n10 20 30 40\\"},\\n {\\"stdin\\": \\"1\\\\n15\\\\n2 8 15 29 33 34 39 59 60 67 68 80 89 92 98\\"},\\n {\\"stdin\\": \\"10\\\\n8\\\\n3 8 21 43 78 100 102 105\\"},\\n {\\"stdin\\": \\"100\\\\n8\\\\n3 8 21 43 78 100 102 105\\"},\\n {\\"stdin\\": \\"1000\\\\n8\\\\n3 8 21 43 78 100 102 105\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint bsearch(int target, int arr[], int n) {\\n // each iteration, \\n // look for ''target'' in ''arr[first]..arr[last-1]''\\n int first = 0;\\n int last = n;\\n \\n while (true) {\\n // empty range\\n if (first == last) {\\n return -1;\\n }\\n\\n if (last == first + 1) {\\n // we''re done, for better or worse\\n\\\\[\\n if (target == arr[first])\\n return first;\\n else\\n return -1;\\n]\\\\\\n }\\n\\n int mid = (last+first)/2;\\n // did we find it?\\n if (\\\\[target == arr[mid]]\\\\) {\\n \\\\[return mid;]\\\\\\n }\\n // continue the search in the appropriate half\\n else if (target > arr[mid]) {\\n \\\\[first = mid+1;]\\\\\\n }\\n else {\\n \\\\[last = mid;]\\\\\\n }\\n }\\n}\\n\\nint main() {\\n // read target, n, then n sorted inputs\\n int target, n;\\n cin >> target >> n;\\n int* arr = new int[n];\\n for (int i=0; i<n; i++)\\n cin >> arr[i];\\n\\n cout << bsearch(target, arr, n);\\n\\n delete [] arr;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(224, '[email protected]', 'cpp/recursion/monkey_recback', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nUsing recursion,\\ncreate a method <tt>printBackwards()</tt>\\nthat prints out all names in the list, one per line, <b>in reverse order</b>.\\nYou will need to declare and define a helper function.\\n", "verboten": "[\\"for\\", \\"while\\", \\"do\\"]", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printBackwards();\\n void addStart(string newName); // implementation not shown\\n private: \\n\\\\[\\n void helpPrintBackwards(Node* n);\\n]\\\\\\n Node* first;\\n};\\n\\\\hide[\\n// add a new node, containing this name, at the start of the list\\nvoid MonkeyChain::addStart(string newName) {\\n Node* newFirst = new Node(newName);\\n Node* oldFirst = first;\\n first = newFirst;\\n first->next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n}\\n]\\\\\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// private helper\\nvoid MonkeyChain::helpPrintBackwards(Node* n) {\\n\\\\[\\n if (n != NULL) {\\n helpPrintBackwards(n->next);\\n cout << n->name << endl;\\n }\\n]\\\\\\n}\\n\\nvoid MonkeyChain::printBackwards() {\\n\\\\[\\n helpPrintBackwards(first);\\n]\\\\\\n}\\n\\n\\nint main() {\\n MonkeyChain mc;\\n mc.threeKongs();\\n mc.printBackwards(); cout << endl;\\n\\n // test on 5 monkeys\\n mc.addStart(\\"King Kong\\");\\n mc.addStart(\\"Bubbles\\");\\n mc.printBackwards(); \\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(225, '[email protected]', 'cpp/recursion/monkey_reverse', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nUsing recursion,\\ncreate a method <tt>reverse()</tt>\\nthat reverses the elements in a linked list.\\nYou will need to declare and define a helper function.\\n", "verboten": "[\\"for\\", \\"while\\", \\"do\\"]", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll(); // not shown\\n void reverse();\\n private: \\n Node* helpReverse(Node* n); // reverse and return pointer to new start\\n Node* first;\\n};\\n\\\\hide[\\nvoid MonkeyChain::printAll() {\\n // one possible approach: use a while loop\\n Node* current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != NULL) {\\n // print current node''s name; then repeat loop w/next one\\n cout << current->name << endl;\\n current = current->next;\\n }\\n}\\n]\\\\\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// private helper: reverse list trailing from n (n moves to end), \\n// return new front\\nNode* MonkeyChain::helpReverse(Node* n) {\\n\\\\[\\n if (n == NULL) {\\n return NULL;\\n }\\n else if (n->next == NULL) {\\n return n; // nothing to reverse\\n }\\n else {\\n Node* tmp = helpReverse(n->next); // now n->next is at end\\n n->next->next = n; // move n past that end\\n n->next = NULL; // n is the end, fix its link\\n return tmp; // same new front\\n }\\n]\\\\\\n}\\n\\nvoid MonkeyChain::reverse() {\\n\\\\[\\n first = helpReverse(first);\\n]\\\\\\n}\\n\\n\\nint main() {\\n MonkeyChain mc;\\n mc.threeKongs();\\n mc.printAll(); cout << endl;\\n mc.reverse();\\n mc.printAll(); \\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(226, '[email protected]', 'cpp/control/primes', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that takes an integer input <tt>n</tt>, and prints \\nout all of the prime numbers less than or equal to <tt>n</tt>. \\n<p>\\nA number is prime if it has no divisors other than itself and one. \\nThe first few primes are 2, 3, 5, 7, 11, …\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"100\\"},\\n {\\"stdin\\": \\"17\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n int n;\\n cin >> n;\\n \\n for (int i=2; i<=n; i++) {\\n bool i_is_prime = true;\\n\\n for (int j=2; j<i; j++)\\n if (i%j == 0) // does j divide i? \\n i_is_prime = false;\\n\\n if (i_is_prime)\\n cout << i << endl;\\n }\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(227, '[email protected]', 'cpp/control/nested_break', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that does a <i>times table search</i>. \\nIt takes as input an integer N.\\nIt will print\\nout consecutive elements of a 9x9 times table, stopping printing\\nif it finds N in the table. For instance if the input is <tt>15</tt>, \\nit should output\\n<pre>\\n 1 2 3 4 5 6 7 8 9\\n 2 4 6 8 10 12 14 16 18\\n 3 6 9 12 15\\n\\nAll done!\\n</pre>\\nIf the input doesn''t appear in the table, all 9x9 entries should be printed.\\n<br>\\nA solution is given, but it uses <tt>break</tt> incorrectly: it assumes \\nthat it will stops all loops, but in reality it only stops the innermost loop.\\nFix it by using a boolean control variable.\\n", "verboten": "[\\"return\\"]", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"15\\"},\\n {\\"stdin\\": \\"12\\"},\\n {\\"stdin\\": \\"51\\"},\\n {\\"stdin\\": \\"49\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\nusing namespace std;\\n\\nint main() {\\n // declare variables\\n\\\\[\\n int N;\\n bool done = false;\\n\\\\show:\\n int N;\\n]\\\\\\n\\n cin >> N;\\n\\n for (int i=1; \\\\[i<10 && !done\\\\show:i<10]\\\\; i++) {\\n for (int j=1; j<10; j++) {\\n // print entry\\n cout << setw(3) << i*j;\\n\\n // quit if needed\\n if (i*j == N) {\\n\\\\[\\n done = true;\\n break;\\n\\\\show:\\n break;\\n]\\\\\\n }\\n }\\n cout << endl;\\n }\\n\\n cout << endl << \\"All done!\\";\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(228, '[email protected]', 'cpp/control/nth', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThis program should take a non-negative integer input <tt>n</tt>. \\nIt should print out the \\nEnglish <i>ordinal number</i> corresponding to <tt>n</tt>.\\nFor example,\\n<ul><li>for input <tt>1</tt> it should output <tt>1st</tt>\\n<li>for input <tt>2</tt> it should output <tt>2nd</tt>\\n<li>for input <tt>3</tt> it should output <tt>3rd</tt>\\n<li>for input <tt>4</tt> it should output <tt>4th</tt>\\n</ul>\\net cetera. \\n<p>Hint: the last digit is important, and you can compute the last\\ndigit using <tt>n % 10</tt>, which is the remainder when you divide <tt>n</tt>\\nby 10. You also need a special case when the last two digits are 11, 12, or 13.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"1\\"},\\n {\\"stdin\\": \\"2\\"},\\n {\\"stdin\\": \\"3\\"},\\n {\\"stdin\\": \\"4\\"},\\n {\\"stdin\\": \\"5\\"},\\n {\\"stdin\\": \\"6\\"},\\n {\\"stdin\\": \\"7\\"},\\n {\\"stdin\\": \\"8\\"},\\n {\\"stdin\\": \\"9\\"},\\n {\\"stdin\\": \\"10\\"},\\n {\\"stdin\\": \\"21\\"},\\n {\\"stdin\\": \\"132\\"},\\n {\\"stdin\\": \\"4323\\"},\\n {\\"stdin\\": \\"12984\\"},\\n {\\"stdin\\": \\"11\\"},\\n {\\"stdin\\": \\"212\\"},\\n {\\"stdin\\": \\"90013\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int n;\\n cin >> n;\\n\\\\[\\n if (n % 100 >= 11 && n % 100 <= 13)\\n cout << n << \\"th\\";\\n else if (n % 10 == 1)\\n cout << n << \\"st\\";\\n else if (n % 10 == 2)\\n cout << n << \\"nd\\";\\n else if (n % 10 == 3)\\n cout << n << \\"rd\\";\\n else\\n cout << n << \\"th\\";\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(229, '[email protected]', 'cpp/control/break_continue', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that reads any number of lines of text from the user.\\nIt should print out each one, with its line number. However,\\n<ul>\\n<li>if the line is <tt>SKIP</tt>, skip it\\n<li>if the line is <tt>DONE</tt>, stop reading completely\\n</ul>\\nE.g., for the input\\n<pre>\\nHello World\\nBonjour, Monde\\nSKIP\\nHallo, Welt\\nDONE\\nHola, Mundo\\n</pre>\\nthe output should be\\n<pre>\\n1 Hello World\\n2 Bonjour, Monde\\n3 Hallo, Welt\\nPrinted 3 lines.\\n</pre>\\n(The summary line logic is written for you already.)\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"Hello World\\\\nBonjour, Monde\\\\nSKIP\\\\nHallo, Welt\\\\nDONE\\\\nHola, Mundo\\\\n\\"},\\n {\\"stdin\\": \\"SKIP\\\\nSKIP\\\\nSKIP\\\\nto my loo\\\\nSKIP\\\\nto the loo\\\\nmy darling\\\\n\\"},\\n {\\"stdin\\": \\"apple\\\\norange\\\\nDONE\\\\nDONE\\\\nSKIP\\\\nbanana\\\\n\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n string line_of_text;\\n int counter = 0;\\n while (true) {\\n getline(cin, line_of_text);\\n if (cin.fail())\\n \\\\[break ]\\\\;\\n \\n if (line_of_text == \\"SKIP\\") \\n \\\\[continue]\\\\;\\n\\n if (line_of_text == \\"DONE\\") \\n \\\\[break ]\\\\;\\n\\n counter++;\\n cout << counter << \\" \\" << line_of_text << endl;\\n }\\n cout << \\"Printed \\" << counter << \\" lines.\\" << endl;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(230, '[email protected]', 'cpp/control/flag', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThe official flag of CSCI 103 is a right triangle pointing up-left,\\nwith <code>n</code> rows and <code>n</code> columns, made out of\\nbackslashes, where <code>n</code> is a command-line argument.\\nWrite a program to print it out for any positive integer <code>n</code>:\\nfor example\\n<code>./flag 5</code> should print out\\n<pre>\\n\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\n\\\\\\\\\\n\\\\\\n</pre>\\nThis tests two things: escaping in strings, and nested loops.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"5\\", \\"args\\": \\"\\"},\\n {\\"stdin\\": \\"10\\", \\"args\\": \\"\\"},\\n {\\"stdin\\": \\"1\\", \\"args\\": \\"\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int n;\\n cin >> n;\\n for (int i=0; \\\\[i<n; i++]\\\\) {\\n for (int j\\\\[=0; j<n-i; j++]\\\\) {\\n cout << \\\\[\\"\\\\\\\\\\"]\\\\;\\n }\\n cout << \\\\[endl]\\\\;\\n }\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(231, '[email protected]', 'cpp/control/countodd', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThis program reads in integers until the user enters a negative number. \\nFor each positive number that is input, the program should check whether that\\nnumber is odd and, if so, increment a count of how many odd numbers \\nhave been input. That total is output at the end of the program.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"0 100 48 47 55 3 -1\\"},\\n {\\"stdin\\": \\"-1\\"},\\n {\\"stdin\\": \\"1 3 5 7 -1\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int num_odds = 0;\\n int value = 0;\\n \\n // You may declare any additional variables below or add any additional\\n // code before the loop starts.\\n\\\\[ \\n\\n]\\\\\\n\\n // Then enter a condition in the while loop parentheses to continue\\n // receiving input until the user enters a negative number (i.e. -1).\\n // For each number input, check if it is odd and if so, increase\\n // ''num_odds'' by 1. \\n \\n while( \\\\[ value >= 0 ]\\\\ ) {\\n cout << \\"Enter a positive integer or -1 to quit:\\" << endl;\\n cin >> value;\\n\\\\[\\n if( value >= 0 ){\\n if( (value%2) == 1){\\n num_odds++;\\n }\\n }\\n]\\\\\\n }\\n\\n cout << \\"You entered \\" << num_odds << \\" odd numbers\\" << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(232, '[email protected]', 'cpp/control/5perlineC', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPrint the integers from 100 to 200, five per line.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\nfor (int i=100; i<=200; i++) {\\n cout << i << \\" \\";\\n if (i%5 == 4) cout << endl;}\\n\\\\show:\\n int i;\\n // print integers from 100 to 200, 5 per line\\n for (i = 100; i >= 200; i++) {\\n for (int j = 0; j < 5; j+=1) {\\n cout << i + j << \\" \\";\\n }\\n cout << endl;\\n }\\n cout << i;\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(233, '[email protected]', 'cpp/control/weekday', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nAsk the user to enter a number between 1-7 where 1 corresponds to Sunday,\\n2 corresponds to Monday, ..., and 7 corresponds to Saturday. \\nReceive the integer input from the user and output the word \\n<code>weekday</code> if the day is Monday-Friday. Output the word \\n<code>weekend</code> if the day is Saturday-Sunday. Output nothing\\nat all if the user enters a number that''s not in the range 1-7.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"-1\\"},\\n {\\"stdin\\": \\"0\\"},\\n {\\"stdin\\": \\"1\\"},\\n {\\"stdin\\": \\"2\\"},\\n {\\"stdin\\": \\"3\\"},\\n {\\"stdin\\": \\"4\\"},\\n {\\"stdin\\": \\"6\\"},\\n {\\"stdin\\": \\"7\\"},\\n {\\"stdin\\": \\"8\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n\\n cout << \\"Enter an integer between 1-7 (1=Sun. to 7=Sat.)\\" << endl;\\n\\n // Receive the number between 1-7 and if the corresponding day is\\n // a \\"weekday\\" or \\"weekend\\" output that single word. Output nothing\\n // if the user outputs a number outside the range 1-7.\\n \\n\\\\[\\n int day;\\n cin >> day;\\n if(day == 1 || day == 7){\\n cout << \\"weekend\\";\\n }\\n else if( day >= 2 && day <= 6){\\n cout << \\"weekday\\";\\n }\\n]\\\\\\n\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(234, '[email protected]', 'cpp/control/timestable', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that prints out a multiplication table. It should\\ntake an input <tt>n</tt>. The output\\nshould have <tt>n</tt> rows and <tt>n</tt> columns, and be \\nformatted in 4-space wide \\ncolumns, like this example output when the input <tt>n</tt> is 5:\\n<pre>\\n 1 2 3 4 5\\n 2 4 6 8 10\\n 3 6 9 12 15\\n 4 8 12 16 20\\n 5 10 15 20 25\\n</pre>\\nUse <tt>cout << setw(4) << [thing you want to print]</tt> with each item printed, in order to get the column-based layout.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"5\\"},\\n {\\"stdin\\": \\"10\\"},\\n {\\"stdin\\": \\"15\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\nusing namespace std;\\n\\nint main() {\\n // get the input\\n int n;\\n cin >> n;\\n\\n // to print out fixed-width columns, print out each item with\\n // cout << setw(4) << \\"item\\"; // see page 49\\n\\\\[\\n for (int j=1; j<=n; j++) {\\n\\n // print items in a row\\n for (int i=1; i<=n; i++) \\n cout << setw(4) << i*j;\\n\\n // end the row\\n cout << endl;\\n }\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(235, '[email protected]', 'cpp/control/revdigits', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThis program should take an integer input (which could be negative) and\\noutputs the string of digits of the number in reverse order. If the number\\nis negative you should still output a negative sign first.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"-14539\\"},\\n {\\"stdin\\": \\"-321\\"},\\n {\\"stdin\\": \\"321\\"},\\n {\\"stdin\\": \\"0\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\nusing namespace std;\\n\\nint main() {\\n int n;\\n int revn;\\n\\n // write code that allows the user to enter a non-zero integer \\n // which could be either (pos. or neg). and then \\n // outputs the number with digits reversed\\n // Example 1: 321 outputs: 123\\n // Example 2: -14539 outputs: -93541\\n // Output a newline after you output the digits in reverse.\\n\\n cout << \\"Enter an integer: \\" << endl;\\n cin >> n;\\n\\n\\\\[ \\n if(n == 0) { cout << 0; }\\n else {\\n if(n < 0){\\n cout << \\"-\\";\\n n = -n;\\n }\\n while( n > 0 ) {\\n cout << n%10;\\n n = n/10;\\n }\\n }\\n cout << endl;\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(236, '[email protected]', 'cpp/control/5perlineB', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPrint the integers from 100 to 200, five per line.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\nfor (int i=100; i<=200; i++) {\\n cout << i << \\" \\";\\n if (i%5 == 4) cout << endl;}\\n\\\\show:\\n int i;\\n // print integers from 100 to 200, 5 per line\\n for (i = 100; i <= 200; i--) {\\n for (int j = 0; j < 5; j+=1) {\\n cout << i + j << \\" \\";\\n }\\n cout << endl;\\n }\\n cout << i;\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(237, '[email protected]', 'cpp/control/liebnizapprox', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThis program should use a loop to compute the result of the first 10\\nterms of Leibniz''s approximation of $\\\\pi/4$. See the comment in the code\\nfor the exact terms.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\n#include <cmath>\\nusing namespace std;\\n\\nint main() {\\n double approx;\\n\\n // write code that includes a for loop to compute the first 10\\n // terms of Liebniz''s approximation to PI/4 which is:\\n // (1/1) - (1/3) + (1/5) - (1/7) + ... - (1/19)\\n\\\\[ \\n approx = 0.0;\\n for(int i=0; i < 10; i++){\\n approx += pow(-1,i)/(2*i+1);\\n }\\n\\n]\\\\\\n\\n cout << \\"The approximate value is \\";\\n cout << fixed << setprecision(3) << approx << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(238, '[email protected]', 'cpp/control/badloops', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that takes two inputs <tt>h</tt> and <tt>w</tt>\\nand draws a grid of equals signs of height <tt>h</tt> and width <tt>w</tt>.\\nE.g. if the input is <tt>2 3</tt> the output should be:\\n<pre>\\n===\\n===\\n</pre>\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"2 3\\"},\\n {\\"stdin\\": \\"10 4\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int h, w;\\n cin >> h >> w;\\n\\\\[\\n for (int i=0; i<h; i++) {\\n for (int j=0; j<w; j++) {\\n cout << \\"=\\";\\n }\\n cout << endl;\\n }\\n\\\\show:\\n int i;\\n for (i=0; i<h; i++) {\\n for (i=0; i<w; i++) {\\n cout << \\"=\\";\\n }\\n cout << endl;\\n }\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(239, '[email protected]', 'cpp/control/examples/sumsquares', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nThis program computes the sum of the first 10 integers'' squares.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int total = 0; // start at 0\\n\\n for (int i = 1; i <= 10; i += 1) // i = 1, 2, ... 10\\n {\\n total = total + i*i; // increase total\\n }\\n\\n cout << total;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(240, '[email protected]', 'cpp/control/checkerboard', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThis program takes an integer input <tt>n</tt>.\\nPrint out a checkerboard with <tt>n</tt> rows and \\n<tt>n</tt> columns in a checkerboard pattern of stars; e.g. when <tt>n</tt>\\nis 4:\\n<pre>\\n* * \\n * *\\n* *\\n * *\\n</pre>\\nThe top-left should always be a star.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"4\\"},\\n {\\"stdin\\": \\"5\\"},\\n {\\"stdin\\": \\"10\\"},\\n {\\"stdin\\": \\"15\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int n;\\n cin >> n;\\n\\\\[\\n for (int i=0; i<n; i++) {\\n if (i % 2 == 0)\\n for (int j=0; j<n; j++) {\\n if (j % 2 == 0)\\n cout << \\"*\\";\\n else\\n cout << \\" \\";\\n }\\n else\\n for (int j=0; j<n; j++) {\\n if (j % 2 == 1)\\n cout << \\"*\\";\\n else\\n cout << \\" \\";\\n }\\n cout << endl;\\n } \\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(241, '[email protected]', 'cpp/control/5perlineA', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPrint the integers from 100 to 200, five per line.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\nfor (int i=100; i<=200; i++) {\\n cout << i << \\" \\";\\n if (i%5 == 4) cout << endl;}\\n\\\\show:\\n int i;\\n // print integers from 100 to 200, 5 per line\\n for (i = 100; i < 200; i+=5) {\\n for (j = 0; j < 5; j+=1) {\\n cout << i + j << \\" \\";\\n }\\n cout << endl;\\n }\\n cout << i;\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(242, '[email protected]', 'cpp/control/examples/nested', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWhat does this program do?\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n\\n\\\\show:\\n for (int i=0; i<12; i++) {\\n if (i % 3 == 2) {\\n for (int j=0; j<i; j++) {\\n cout << \\"*\\";\\n }\\n cout << endl;\\n }\\n }\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(243, '[email protected]', 'cpp/control/discount', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThis program reads in an integer number of items a user wants to buy and\\nthen computes the final cost. Items cost <b><i>$</i>5 each</b> but customers will\\nreceive a <b><i>$</i>10 discount (i.e. subtract <i>$</i>10 from their total)</b> if their\\ntotal bill is at least <i>$</i>50. You should receive input from user and\\ncompute the final cost in the variable <code>cost</code>.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"9\\"},\\n {\\"stdin\\": \\"10\\"},\\n {\\"stdin\\": \\"1000\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int cost;\\n cout << \\"Enter the number of items you wish to buy?\\" << endl;\\n // Receive the number of items and calculate the total cost\\n // Recall items cost $5 each with a $10 discount if the total is \\n // at least $50\\n \\n\\\\[\\n int items;\\n cin >> items;\\n cost = 5*items;\\n if(cost >= 50){\\n cost -= 10;\\n }\\n]\\\\\\n\\n cout << \\"Final cost is \\" << cost << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(244, '[email protected]', 'cpp/control/isprime', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that takes an integer input <tt>n</tt>, and prints \\nwhether that number is prime or not.<p>\\nA number is prime if it has no divisors other than itself and one. \\nThe first few primes are 2, 3, 5, 7, 11, …\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"100\\"},\\n {\\"stdin\\": \\"17\\"},\\n {\\"stdin\\": \\"3\\"},\\n {\\"stdin\\": \\"4\\"},\\n {\\"stdin\\": \\"37\\"},\\n {\\"stdin\\": \\"39\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cmath>\\nusing namespace std;\\n\\n\\\\[ bool ]\\\\ isPrime( \\\\[ int n ]\\\\ )\\n{\\n\\\\[\\n for(int i=2; i < sqrt(n); i++){\\n if (n%i == 0) // does i divide n? \\n return false;\\n }\\n return true;\\n]\\\\\\n}\\nint main() {\\n int n;\\n cin >> n;\\n \\n if ( isPrime(n) ) {\\n cout << n << \\" is prime!\\" << endl;\\n }\\n else {\\n cout << n << \\" is NOT prime!\\" << endl;\\n }\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(245, '[email protected]', 'cpp/control/wallisapprox', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThis program should use a loop to compute the result of the first 10\\nterms of Wallis'' approximation of PI/2. See the comment in the code\\nfor the exact terms.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\nusing namespace std;\\n\\nint main() {\\n double approx;\\n\\n // write code that includes a for loop to compute the first 10\\n // terms of Wallis'' approximation to PI/2 which is:\\n // (2/1)*(2/3)*(4/3)*(4/5)*(6/5)*(6/7)*(8/7)*(8/9)*(10/9)*(10/11)\\n\\\\[ \\n approx = 1.0;\\n for(int i=2; i <= 10; i+=2){\\n approx = approx * ( static_cast<double>(i) / (i-1) );\\n approx = approx * ( static_cast<double>(i) / (i+1) );\\n }\\n\\n]\\\\\\n\\n cout << \\"The approximate value is \\";\\n cout << fixed << setprecision(3) << approx << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(246, '[email protected]', 'cpp/cppstrings/examples/stringeg', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of <tt>string</tt>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n\\n\\\\show:\\n cout << boolalpha;\\n// parallel syntax for construction, like\\n// int x = 5;\\n string name = \\"Bobby\\";\\n cout << name << endl; // Bobby\\n\\n string place = name; // deep copy\\n cout << (place == name) << endl; // deep compare: true\\n\\n place[0] = ''L'';\\n cout << name << \\" \\" << place << endl; // Bobby Lobby\\n cout << (place == name) << endl; // deep compare: false\\n\\n // member functions (dot notation!)\\n cout << place.length() << endl; // 5\\n cout << place.substr(2, 2) << endl; // bb\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(247, '[email protected]', 'cpp/cppstrings/complement', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a function <tt>string complement(string dna)</tt>\\nthat takes a string containing only the capital letters <tt>A</tt>, <tt>C</tt>,\\n <tt>T</tt>, <tt>G</tt>,\\n(representing DNA), and returns its <i>Watson-Crick complement</i>:\\nreplace <tt>A</tt> with <tt>T</tt>, <tt>C</tt> with <tt>G</tt>, and vice-versa.\\n\\n<p>For example, <tt>complement(\\"GATTACA\\")</tt> should return \\n<tt>\\"CTAATGT\\"</tt>. (You may assume the input is valid, there is no need\\nto check for non-DNA characters.)\\n\\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"complement\\", \\"string\\", [\\"string\\"]],\\n [\\"call-function\\", \\"complement\\", [\\"\\\\\\"GAATTACA\\\\\\"\\"]],\\n [\\"call-function\\", \\"complement\\", [\\"\\\\\\"CAT\\\\\\"\\"]],\\n [\\"call-function\\", \\"complement\\", [\\"\\\\\\"TAGACAT\\\\\\"\\"]],\\n [\\"call-function\\", \\"complement\\", [\\"\\\\\\"GCGAGTGAGC\\\\\\"\\"]],\\n [\\"call-function\\", \\"complement\\", [\\"\\\\\\"\\\\\\"\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// replace all ''C''s with ''G''s and vice-versa\\n// replace all ''A''s with ''T''s and vice-versa\\nstring complement(string dna) {\\n\\\\[\\n string result = dna; // create string of same length\\n int n = dna.length();\\n for (int i=0; i<n; i++) {\\n if (dna[i] == ''C'')\\n result[i] = ''G'';\\n else if (dna[i] == ''G'')\\n result[i] = ''C'';\\n else if (dna[i] == ''A'')\\n result[i] = ''T'';\\n else if (dna[i] == ''T'')\\n result[i] = ''A'';\\n }\\n return result;\\n]\\\\\\n}"}', '2015-07-02 22:07:05', 'save', 'open'),
(248, '[email protected]', 'cpp/cppstrings/palindrome', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nA <i>palindrome</i> is a string that reads the same forwards or backwards,\\nlike <tt>\\"RADAR\\"</tt> or <tt>\\"STOOTS\\"</tt>.\\nDefine a function <tt>palindrome</tt> \\nthat takes as input a string and returns true if the \\nstring is a palindrome, and false otherwise. You will need to use\\nthe <tt>[i]</tt> operator and <tt>length()</tt> method.\\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"palindrome\\", \\"bool\\", [\\"string\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"racecar\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"ferrari\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"foolproof\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"cool\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"rester\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"redder\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"pinker\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"radar\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"rider\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"o\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"ok\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"kk\\\\\\"\\"]],\\n [\\"call-function\\", \\"palindrome\\", [\\"\\\\\\"\\\\\\"\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nbool palindrome(string s) {\\n\\\\[\\n// it''s only necessary to do half the length many checks\\nfor (int i=0; i<s.length()/2; i++) {\\n // look at ith character from start and end\\n if (s[i] != s[s.length()-i-1])\\n return false;\\n}\\n\\nreturn true; // everything matched\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(249, '[email protected]', 'cpp/cppstrings/circ_shift', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nA string <tt>S</tt> is a <i>circular shift</i> of a string <tt>T</tt>\\nif they are of the same length, and when written in clockwise circles,\\nthey are the same except for a rotation. For example, <tt>STOP</tt> and\\n<tt>TOPS</tt> are circular shifts of each other,\\nas are <tt>STRING</tt> and <TT>RINGST</tt>. But <tt>STOP</tt> and\\n<tt>POTS</tt> are not circular shifts of one another, nor are \\n<tt>CAT</tt> and <tt>ACT</tt>.\\n\\n<p>\\nWrite a static boolean method\\n<tt>is_circular_shift(string S, string T)</tt>\\nthat determines whether two strings are circular shifts of one another.\\n\\n<p>\\nOne approach is to use <tt>length()</tt>, <tt>+</tt> and <tt>find()</tt>.\\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"is_circular_shift\\", \\"bool\\", [\\"string\\", \\"string\\"]],\\n [\\"call-function\\", \\"is_circular_shift\\", [\\"\\\\\\"POTS\\\\\\"\\", \\"\\\\\\"SPOT\\\\\\"\\"]],\\n [\\"call-function\\", \\"is_circular_shift\\", [\\"\\\\\\"TOPS\\\\\\"\\", \\"\\\\\\"STOP\\\\\\"\\"]],\\n [\\"call-function\\", \\"is_circular_shift\\", [\\"\\\\\\"TOPS\\\\\\"\\", \\"\\\\\\"SPOT\\\\\\"\\"]],\\n [\\"call-function\\", \\"is_circular_shift\\", [\\"\\\\\\"ABBA\\\\\\"\\", \\"\\\\\\"AABB\\\\\\"\\"]],\\n [\\"call-function\\", \\"is_circular_shift\\", [\\"\\\\\\"BYEBYE\\\\\\"\\", \\"\\\\\\"BYE\\\\\\"\\"]],\\n [\\"call-function\\", \\"is_circular_shift\\", [\\"\\\\\\"HI\\\\\\"\\", \\"\\\\\\"HIHI\\\\\\"\\"]],\\n [\\"call-function\\", \\"is_circular_shift\\", [\\"\\\\\\"TESTCASE\\\\\\"\\", \\"\\\\\\"TESTCASE\\\\\\"\\"]],\\n [\\"call-function\\", \\"is_circular_shift\\", [\\"\\\\\\"find()\\\\\\"\\", \\"\\\\\\"()find\\\\\\"\\"]],\\n [\\"call-function\\", \\"is_circular_shift\\", [\\"\\\\\\"find()\\\\\\"\\", \\"\\\\\\"(find)\\\\\\"\\"]]\\n]\\n", "source_code": "\\n#include <string>\\nusing namespace std;\\n\\nbool is_circular_shift(string s, string t) {\\n\\\\[\\n return s.length() == t.length() && (s+s).find(t)!=string::npos;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(250, '[email protected]', 'cpp/cppstrings/namegame', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThe function <tt>namegame(string s)</tt> should return\\na string which is the same as its input, except\\nstarting with <tt>Z</tt>.\\n<p>\\nFor example <tt>namegame(\\"David\\")</tt> returns <tt>\\"Zavid\\"</tt>.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"Rumpelstiltskin\\"},\\n {\\"stdin\\": \\"Wolfeschlegelsteinhausenbergerdorff\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// avoid copying the long name\\nstring namegame(const string& name) {\\n\\\\[\\n return \\"Z\\" + name.substr(1);\\n\\\\show:\\n name[0] = ''Z''; // whoops\\n return name;\\n]\\\\\\n} \\n\\nint main() {\\n string name;\\n cin >> name;\\n cout << \\"My name is: \\" << name << endl;\\n cout << \\"Ziggity Zap \\" << namegame(name) << endl;\\n cout << \\"My name is: \\" << name << endl; // should be unchanged\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(251, '[email protected]', 'cpp/exam_practice/FoodPart1', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPlease see <a href=\\"http://bits.usc.edu/cs103/programming-exam/\\">the programming exam page</a>.\\n<br>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"6 3\\\\nGER 1 13 20\\\\nBEL 15 15 15\\\\nAUT 17 18 3\\\\nCHF 19 7 19\\\\nLUX 14 14 15\\\\nLIE 7 8 9\\"},\\n {\\"stdin\\": \\"3 6\\\\nCanada 10 16 10 20 14 10\\\\nMexico 14 14 14 14 14 14\\\\nUSA 7 14 20 12 15 16\\"},\\n {\\"stdin\\": \\"1 3\\\\nPangaea 8 8 8\\"},\\n {\\"stdin\\": \\"6 3\\\\nLMH 1 2 3\\\\nLHM 4 6 5\\\\nMLH 8 7 9\\\\nMHL 11 12 10\\\\nHLM 15 13 14\\\\nHML 18 17 16\\"},\\n {\\"stdin\\": \\"6 3\\\\nLLH 1 1 9\\\\nLHL 1 9 1\\\\nHLL 9 1 1\\\\nLHH 1 9 9\\\\n HLH 9 1 9\\\\nHHL 9 9 1\\"},\\n {\\"stdin\\": \\"2 3\\\\noneLand 1 1 1\\\\ntwentyStan 20 20 20\\"},\\n {\\"stdin\\": \\"4 4\\\\nmaxRepeat 18 18 7 5\\\\nminRepeat 6 6 12 19\\\\nbothRepeat 4 4 12 12\\\\nfours 4 4 4 4\\"}\\n]\\n", "source_code": "\\n// NOTE: The actual exam will not use Websheets (instead, the PA submit system).\\n// It''s recommended to practice and test on your own machine and copy here to check.\\n \\\\[\\n/*******************************************************************\\n Reference solution for Foodlympics Part One: Competitive Cuisine\\n\\n Description: Reads in judge rankings for C countries by J judges.\\n Prints out the rounded average score for each country,\\n excluding the min and max.\\n**************************************************************************/\\n\\n#include <iostream>\\n#include <cmath> // for round\\nusing namespace std;\\n\\n// excluding the min and max, compute the rounded average\\n// of the entries of judgeRatings\\n// J is the number of judges\\nint score(int judgeRatings[], int J) {\\n\\n int sum = 0;\\n int min = judgeRatings[0];\\n int max = judgeRatings[0];\\n\\n for (int i = 0; i < J; i++) {\\n if (judgeRatings[i] > max)\\n max = judgeRatings[i];\\n if (judgeRatings[i] < min)\\n min = judgeRatings[i];\\n sum += judgeRatings[i];\\n } \\n\\n // eliminate min and max\\n sum = sum - min - max;\\n \\n // average\\n double ave = sum / (double) (J - 2);\\n \\n // rounded average, excluding min and max\\n int score = (int) round(ave);\\n return score;\\n}\\n\\n// read the judges'' ratings for several countries\\n// from standard input and print their overall scores\\n// to standard output\\nint main() {\\n int C; // number of countries\\n int J; // number of judges\\n cin >> C >> J; // read the input\\n\\n cout << C << endl; // first line of output\\n\\n // for each country, process their ratings\\n for (int i = 0; i < C; i++) {\\n\\n // read the next line of input\\n string name;\\n cin >> name;\\n\\n int ratings[100];\\n for (int j = 0; j < J; j++)\\n cin >> ratings[j];\\n\\n // compute the overall score\\n int overall = score(ratings, J);\\n\\n // output for this country\\n cout << name << \\" \\" << overall << endl;\\n }\\n}\\n ]\\\\ \\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(252, '[email protected]', 'cpp/exam_practice/SnowStats', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPlease see <a href=\\"http://bits.usc.edu/cs103/programming-exam/\\">the programming exam page</a>.\\n<br>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\"},\\n {\\"stdin\\": \\"8.0 12\\\\n12.0 -5\\\\n0.0 -2\\\\n2.4 6\\\\n0.9 23\\\\n0.1 23\\\\n1.3 39\\"},\\n {\\"stdin\\": \\"108.0 200\\\\n102.7 200\\\\n10000 200\\"},\\n {\\"stdin\\": \\"102.0 -199\\\\n100.0 -145\\\\n102.4 -200\\\\n101.9 -119\\\\n104.4 -126\\"},\\n {\\"stdin\\": \\"0.0 13\\"},\\n {\\"stdin\\": \\"1.6 27\\\\n0.1 -4\\\\n1.5 26\\\\n3.4 77\\\\n7.7 -13\\\\n3.6 75\\\\n6.0 -10\\\\n7.5 49\\\\n6.2 -6\\\\n4.7 -36\\\\n8.1 49\\\\n7.6 -18\\\\n0.8 -25\\\\n2.0 31\\\\n1.1 69\\\\n6.6 27\\\\n9.6 -26\\\\n4.4 -7\\\\n8.6 -11\\\\n3.1 51\\\\n8.0 -26\\\\n3.1 71\\\\n2.3 -4\\\\n6.6 50\\\\n3.0 36\\\\n4.0 62\\\\n1.4 30\\\\n2.8 -4\\\\n5.3 53\\\\n4.5 12\\\\n6.9 -34\\\\n9.5 25\\\\n9.6 31\\\\n6.8 -20\\\\n6.6 36\\\\n9.3 59\\\\n1.8 32\\\\n7.4 8\\\\n0.2 -35\\\\n5.8 14\\\\n3.3 7\\\\n1.4 33\\\\n0.0 0\\\\n2.3 42\\\\n2.1 15\\\\n8.7 40\\\\n3.9 -30\\\\n0.5 76\\\\n3.7 -11\\\\n10.0 74\\\\n9.3 18\\\\n2.3 21\\\\n8.1 23\\\\n3.0 77\\\\n3.0 60\\\\n9.8 3\\\\n7.3 12\\\\n2.8 -11\\\\n0.8 35\\\\n1.6 24\\\\n9.2 -27\\\\n6.2 -16\\\\n0.5 51\\\\n8.4 77\\\\n9.5 -40\\\\n7.0 -2\\\\n6.6 -16\\\\n8.2 -30\\\\n1.5 65\\\\n5.6 52\\\\n1.1 -40\\\\n7.0 71\\\\n8.7 -15\\\\n7.8 -10\\\\n8.2 14\\\\n4.3 -7\\\\n8.6 61\\\\n8.1 -39\\\\n5.7 4\\\\n3.1 53\\\\n1.0 74\\\\n8.0 20\\\\n8.8 -14\\\\n3.3 60\\\\n1.7 16\\\\n2.6 -9\\\\n1.6 1\\\\n7.0 51\\\\n7.2 -21\\\\n6.1 33\\\\n3.5 20\\\\n6.5 9\\\\n5.5 -15\\\\n2.0 39\\\\n0.5 7\\\\n1.2 39\\\\n\\"}\\n]\\n", "source_code": "\\n// NOTE: The actual exam will not use Websheets (instead, the PA submit system).\\n// It''s recommended to practice and test on your own machine and copy here to check.\\n \\\\[\\n\\n/****************************************************************************\\n* Solution for Exam Part 1: SnowStats\\n*\\n* Description: Inputs snowfall and temperature for a series of days.\\n* Outputs number of days, total inches of snow and coldest temp.\\n*****************************************************************************/\\n\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n // start at day zero, no snow, hottest possible temperature\\n int days = 0;\\n double snowSum = 0.0;\\n int lowestTemp = 200; // from exam text\\n\\n // read data from standard input and count days\\n // add snowfall for total, keep lowest temp\\n while (!cin.fail()) {\\n double snow;\\n cin >> snow;\\n int temp;\\n cin >> temp;\\n \\n if (!cin.fail()) {\\n days++;\\n snowSum = snowSum + snow;\\n if (temp < lowestTemp) lowestTemp = temp;\\n } \\n }\\n cout << \\"Number of days: \\" << days << endl;\\n cout << \\"Total snow: \\" << snowSum << endl;\\n cout << \\"Coldest temperature: \\" << lowestTemp << endl;\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:05', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(253, '[email protected]', 'cpp/exam_practice/HatsPart2', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPlease see <a href=\\"http://bits.usc.edu/cs103/programming-exam/\\">the programming exam page</a>.\\n<br>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"9\\\\n9 8 7 6 5 4 3 2 1\\\\n3 7 6 9 8 2 1 5 4\\"},\\n {\\"stdin\\": \\"6\\\\n1 2 6 4 3 5\\\\n6 1 5 4 3 2\\"},\\n {\\"stdin\\": \\"9\\\\n1 2 3 4 5 6 7 8 9\\\\n9 8 7 6 5 4 3 2 1\\\\n2 1 4 3 6 5 8 7 9\\\\n8 9 2 1 4 7 5 3 6\\\\n3 7 6 9 8 2 1 5 4\\"},\\n {\\"stdin\\": \\"15\\\\r\\\\n13 2 6 4 5 8 1 7 14 12 3 10 11 9 15 \\\\r\\\\n12 8 7 5 9 10 1 14 13 2 4 3 11 15 6 \\\\r\\\\n11 3 14 15 12 9 8 1 5 7 10 4 6 13 2 \\\\r\\\\n3 2 4 14 6 7 12 13 9 5 8 11 15 10 1 \\\\r\\\\n7 12 3 4 6 2 8 10 5 13 1 14 9 15 11 \\\\r\\\\n14 7 4 9 1 5 3 12 11 8 10 13 2 6 15 \\\\r\\\\n12 7 3 2 14 1 5 15 6 8 4 13 10 11 9 \\\\r\\\\n1 9 11 14 6 10 5 12 3 8 13 2 15 7 4 \\\\r\\\\n15 10 2 5 12 1 8 7 11 6 13 3 9 14 4 \\\\r\\\\n14 7 6 8 9 4 2 10 5 12 3 1 11 13 15 \\\\r\\\\n9 10 15 12 2 13 11 7 1 8 3 5 4 14 6 \\\\r\\\\n11 4 15 8 10 9 13 2 14 1 3 6 5 7 12 \\\\r\\\\n2 12 4 10 3 6 15 13 1 8 14 7 5 9 11 \\\\r\\\\n14 3 12 11 4 7 9 6 10 2 13 8 1 5 15 \\\\r\\\\n1 10 5 3 12 11 7 15 8 13 6 4 9 2 14 \\\\r\\\\n11 13 7 2 6 14 1 12 3 5 9 10 4 15 8 \\\\r\\\\n6 9 11 3 12 5 1 7 13 2 15 14 8 4 10 \\\\r\\\\n3 14 4 2 10 8 13 1 5 15 6 7 11 12 9 \\\\r\\\\n7 10 6 15 9 11 14 13 8 1 4 5 2 3 12 \\\\r\\\\n7 2 3 5 14 12 13 9 11 8 6 4 1 15 10 \\\\r\\\\n10 2 8 15 5 1 9 4 3 11 13 7 6 12 14 \\\\r\\\\n1 11 10 6 2 4 8 13 14 12 7 3 15 9 5 \\\\r\\\\n2 14 6 11 7 4 10 13 1 5 15 3 9 12 8 \\\\r\\\\n7 10 4 3 8 1 15 14 2 5 6 11 12 9 13 \\\\r\\\\n10 4 15 5 12 2 8 6 14 1 13 3 9 7 11 \\\\r\\\\n7 11 15 9 2 3 10 4 5 14 8 12 13 6 1 \\\\r\\\\n8 10 15 5 2 11 3 9 1 13 7 12 6 4 14 \\\\r\\\\n14 1 15 9 12 13 6 2 11 3 5 10 7 4 8 \\\\r\\\\n2 8 10 1 11 12 3 13 9 4 14 15 7 5 6 \\\\r\\\\n10 14 9 2 5 6 1 8 13 4 15 11 3 12 7 \\\\r\\\\n5 7 11 1 14 9 4 15 2 3 13 10 8 6 12 \\\\r\\\\n4 8 3 13 2 7 9 14 5 10 1 6 15 12 11 \\\\r\\\\n12 10 11 14 4 5 9 8 15 7 13 2 1 3 6 \\\\r\\\\n7 5 15 3 13 9 8 6 2 1 12 10 4 11 14 \\\\r\\\\n10 8 4 11 1 2 9 13 5 12 6 7 15 14 3 \\\\r\\\\n3 9 15 7 11 1 2 13 5 14 4 10 12 6 8 \\\\r\\\\n10 2 9 4 11 3 15 1 14 7 8 12 6 13 5 \\\\r\\\\n2 12 5 14 8 11 7 6 1 9 4 15 10 13 3 \\\\r\\\\n6 10 13 1 5 8 4 3 12 14 2 7 15 9 11 \\\\r\\\\n6 14 12 8 11 13 15 10 9 4 7 1 3 2 5 \\\\r\\\\n7 11 9 4 3 13 15 12 6 14 10 8 5 1 2 \\\\r\\\\n14 6 8 3 9 4 13 11 2 10 15 12 7 5 1 \\\\r\\\\n14 4 6 3 15 8 11 9 12 10 1 7 5 13 2 \\\\r\\\\n4 14 13 2 3 12 5 15 10 11 1 8 6 7 9 \\\\r\\\\n5 8 11 6 4 1 13 7 3 15 9 12 2 10 14 \\\\r\\\\n2 10 14 11 3 7 5 9 4 15 6 1 8 12 13 \\\\r\\\\n10 1 5 14 3 4 15 12 8 13 7 11 6 2 9 \\\\r\\\\n15 7 1 10 4 11 13 8 6 12 2 5 3 9 14 \\\\r\\\\n14 4 13 2 6 12 11 3 7 8 15 9 1 5 10 \\\\r\\\\n9 8 12 11 5 3 10 14 13 1 6 15 2 7 4 \\\\r\\\\n13 12 10 3 15 1 7 5 4 6 11 8 9 14 2 \\\\r\\\\n2 13 8 6 3 7 4 9 5 12 10 14 1 11 15 \\\\r\\\\n4 1 8 5 15 12 6 10 13 2 3 14 11 9 7 \\\\r\\\\n5 1 9 8 14 12 2 15 4 11 7 3 10 6 13 \\\\r\\\\n8 4 13 3 11 7 10 2 15 6 14 9 5 1 12 \\\\r\\\\n10 11 6 2 3 7 8 13 15 12 14 1 4 9 5 \\\\r\\\\n10 4 14 3 1 5 7 6 13 15 9 11 12 8 2 \\\\r\\\\n4 13 8 11 9 14 10 1 15 6 5 2 7 3 12 \\\\r\\\\n12 14 1 15 9 10 5 7 11 8 4 13 6 2 3 \\\\r\\\\n2 8 9 11 4 6 15 10 12 7 14 13 3 1 5 \\\\r\\\\n3 10 6 13 8 2 14 11 5 15 4 7 1 12 9 \\\\r\\\\n7 1 5 9 8 12 3 6 4 15 11 13 10 14 2 \\\\r\\\\n15 2 5 6 3 10 8 14 1 7 12 11 9 4 13 \\\\r\\\\n4 13 5 11 10 7 9 15 3 14 12 2 8 6 1 \\\\r\\\\n13 7 5 6 10 3 2 1 11 9 8 14 12 4 15 \\\\r\\\\n11 14 10 3 12 9 2 15 13 8 5 4 1 6 7 \\\\r\\\\n14 15 9 12 3 8 10 2 6 13 4 7 11 5 1 \\\\r\\\\n11 12 4 8 13 14 1 6 10 15 2 3 5 9 7 \\\\r\\\\n3 8 4 1 12 15 7 14 9 6 10 11 5 13 2 \\\\r\\\\n8 2 13 7 6 10 1 14 4 11 15 9 3 12 5 \\\\r\\\\n6 2 5 13 8 4 15 1 7 12 10 9 3 14 11 \\\\r\\\\n9 3 13 11 5 14 15 7 1 4 2 10 6 8 12 \\\\r\\\\n7 4 1 2 9 15 14 3 5 6 11 10 12 8 13 \\\\r\\\\n14 5 9 11 8 10 3 6 4 1 13 2 15 12 7 \\\\r\\\\n1 11 3 7 2 5 13 12 10 15 4 14 6 8 9 \\\\r\\\\n3 1 10 8 4 9 14 12 2 6 15 5 7 11 13 \\\\r\\\\n4 5 7 10 12 14 9 15 8 3 2 11 13 6 1 \\\\r\\\\n5 10 6 12 2 15 1 14 4 3 13 7 11 9 8 \\\\r\\\\n5 12 1 7 6 15 14 10 9 3 13 2 4 8 11 \\\\r\\\\n2 14 12 7 9 6 3 5 13 15 4 11 1 8 10 \\\\r\\\\n1 11 4 10 7 14 8 2 6 3 13 5 15 12 9 \\\\r\\\\n12 5 9 14 6 4 7 11 1 15 3 13 10 8 2 \\\\r\\\\n1 12 15 14 2 6 5 7 3 9 8 4 13 10 11 \\\\r\\\\n14 8 15 6 5 3 12 2 9 10 11 7 1 13 4 \\\\r\\\\n9 7 2 13 1 6 4 11 12 8 15 5 10 3 14 \\\\r\\\\n15 10 3 1 2 9 6 13 12 8 7 14 11 5 4 \\\\r\\\\n1 13 11 2 3 15 14 8 6 9 4 12 5 7 10 \\\\r\\\\n5 13 6 15 1 10 7 8 9 3 12 14 4 2 11 \\\\r\\\\n1 8 14 5 15 4 10 7 3 2 6 9 13 12 11 \\\\r\\\\n9 11 6 1 3 10 13 15 14 8 5 4 12 2 7 \\\\r\\\\n5 2 12 10 1 11 13 8 14 9 7 15 4 6 3 \\\\r\\\\n3 6 5 15 12 7 13 8 14 4 2 1 11 10 9 \\\\r\\\\n15 10 6 2 4 12 13 8 9 14 7 1 3 5 11 \\\\r\\\\n11 9 13 8 14 12 6 2 7 4 3 10 1 5 15 \\\\r\\\\n11 2 9 6 10 12 5 13 1 4 7 15 3 8 14 \\\\r\\\\n10 15 2 6 5 4 11 9 13 8 14 3 1 12 7 \\\\r\\\\n1 15 7 4 3 12 9 2 14 11 8 10 5 13 6 \\\\r\\\\n4 1 14 12 13 6 15 10 2 7 8 11 3 9 5 \\\\r\\\\n11 9 6 15 1 4 13 10 3 12 14 5 2 8 7 \\\\r\\\\n5 13 15 14 1 7 10 11 4 9 3 12 2 8 6 \\\\r\\\\n1 7 10 11 12 4 13 5 15 3 14 6 2 8 9 \\\\r\\\\n5 7 9 15 12 10 2 8 1 4 13 11 3 6 14 \\\\r\\\\n12 3 8 10 9 1 15 11 14 13 2 4 5 7 6 \\\\r\\\\n3 15 8 13 12 10 1 2 11 9 7 14 4 5 6 \\\\r\\\\n1 11 4 6 13 10 15 2 8 12 14 7 3 5 9 \\\\r\\\\n11 7 2 13 1 8 5 12 10 14 4 9 3 15 6 \\\\r\\\\n9 4 13 6 1 5 14 12 15 8 2 11 10 3 7 \\\\r\\\\n14 15 8 9 6 12 5 1 11 4 13 2 10 7 3 \\\\r\\\\n5 10 7 12 3 2 8 6 4 11 1 15 13 14 9 \\\\r\\\\n7 1 8 5 4 6 10 2 9 12 15 3 14 11 13 \\\\r\\\\n10 6 8 12 9 11 1 13 2 3 14 4 5 7 15 \\\\r\\\\n4 7 13 11 6 15 5 8 2 1 9 14 12 10 3 \\\\r\\\\n5 6 10 7 12 14 2 1 9 11 3 15 8 4 13 \\\\r\\\\n8 5 2 11 7 14 15 3 6 10 9 12 1 13 4 \\\\r\\\\n13 14 3 9 7 1 11 4 8 12 2 10 5 6 15 \\\\r\\\\n3 12 9 1 2 5 15 14 7 10 6 11 8 13 4 \\\\r\\\\n10 5 1 7 9 14 12 6 3 8 13 15 4 2 11 \\\\r\\\\n10 7 13 15 11 5 14 6 9 1 2 4 3 8 12 \\\\r\\\\n7 9 5 14 11 4 3 12 13 15 2 6 8 1 10 \\\\r\\\\n3 10 7 14 9 2 6 15 12 4 8 13 5 1 11 \\\\r\\\\n3 9 12 1 4 11 13 15 6 5 8 10 7 14 2 \\\\r\\\\n9 1 8 2 6 10 3 12 11 4 15 5 14 13 7 \\\\r\\\\n15 11 6 3 8 12 1 5 2 13 7 10 14 9 4 \\\\r\\\\n7 13 6 5 2 14 11 8 1 12 9 15 10 4 3 \\\\r\\\\n15 11 7 8 1 14 2 9 12 13 4 3 5 6 10 \\\\r\\\\n9 6 10 4 15 3 12 5 1 11 13 2 8 7 14 \\\\r\\\\n4 15 5 1 6 9 2 11 8 10 12 3 7 13 14 \\\\r\\\\n6 4 8 13 12 2 10 15 7 3 5 14 9 1 11 \\\\r\\\\n10 12 3 2 9 8 13 6 4 15 5 1 11 14 7 \\\\r\\\\n9 12 1 6 8 5 2 13 4 7 3 10 14 11 15 \\\\r\\\\n6 10 15 3 11 9 4 5 13 7 1 14 2 8 12 \\\\r\\\\n12 6 2 8 1 11 9 15 3 14 5 4 10 13 7 \\\\r\\\\n2 15 8 6 12 3 7 10 4 14 1 11 9 13 5 \\\\r\\\\n4 14 7 2 6 5 12 9 13 3 10 8 15 1 11 \\\\r\\\\n10 11 1 5 9 13 14 8 12 15 2 7 4 6 3 \\\\r\\\\n12 7 2 11 9 14 5 1 8 6 15 10 13 4 3 \\\\r\\\\n14 13 12 3 15 5 1 4 11 10 7 2 8 6 9 \\\\r\\\\n9 15 14 5 11 7 13 12 1 3 4 2 6 10 8 \\\\r\\\\n10 1 3 9 4 14 2 11 12 15 13 7 6 8 5 \\\\r\\\\n15 3 13 6 12 2 1 7 5 8 9 11 14 4 10 \\\\r\\\\n7 14 3 9 1 15 4 2 8 13 12 11 10 6 5 \\\\r\\\\n1 2 8 7 5 4 3 11 14 6 13 10 9 15 12 \\\\r\\\\n10 9 6 1 8 11 7 4 14 3 2 5 13 12 15 \\\\r\\\\n8 9 1 2 3 15 6 10 12 13 14 7 5 11 4 \\\\r\\\\n15 13 6 2 9 1 14 7 3 10 11 8 12 5 4 \\\\r\\\\n13 15 12 1 5 9 7 11 8 6 4 10 3 14 2 \\\\r\\\\n3 13 11 9 12 15 4 1 8 6 5 7 14 10 2 \\\\r\\\\n7 3 9 14 13 4 8 5 10 6 2 11 1 15 12 \\\\r\\\\n9 2 1 14 12 4 15 8 6 13 10 11 5 3 7 \\\\r\\\\n1 15 4 12 7 9 10 14 8 5 3 2 13 6 11 \\\\r\\\\n11 7 2 13 3 9 8 12 4 1 10 5 6 15 14 \\\\r\\\\n11 15 4 7 8 14 9 6 3 1 2 10 12 13 5 \\\\r\\\\n2 7 3 10 15 1 12 9 4 13 6 8 5 11 14 \\\\r\\\\n2 1 9 5 3 13 7 15 6 4 11 12 14 10 8 \\\\r\\\\n4 9 1 6 5 10 14 8 15 12 7 13 11 3 2 \\\\r\\\\n15 12 7 4 2 8 5 10 13 14 9 3 6 11 1 \\\\r\\\\n2 4 14 7 12 15 11 10 1 9 5 6 13 3 8 \\\\r\\\\n5 7 2 4 12 11 15 6 14 1 9 8 10 13 3 \\\\r\\\\n12 6 9 8 13 14 15 3 4 7 2 10 5 11 1 \\\\r\\\\n11 10 1 14 7 2 3 8 13 15 6 5 9 4 12 \\\\r\\\\n10 8 4 7 2 3 6 13 1 11 14 5 12 15 9 \\\\r\\\\n7 4 3 2 8 9 14 1 12 15 6 11 10 13 5 \\\\r\\\\n13 10 6 11 9 4 5 14 7 2 1 8 3 12 15 \\\\r\\\\n4 7 13 2 1 11 15 12 8 5 6 3 14 9 10 \\\\r\\\\n6 11 10 12 2 9 4 3 15 5 14 7 1 8 13 \\\\r\\\\n6 11 2 12 7 15 14 4 5 9 13 3 8 1 10 \\\\r\\\\n7 11 5 13 8 4 3 2 12 6 9 14 15 10 1 \\\\r\\\\n10 3 6 1 5 13 9 15 2 8 7 4 11 14 12 \\\\r\\\\n10 6 14 12 11 7 8 4 15 13 1 9 3 5 2 \\\\r\\\\n11 14 1 8 10 13 5 6 4 3 15 12 2 9 7 \\\\r\\\\n7 6 13 15 3 14 1 12 2 11 8 4 9 10 5 \\\\r\\\\n9 8 12 14 5 2 13 6 7 10 4 1 15 3 11 \\\\r\\\\n5 15 1 4 13 14 8 11 2 10 9 3 6 7 12 \\\\r\\\\n10 13 15 12 8 7 2 5 1 3 4 9 6 14 11 \\\\r\\\\n1 9 11 8 12 3 14 10 5 2 15 7 6 4 13 \\\\r\\\\n10 4 7 11 14 5 6 8 9 2 12 3 13 15 1 \\\\r\\\\n10 4 6 11 2 14 9 12 1 13 3 8 7 5 15 \\\\r\\\\n3 9 7 5 1 15 2 11 4 13 10 8 14 6 12 \\\\r\\\\n13 8 14 15 11 12 6 7 1 4 3 9 2 10 5 \\\\r\\\\n8 9 14 3 1 6 4 2 7 12 15 5 11 10 13 \\\\r\\\\n1 11 9 7 14 5 3 2 12 10 4 6 15 13 8 \\\\r\\\\n10 2 7 3 5 13 11 4 14 8 12 6 15 9 1 \\\\r\\\\n2 5 4 12 1 10 14 7 9 15 11 8 6 3 13 \\\\r\\\\n7 11 2 6 5 8 1 14 10 13 3 12 15 9 4 \\\\r\\\\n13 6 3 2 9 8 5 1 7 14 15 10 4 11 12 \\\\r\\\\n6 5 12 14 10 15 1 3 7 9 11 13 2 8 4 \\\\r\\\\n11 9 7 12 4 10 2 13 3 6 1 15 14 5 8 \\\\r\\\\n11 9 6 13 7 8 12 14 4 2 5 1 15 3 10 \\\\r\\\\n12 4 13 6 5 10 9 3 1 2 8 11 14 15 7 \\\\r\\\\n8 2 6 9 5 7 4 14 11 12 15 3 13 1 10 \\\\r\\\\n5 2 11 3 13 12 15 9 14 4 8 7 1 6 10 \\\\r\\\\n10 1 9 12 11 7 6 15 2 4 8 14 13 3 5 \\\\r\\\\n15 10 4 1 3 5 7 9 13 8 12 14 6 11 2 \\\\r\\\\n9 4 13 1 7 10 14 15 5 2 8 12 6 3 11 \\\\r\\\\n13 11 1 2 10 12 9 3 7 14 4 15 5 6 8 \\\\r\\\\n14 2 7 10 1 8 12 11 6 9 15 5 4 13 3 \\\\r\\\\n4 14 15 3 5 7 8 12 6 1 13 10 11 2 9 \\\\r\\\\n8 4 2 14 15 10 13 11 7 9 6 1 5 12 3 \\\\r\\\\n3 14 11 10 6 1 2 5 9 12 4 15 13 8 7 \\\\r\\\\n3 5 12 4 11 9 6 14 13 1 10 15 8 2 7 \\\\r\\\\n14 10 3 5 11 1 15 13 12 8 4 9 6 7 2 \\\\r\\\\n5 12 13 14 3 11 10 7 4 9 1 15 8 6 2 \\\\r\\\\n6 11 10 15 12 4 7 5 3 14 1 13 9 2 8 \\\\r\\\\n3 14 6 10 15 5 13 9 4 12 11 8 2 1 7 \\\\r\\\\n7 9 10 3 6 2 11 5 1 15 14 4 12 8 13 \\\\r\\\\n5 15 4 2 1 11 13 9 10 14 8 6 12 3 7 \\\\r\\\\n2 4 11 14 7 12 5 13 10 6 9 3 15 1 8 \\\\r\\\\n1 8 3 12 15 11 5 6 10 13 4 7 2 14 9 \\\\r\\\\n11 12 1 13 4 15 9 3 2 5 8 14 7 10 6 \\\\r\\\\n5 15 8 11 4 10 6 12 13 2 1 7 9 3 14 \\\\r\\\\n11 13 4 7 10 1 14 3 6 15 9 2 5 8 12 \\\\r\\\\n1 9 10 8 5 11 15 13 14 7 4 12 2 3 6 \\\\r\\\\n11 2 7 9 13 10 4 8 5 14 6 12 1 3 15 \\\\r\\\\n15 12 7 11 4 6 5 8 10 9 13 3 14 1 2 \\\\r\\\\n4 7 9 15 13 12 11 5 3 1 10 6 14 8 2 \\\\r\\\\n7 6 3 11 5 9 4 15 8 14 2 12 10 1 13 \\\\r\\\\n6 8 9 7 13 12 15 11 5 3 1 2 4 10 14 \\\\r\\\\n2 7 14 4 1 5 6 15 11 3 8 12 10 13 9 \\\\r\\\\n11 4 8 6 1 3 5 12 9 10 14 15 7 13 2 \\\\r\\\\n11 4 10 7 15 9 1 5 13 6 14 3 8 2 12 \\\\r\\\\n11 2 8 10 14 1 5 15 6 3 7 13 4 9 12 \\\\r\\\\n15 6 4 9 11 5 3 10 12 2 1 13 8 14 7 \\\\r\\\\n2 3 15 8 11 9 6 4 12 14 10 1 13 7 5 \\\\r\\\\n10 7 6 15 8 13 11 2 12 9 14 1 5 4 3 \\\\r\\\\n12 6 11 10 8 3 1 15 7 5 14 9 2 13 4 \\\\r\\\\n8 15 5 11 7 2 1 4 3 10 13 6 12 14 9 \\\\r\\\\n11 5 9 6 10 3 14 13 1 7 15 12 4 8 2 \\\\r\\\\n6 11 7 10 4 15 3 14 1 13 8 2 5 12 9 \\\\r\\\\n10 9 15 2 13 12 14 6 3 1 4 7 8 11 5 \\\\r\\\\n2 15 1 7 12 11 3 5 8 9 14 4 13 10 6 \\\\r\\\\n13 1 14 5 6 9 3 11 10 8 12 2 7 15 4 \\\\r\\\\n1 14 3 10 5 8 7 2 13 4 6 12 11 15 9 \\\\r\\\\n3 7 12 2 8 15 5 13 10 9 4 14 6 11 1 \\\\r\\\\n2 5 11 15 9 13 14 3 4 10 8 6 12 1 7 \\\\r\\\\n11 15 2 3 7 10 14 9 4 5 12 6 8 13 1 \\\\r\\\\n7 14 13 10 9 4 1 6 11 8 15 2 3 12 5 \\\\r\\\\n7 4 3 6 14 11 1 2 10 12 9 5 15 13 8 \\\\r\\\\n9 3 7 8 1 15 2 13 12 6 4 11 14 5 10 \\\\r\\\\n10 9 8 13 14 12 4 5 6 11 15 1 2 7 3 \\\\r\\\\n14 8 1 12 15 5 2 9 3 7 6 11 13 4 10 \\\\r\\\\n1 5 8 4 7 9 3 10 6 11 12 14 15 13 2 \\\\r\\\\n8 1 6 15 12 13 4 11 7 10 9 3 5 14 2 \\\\r\\\\n9 11 5 1 3 2 14 4 7 6 13 12 15 10 8 \\\\r\\\\n10 14 1 12 7 11 8 2 4 15 3 6 9 13 5 \\\\r\\\\n5 11 10 3 7 2 14 9 8 1 12 15 6 13 4 \\\\r\\\\n9 3 12 2 7 6 5 1 14 11 8 13 10 4 15 \\\\r\\\\n5 4 12 1 6 14 3 15 2 7 13 11 10 8 9 \\\\r\\\\n3 4 11 10 1 14 8 5 6 13 12 7 15 2 9 \\\\r\\\\n7 11 8 10 13 3 12 4 2 14 9 15 6 1 5 \\\\r\\\\n2 4 1 10 7 3 6 15 11 14 12 9 8 5 13 \\\\r\\\\n1 14 10 2 5 6 13 8 15 12 7 3 4 9 11 \\\\r\\\\n15 6 5 14 10 4 7 1 13 9 2 3 8 12 11 \\\\r\\\\n2 3 9 10 7 11 15 6 13 5 4 8 12 1 14 \\\\r\\\\n11 12 5 14 8 1 2 4 10 3 7 15 13 9 6 \\\\r\\\\n10 9 11 8 12 4 13 15 3 1 2 6 7 5 14 \\\\r\\\\n5 11 14 6 2 1 12 4 9 13 7 8 15 3 10 \\\\r\\\\n7 2 1 15 13 6 9 11 10 3 14 5 4 8 12 \\\\r\\\\n9 8 12 2 1 5 4 13 3 10 7 6 11 15 14 \\\\r\\\\n14 12 15 1 7 11 8 2 4 6 13 9 5 10 3 \\\\r\\\\n14 3 7 6 1 5 15 13 12 4 11 10 2 9 8 \\\\r\\\\n9 13 11 10 7 15 2 1 12 6 4 3 5 14 8 \\\\r\\\\n10 4 5 12 1 8 3 2 7 13 6 11 15 9 14 \\\\r\\\\n13 2 8 1 14 3 11 9 4 5 15 12 6 7 10 \\\\r\\\\n3 11 1 5 6 14 10 4 15 12 7 2 9 8 13 \\\\r\\\\n5 8 2 11 1 13 4 3 9 12 7 14 10 15 6 \\\\r\\\\n14 1 12 10 2 9 6 4 8 7 3 13 5 15 11 \\\\r\\\\n11 2 14 5 15 9 10 3 8 1 4 13 7 6 12 \\\\r\\\\n1 6 5 3 15 13 2 14 10 4 11 12 9 8 7 \\\\r\\\\n14 3 10 6 9 1 4 15 5 12 7 8 2 11 13 \\\\r\\\\n14 3 5 15 2 1 12 7 9 6 11 10 13 8 4 \\\\r\\\\n1 10 9 13 15 8 5 11 2 6 7 3 4 14 12 \\\\r\\\\n3 12 15 10 8 14 5 1 11 7 9 4 13 2 6 \\\\r\\\\n15 5 6 14 4 10 1 12 3 11 8 9 13 2 7 \\\\r\\\\n13 2 8 9 11 14 10 12 1 5 7 6 4 15 3 \\\\r\\\\n8 13 1 5 7 11 4 14 12 9 10 3 15 6 2 \\\\r\\\\n9 14 12 8 1 6 13 10 15 7 11 3 2 5 4 \\\\r\\\\n3 11 2 7 12 9 1 15 10 13 6 8 14 4 5 \\\\r\\\\n7 11 10 14 3 4 2 5 15 9 6 12 1 8 13 \\\\r\\\\n14 1 2 3 5 4 7 8 10 9 6 13 11 15 12 \\\\r\\\\n9 3 2 7 13 1 4 11 6 8 5 14 10 12 15 \\\\r\\\\n14 13 12 8 9 3 5 4 2 6 10 7 1 11 15 \\\\r\\\\n10 8 7 6 5 12 1 11 4 14 2 13 9 3 15 \\\\r\\\\n6 10 12 2 15 14 7 13 4 1 9 8 11 5 3 \\\\r\\\\n4 6 7 1 8 12 2 9 10 3 11 13 5 15 14 \\\\r\\\\n2 1 12 15 13 10 4 11 14 3 7 6 8 5 9 \\\\r\\\\n9 12 14 15 11 2 8 13 6 1 7 5 10 4 3 \\\\r\\\\n14 6 15 2 4 5 1 3 10 9 12 11 13 7 8 \\\\r\\\\n8 10 14 15 3 6 2 7 11 12 4 13 1 9 5 \\\\r\\\\n6 12 5 14 15 9 10 1 11 4 3 13 8 2 7 \\\\r\\\\n11 10 15 13 6 9 2 4 3 5 7 12 1 14 8 \\\\r\\\\n6 4 2 5 8 7 11 9 3 13 15 10 12 1 14 \\\\r\\\\n12 1 3 7 14 9 10 6 15 11 4 8 13 2 5 \\\\r\\\\n14 10 12 15 7 6 9 5 1 8 11 3 13 2 4 \\\\r\\\\n11 3 12 1 8 6 10 15 9 5 13 4 2 7 14 \\\\r\\\\n10 12 1 6 4 13 3 15 5 9 7 11 2 14 8 \\\\r\\\\n3 13 2 7 6 10 11 9 1 14 15 5 12 8 4 \\\\r\\\\n15 9 13 11 1 14 2 5 12 7 8 3 10 6 4 \\\\r\\\\n8 3 5 12 11 7 13 6 1 14 4 15 2 9 10 \\\\r\\\\n9 15 13 14 5 8 6 12 2 4 3 1 7 11 10 \\\\r\\\\n4 13 2 7 5 6 3 10 14 15 8 11 12 1 9 \\\\r\\\\n9 1 7 12 2 8 5 3 14 4 11 15 13 10 6 \\\\r\\\\n6 10 1 13 15 3 2 14 12 11 8 5 4 9 7 \\\\r\\\\n10 1 11 8 5 14 6 3 15 4 9 2 12 7 13 \\\\r\\\\n8 4 13 2 1 7 9 15 6 14 5 10 11 3 12 \\\\r\\\\n4 5 7 9 8 1 6 3 15 12 10 13 11 14 2 \\\\r\\\\n15 3 8 2 1 6 5 11 10 13 12 4 9 14 7 \\\\r\\\\n15 9 6 1 7 13 12 5 14 11 10 2 3 4 8 \\\\r\\\\n11 12 13 9 5 4 10 14 1 2 6 8 15 3 7 \\\\r\\\\n10 9 13 11 4 14 1 15 2 6 7 5 3 12 8 \\\\r\\\\n11 10 3 6 14 15 1 9 8 12 13 2 5 7 4 \\\\r\\\\n2 3 7 11 1 4 14 12 8 15 6 5 9 10 13 \\\\r\\\\n13 6 14 10 8 9 4 3 11 5 2 1 7 15 12 \\\\r\\\\n4 3 9 14 1 6 15 10 13 2 12 8 11 5 7 \\\\r\\\\n4 6 11 10 15 13 3 2 12 5 14 8 1 7 9 \\\\r\\\\n9 5 3 7 15 14 12 4 6 2 1 13 11 10 8 \\\\r\\\\n11 2 10 6 15 5 9 13 4 1 8 7 3 12 14 \\\\r\\\\n14 13 5 3 4 2 9 15 6 11 1 10 7 12 8 \\\\r\\\\n7 10 8 9 14 11 15 1 2 3 13 5 6 12 4 \\\\r\\\\n7 8 11 6 4 3 2 10 9 14 5 13 15 12 1 \\\\r\\\\n9 7 12 1 8 10 14 13 4 5 3 2 6 11 15 \\\\r\\\\n11 7 13 1 4 12 8 3 14 2 15 6 10 9 5 \\\\r\\\\n4 7 8 9 10 11 6 1 12 2 15 13 14 5 3 \\\\r\\\\n8 15 12 13 4 3 2 14 10 7 6 1 11 5 9 \\\\r\\\\n12 9 10 2 3 4 1 8 11 5 15 7 13 6 14 \\\\r\\\\n15 7 5 12 11 1 13 2 8 4 9 10 6 14 3 \\\\r\\\\n5 12 10 3 8 2 11 4 15 14 6 13 7 1 9 \\\\r\\\\n8 12 7 13 3 1 10 6 2 14 11 5 15 9 4 \\\\r\\\\n6 5 1 3 14 7 13 2 12 8 4 11 15 10 9 \\\\r\\\\n4 9 5 13 7 15 1 12 8 2 3 10 11 6 14 \\\\r\\\\n7 11 2 9 12 15 1 4 10 14 6 13 3 8 5 \\\\r\\\\n4 2 8 11 6 10 7 12 15 14 9 13 3 5 1 \\\\r\\\\n7 10 9 5 14 1 2 11 6 8 12 4 3 13 15 \\\\r\\\\n4 12 14 8 7 2 11 10 6 15 9 1 3 13 5 \\\\r\\\\n15 9 8 13 10 14 5 12 3 7 2 11 6 4 1 \\\\r\\\\n4 15 12 3 13 6 8 9 14 5 2 1 11 7 10 \\\\r\\\\n12 5 1 2 3 4 6 13 10 15 8 14 7 9 11 \\\\r\\\\n5 11 9 4 10 6 12 13 15 1 3 7 14 2 8 \\\\r\\\\n5 11 8 13 1 10 14 9 3 15 2 4 6 7 12 \\\\r\\\\n10 1 12 11 9 7 6 3 13 14 15 5 8 4 2 \\\\r\\\\n6 1 10 14 4 3 15 9 5 8 2 13 11 12 7 \\\\r\\\\n2 15 7 4 5 10 6 8 9 1 11 3 13 12 14 \\\\r\\\\n14 10 13 11 15 1 2 4 6 8 12 9 3 7 5 \\\\r\\\\n3 10 11 15 13 14 4 1 6 2 12 7 8 5 9 \\\\r\\\\n5 2 3 11 14 1 8 9 4 6 13 15 7 10 12 \\\\r\\\\n9 15 8 14 13 7 5 10 12 2 1 4 6 3 11 \\\\r\\\\n14 13 15 3 2 7 8 4 11 1 12 9 6 10 5 \\\\r\\\\n5 15 10 3 11 13 1 7 2 9 6 14 4 12 8 \\\\r\\\\n5 15 7 11 13 6 3 4 10 9 2 12 8 14 1 \\\\r\\\\n7 9 15 11 10 6 5 13 2 1 14 8 4 12 3 \\\\r\\\\n10 1 3 14 12 9 13 7 11 8 2 6 15 4 5 \\\\r\\\\n13 6 14 1 8 10 9 11 4 2 12 5 3 15 7 \\\\r\\\\n15 4 11 2 10 13 7 12 9 8 5 6 14 3 1 \\\\r\\\\n2 5 13 15 10 6 12 11 3 8 9 4 7 1 14 \\\\r\\\\n1 4 14 6 2 10 15 3 9 11 5 12 8 7 13 \\\\r\\\\n6 15 5 12 14 8 7 10 4 3 1 2 11 9 13 \\\\r\\\\n2 5 1 7 3 15 10 13 8 6 11 9 12 14 4 \\\\r\\\\n10 13 8 2 4 14 3 1 11 6 9 12 5 15 7 \\\\r\\\\n4 5 1 3 14 11 2 8 13 6 9 15 12 10 7 \\\\r\\\\n7 10 6 9 2 12 14 5 15 4 8 3 13 1 11 \\\\r\\\\n15 2 11 4 13 8 10 1 14 9 7 6 5 12 3 \\\\r\\\\n6 13 9 4 14 5 15 10 11 8 12 7 2 3 1 \\\\r\\\\n5 8 1 13 3 11 2 9 6 7 10 14 15 12 4 \\\\r\\\\n8 15 6 3 14 2 7 9 13 10 1 5 11 4 12 \\\\r\\\\n9 1 3 7 5 10 11 8 12 15 14 2 6 13 4 \\\\r\\\\n11 14 6 8 13 3 2 15 4 7 10 12 1 9 5 \\\\r\\\\n2 1 10 12 9 13 14 15 6 8 3 7 4 11 5 \\\\r\\\\n7 3 6 5 1 2 10 14 15 11 9 13 8 4 12 \\\\r\\\\n4 2 7 5 11 8 15 14 6 13 1 9 10 12 3 \\\\r\\\\n1 5 2 10 13 6 11 15 9 7 12 8 14 3 4 \\\\r\\\\n13 2 10 8 9 6 11 14 4 7 3 1 5 12 15 \\\\r\\\\n1 3 7 13 9 11 2 15 8 10 6 14 4 12 5 \\\\r\\\\n11 5 15 12 6 2 7 1 13 4 14 9 8 10 3 \\\\r\\\\n12 3 11 7 9 4 2 13 8 15 5 14 10 1 6 \\\\r\\\\n1 15 7 9 8 10 12 11 4 3 6 13 2 5 14 \\\\r\\\\n12 11 5 14 1 2 6 8 10 7 3 15 9 4 13 \\\\r\\\\n13 1 4 6 3 12 10 14 11 7 5 2 15 9 8 \\\\r\\\\n12 5 14 10 3 2 8 13 15 1 9 7 4 6 11 \\\\r\\\\n12 5 9 1 8 4 13 15 2 11 7 6 14 10 3 \\\\r\\\\n11 7 8 5 12 3 2 15 10 4 9 1 6 14 13 \\\\r\\\\n1 3 7 4 8 2 11 10 6 9 14 15 13 12 5 \\\\r\\\\n8 13 5 7 14 10 1 2 15 6 4 3 12 9 11 \\\\r\\\\n2 5 4 3 7 13 12 8 11 10 15 1 9 6 14 \\\\r\\\\n1 2 6 10 9 3 13 12 5 15 11 7 14 8 4 \\\\r\\\\n2 8 3 12 7 13 14 10 15 5 6 11 1 9 4 \\\\r\\\\n6 10 14 8 12 9 5 15 2 1 11 13 7 3 4 \\\\r\\\\n1 13 6 3 11 2 10 14 4 9 15 8 12 5 7 \\\\r\\\\n11 8 10 15 14 13 6 3 1 4 2 5 12 9 7 \\\\r\\\\n8 10 3 9 6 7 11 13 15 4 12 2 1 5 14 \\\\r\\\\n4 3 1 5 11 12 8 9 2 14 15 10 7 13 6 \\\\r\\\\n8 2 13 10 15 11 4 14 3 7 12 9 6 1 5 \\\\r\\\\n4 1 7 15 5 12 14 10 8 13 2 3 9 6 11 \\\\r\\\\n7 4 6 1 3 13 9 14 2 15 8 12 5 11 10 \\\\r\\\\n7 3 11 12 10 6 15 13 8 14 2 9 1 5 4 \\\\r\\\\n2 3 1 4 10 15 6 5 12 8 7 14 13 9 11 \\\\r\\\\n14 10 9 8 7 2 15 12 1 3 4 13 6 5 11 \\\\r\\\\n1 4 13 8 5 7 2 15 3 14 11 10 9 12 6 \\\\r\\\\n7 14 12 6 5 15 4 1 3 2 11 9 13 10 8 \\\\r\\\\n6 7 11 4 5 10 3 13 9 1 2 14 15 12 8 \\\\r\\\\n2 12 7 14 1 9 15 6 10 4 8 13 3 5 11 \\\\r\\\\n4 15 13 8 10 12 9 1 7 11 5 6 14 3 2 \\\\r\\\\n12 9 5 10 14 8 6 13 11 1 3 7 4 2 15 \\\\r\\\\n12 5 7 9 6 1 15 8 14 2 3 4 11 13 10 \\\\r\\\\n6 12 7 8 5 14 4 10 15 1 3 11 13 2 9 \\\\r\\\\n10 6 1 3 4 11 8 12 15 7 14 9 2 5 13 \\\\r\\\\n8 11 2 15 5 1 6 3 13 4 12 10 9 7 14 \\\\r\\\\n13 3 11 1 15 8 4 10 5 6 7 9 2 14 12 \\\\r\\\\n1 8 3 13 10 15 12 5 14 7 6 4 11 9 2 \\\\r\\\\n5 3 9 11 14 1 15 10 7 8 6 13 4 2 12 \\\\r\\\\n11 7 12 13 10 1 14 8 15 2 5 9 3 6 4 \\\\r\\\\n10 12 9 7 4 6 8 15 5 14 11 13 3 1 2 \\\\r\\\\n13 4 2 3 12 1 5 8 7 10 9 14 15 11 6 \\\\r\\\\n8 1 15 2 10 5 4 3 11 14 6 7 13 9 12 \\\\r\\\\n10 11 12 1 8 4 2 6 15 7 5 3 14 13 9 \\\\r\\\\n11 12 14 7 6 5 1 15 3 2 10 4 9 13 8 \\\\r\\\\n13 15 11 6 2 4 7 10 8 3 5 9 1 12 14 \\\\r\\\\n10 4 1 5 3 6 9 13 2 12 14 8 15 11 7 \\\\r\\\\n9 4 14 8 6 1 13 10 2 3 12 11 15 5 7 \\\\r\\\\n10 12 5 6 11 1 8 2 3 7 14 4 13 15 9 \\\\r\\\\n10 2 7 1 12 6 3 5 9 8 4 13 15 11 14 \\\\r\\\\n8 15 3 12 6 7 4 5 2 13 14 9 1 10 11 \\\\r\\\\n13 10 11 12 14 15 6 1 5 8 4 9 7 3 2 \\\\r\\\\n5 7 1 10 12 2 4 9 13 3 8 15 14 6 11 \\\\r\\\\n1 13 8 10 6 5 4 9 15 2 12 3 7 14 11 \\\\r\\\\n15 11 13 10 5 4 3 12 6 2 1 8 7 9 14 \\\\r\\\\n9 7 6 5 4 11 14 15 10 1 3 8 13 2 12 \\\\r\\\\n9 6 7 1 14 11 13 2 15 10 8 4 5 12 3 \\\\r\\\\n1 6 11 5 14 9 2 4 10 13 12 15 3 8 7 \\\\r\\\\n15 4 5 8 6 1 11 3 7 13 9 10 2 14 12 \\\\r\\\\n8 14 1 6 11 2 3 7 15 13 5 9 4 10 12 \\\\r\\\\n11 10 15 7 14 9 2 5 13 3 8 6 12 1 4 \\\\r\\\\n3 10 14 15 9 8 2 6 11 7 4 13 1 5 12 \\\\r\\\\n6 4 1 3 10 2 7 13 8 15 12 9 14 11 5 \\\\r\\\\n10 5 4 13 3 14 9 2 15 8 6 11 12 7 1 \\\\r\\\\n14 2 6 11 8 1 7 4 3 10 5 13 9 15 12 \\\\r\\\\n12 14 3 6 11 8 15 10 1 5 2 4 13 9 7 \\\\r\\\\n8 5 13 2 12 9 15 10 4 3 1 7 14 6 11 \\\\r\\\\n14 4 11 6 15 3 1 8 2 10 7 12 5 13 9 \\\\r\\\\n2 11 8 6 1 7 13 4 9 12 3 10 15 14 5 \\\\r\\\\n10 8 15 7 13 3 14 1 5 9 11 2 12 4 6 \\\\r\\\\n4 6 13 2 15 11 9 5 3 8 1 7 12 10 14 \\\\r\\\\n3 9 8 7 15 1 11 6 5 12 13 14 2 4 10 \\\\r\\\\n14 11 8 6 4 15 10 9 2 1 12 3 13 5 7 \\\\r\\\\n15 1 7 5 8 4 9 13 14 6 10 12 2 3 11 \\\\r\\\\n8 14 12 9 10 5 15 11 3 1 4 7 13 2 6 \\\\r\\\\n7 12 11 15 10 5 9 13 4 1 3 14 2 6 8 \\\\r\\\\n5 8 3 1 9 4 11 14 15 6 7 12 13 2 10 \\\\r\\\\n8 9 3 12 11 4 13 2 1 6 7 10 14 5 15 \\\\r\\\\n4 8 13 11 3 6 5 9 15 10 1 7 12 2 14 \\\\r\\\\n7 9 15 10 2 11 8 13 12 5 3 4 6 14 1 \\\\r\\\\n1 12 10 3 15 5 4 2 8 11 7 14 9 13 6 \\\\r\\\\n15 9 1 2 7 14 13 3 4 5 11 10 12 6 8 \\\\r\\\\n7 15 13 4 10 5 11 2 3 1 12 8 6 9 14 \\\\r\\\\n4 8 12 1 10 6 9 3 5 11 7 13 14 15 2 \\\\r\\\\n11 14 7 6 10 13 3 8 2 12 4 1 15 9 5 \\\\r\\\\n9 10 6 11 2 4 14 7 8 13 5 12 1 3 15 \\\\r\\\\n2 12 6 8 10 13 5 7 1 4 9 11 15 3 14 \\\\r\\\\n14 6 15 11 13 3 9 5 4 10 2 8 1 7 12 \\\\r\\\\n14 2 7 9 13 4 10 1 8 11 12 15 5 6 3 \\\\r\\\\n1 12 10 4 7 3 5 6 13 14 8 9 2 11 15 \\\\r\\\\n9 12 14 8 11 10 5 15 13 6 2 4 3 1 7 \\\\r\\\\n4 8 2 9 1 14 7 13 5 10 6 12 11 3 15 \\\\r\\\\n11 15 10 12 9 2 1 7 6 14 8 4 3 13 5 \\\\r\\\\n15 12 8 9 14 5 3 10 7 4 1 6 11 13 2 \\\\r\\\\n2 12 1 15 6 5 14 13 11 9 3 4 8 7 10 \\\\r\\\\n3 13 10 4 9 7 8 12 14 15 11 5 6 2 1 \\\\r\\\\n13 7 11 15 4 8 6 1 10 9 12 2 5 3 14 \\\\r\\\\n10 4 6 13 9 11 7 3 12 8 15 14 2 1 5 \\\\r\\\\n8 2 11 1 12 13 5 7 6 4 14 10 15 9 3 \\\\r\\\\n4 13 12 2 14 3 11 10 9 7 5 1 15 8 6 \\\\r\\\\n2 6 7 4 11 12 15 8 1 10 14 13 5 3 9 \\\\r\\\\n3 1 4 5 13 2 7 8 11 6 10 14 9 15 12 \\\\r\\\\n3 15 2 7 6 14 13 1 5 8 11 10 12 4 9 \\\\r\\\\n12 10 1 13 8 4 11 3 2 15 7 6 5 14 9 \\\\r\\\\n6 5 11 1 12 9 10 14 4 2 8 7 3 13 15 \\\\r\\\\n10 6 2 11 8 9 5 12 15 13 4 7 3 1 14 \\\\r\\\\n5 13 3 15 6 7 11 2 4 12 1 14 10 9 8 \\\\r\\\\n8 2 3 4 6 14 15 10 13 7 1 9 11 5 12 \\\\r\\\\n8 4 1 2 11 13 12 3 5 15 7 6 10 9 14 \\\\r\\\\n12 2 15 4 14 6 13 3 11 1 7 10 9 5 8 \\\\r\\\\n12 2 8 14 15 4 6 5 1 10 7 3 13 11 9 \\\\r\\\\n8 4 10 14 3 6 15 2 12 1 7 9 5 13 11 \\\\r\\\\n12 15 11 10 3 6 2 9 7 13 5 14 1 8 4 \\\\r\\\\n7 9 2 4 6 3 1 10 8 5 11 14 15 12 13 \\\\r\\\\n5 14 8 12 4 2 11 13 6 1 15 3 10 7 9 \\\\r\\\\n5 6 7 15 14 1 3 9 2 10 8 4 12 11 13 \\\\r\\\\n4 8 9 6 13 11 10 15 12 7 3 5 2 1 14 \\\\r\\\\n8 5 1 13 11 10 14 3 7 4 6 9 2 15 12 \\\\r\\\\n6 14 12 15 7 2 11 8 3 1 4 9 13 5 10 \\\\r\\\\n12 4 11 14 3 9 2 7 5 15 10 8 13 6 1 \\\\r\\\\n11 6 3 4 13 5 15 14 2 12 10 9 7 1 8 \\\\r\\\\n8 7 5 11 14 13 1 3 4 9 12 10 2 15 6 \\\\r\\\\n12 2 15 4 13 6 7 11 3 1 14 8 5 10 9 \\\\r\\\\n13 11 10 2 12 14 6 8 1 7 9 3 15 4 5 \\\\r\\\\n1 3 12 8 14 15 13 9 10 11 4 7 5 6 2 \\\\r\\\\n4 5 9 11 8 15 6 12 10 14 2 13 1 7 3 \\\\r\\\\n13 12 3 7 8 11 9 15 5 2 14 4 10 1 6 \\\\r\\\\n7 11 3 8 2 10 6 4 15 13 12 1 5 14 9 \\\\r\\\\n15 3 12 9 1 8 5 2 6 10 13 14 11 4 7 \\\\r\\\\n13 8 12 14 1 4 5 9 11 10 6 2 15 7 3 \\\\r\\\\n11 14 5 3 4 1 10 8 12 15 6 7 13 9 2 \\\\r\\\\n13 8 12 7 5 4 11 14 6 3 1 2 9 10 15 \\\\r\\\\n6 1 15 11 10 2 9 13 8 14 4 5 12 3 7 \\\\r\\\\n1 5 9 14 10 8 2 3 6 7 15 13 11 12 4 \\\\r\\\\n3 15 1 7 8 9 12 2 13 10 5 6 4 14 11 \\\\r\\\\n8 10 2 13 14 9 3 1 6 15 11 12 4 5 7 \\\\r\\\\n13 7 8 2 14 10 5 6 12 11 15 3 1 4 9 \\\\r\\\\n1 2 13 14 11 12 7 8 10 9 6 15 3 4 5 \\\\r\\\\n15 5 14 7 1 6 10 4 9 8 3 11 13 12 2 \\\\r\\\\n4 7 2 5 9 3 6 13 8 15 1 14 12 10 11 \\\\r\\\\n10 12 4 7 9 3 13 1 5 2 11 15 14 8 6 \\\\r\\\\n1 3 10 11 13 6 9 2 5 14 15 4 7 8 12 \\\\r\\\\n10 8 13 14 4 5 1 12 7 15 11 2 6 9 3 \\\\r\\\\n7 6 15 4 5 10 2 1 11 12 14 3 8 9 13 \\\\r\\\\n15 11 6 9 7 2 12 1 10 8 5 4 3 13 14 \\\\r\\\\n8 11 13 15 6 1 9 4 10 5 12 2 14 3 7 \\\\r\\\\n11 4 13 5 15 2 12 14 1 10 3 7 6 8 9 \\\\r\\\\n5 13 14 10 11 3 15 12 2 8 1 9 7 4 6 \\\\r\\\\n5 15 6 8 13 4 2 9 7 12 3 11 10 1 14 \\\\r\\\\n4 6 1 12 5 7 9 2 10 15 8 13 3 14 11 \\\\r\\\\n12 3 10 2 14 15 7 4 9 11 13 6 5 1 8 \\\\r\\\\n10 3 14 11 1 9 2 4 13 8 6 5 12 7 15 \\\\r\\\\n6 3 10 1 13 7 4 8 12 14 2 5 11 15 9 \\\\r\\\\n1 9 12 2 7 6 14 4 8 15 5 10 3 11 13 \\\\r\\\\n9 7 11 3 10 6 13 14 2 4 1 15 12 8 5 \\\\r\\\\n9 7 8 4 14 12 6 3 5 1 10 11 15 13 2 \\\\r\\\\n4 11 1 6 9 3 8 10 13 14 2 15 5 7 12 \\\\r\\\\n11 1 14 10 12 6 5 15 13 3 7 8 2 9 4 \\\\r\\\\n6 13 7 10 4 5 14 3 9 1 8 12 2 11 15 \\\\r\\\\n12 2 1 3 6 5 10 15 4 7 11 9 8 14 13 \\\\r\\\\n11 3 7 5 10 4 1 14 9 15 6 2 13 12 8 \\\\r\\\\n10 13 14 1 3 11 8 7 6 9 4 2 15 12 5 \\\\r\\\\n11 12 4 2 3 8 9 13 6 10 14 7 15 5 1 \\\\r\\\\n2 5 13 6 1 8 4 11 9 14 10 7 12 15 3 \\\\r\\\\n12 2 10 4 1 13 7 14 11 5 9 15 3 6 8 \\\\r\\\\n15 12 3 7 6 1 14 9 5 10 13 8 11 4 2 \\\\r\\\\n12 2 7 8 1 10 15 13 6 3 5 9 4 14 11 \\\\r\\\\n5 11 14 13 1 9 12 4 6 2 8 7 15 10 3 \\\\r\\\\n9 15 1 4 5 7 6 10 13 14 8 3 2 12 11 \\\\r\\\\n6 8 13 3 2 5 4 10 15 1 7 14 12 11 9 \\\\r\\\\n4 14 3 1 11 5 10 12 7 6 8 15 9 2 13 \\\\r\\\\n4 1 15 2 10 9 12 7 8 5 3 14 6 11 13 \\\\r\\\\n11 10 12 1 5 9 4 6 14 2 13 8 7 15 3 \\\\r\\\\n2 14 9 8 6 7 15 3 12 5 1 4 11 10 13 \\\\r\\\\n4 15 7 11 10 3 5 6 8 14 13 1 2 9 12 \\\\r\\\\n5 3 4 12 6 14 8 9 13 15 11 7 10 1 2 \\\\r\\\\n12 3 13 4 14 10 2 8 7 15 5 1 11 9 6 \\\\r\\\\n14 10 15 5 3 1 8 7 12 13 9 2 4 11 6 \\\\r\\\\n6 2 15 14 12 1 9 11 8 3 13 7 4 5 10 \\\\r\\\\n11 6 5 12 9 1 14 4 2 15 7 8 10 13 3 \\\\r\\\\n13 4 11 6 7 10 8 12 1 2 15 14 3 5 9 \\\\r\\\\n1 7 10 9 5 4 15 2 14 11 8 6 12 13 3 \\\\r\\\\n4 15 8 3 13 2 6 10 5 9 7 12 14 11 1 \\\\r\\\\n7 9 5 2 15 14 1 3 8 12 10 13 4 6 11 \\\\r\\\\n6 10 15 14 3 1 11 4 7 8 12 13 2 5 9 \\\\r\\\\n12 3 1 9 13 6 8 5 4 11 7 14 10 15 2 \\\\r\\\\n11 1 4 6 9 15 10 8 14 3 2 13 5 7 12 \\\\r\\\\n13 3 4 7 6 15 1 2 14 8 5 10 11 12 9 \\\\r\\\\n11 3 9 10 12 1 15 13 6 8 5 2 7 4 14 \\\\r\\\\n7 6 3 13 8 11 1 14 15 10 12 9 2 5 4 \\\\r\\\\n10 14 15 8 4 7 11 9 5 13 2 1 12 3 6 \\\\r\\\\n11 4 2 1 6 10 3 12 7 15 9 5 8 13 14 \\\\r\\\\n10 1 13 2 5 8 14 15 6 4 9 3 7 12 11 \\\\r\\\\n6 8 13 11 14 1 12 7 2 10 3 5 4 9 15 \\\\r\\\\n4 2 5 6 7 9 3 8 11 12 1 13 14 10 15 \\\\r\\\\n13 9 8 15 14 5 3 7 11 6 10 1 2 4 12 \\\\r\\\\n2 12 7 14 5 9 8 4 10 1 11 6 15 3 13 \\\\r\\\\n7 14 5 11 4 6 9 2 15 12 1 10 13 3 8 \\\\r\\\\n2 14 5 7 1 8 4 10 15 13 6 12 3 9 11 \\\\r\\\\n3 9 8 1 12 7 5 6 4 13 10 11 14 15 2 \\\\r\\\\n10 6 11 3 5 15 9 2 4 7 14 8 1 12 13 \\\\r\\\\n2 12 11 14 15 13 6 3 9 10 1 8 4 7 5 \\\\r\\\\n5 8 15 3 7 2 4 13 12 9 1 11 6 10 14 \\\\r\\\\n10 1 11 15 14 12 7 8 5 6 9 13 2 4 3 \\\\r\\\\n3 10 12 14 15 9 5 7 2 1 6 11 13 4 8 \\\\r\\\\n2 9 1 12 7 15 4 5 14 6 8 13 3 11 10 \\\\r\\\\n14 15 3 5 10 4 13 7 6 11 2 12 8 9 1 \\\\r\\\\n7 12 9 1 6 3 15 10 8 5 4 11 14 13 2 \\\\r\\\\n10 1 6 11 3 15 12 4 2 8 13 14 5 7 9 \\\\r\\\\n2 4 11 12 14 5 15 7 1 3 9 8 13 10 6 \\\\r\\\\n9 7 11 8 15 6 12 14 5 3 1 10 2 4 13 \\\\r\\\\n14 8 10 3 12 15 11 4 7 1 9 5 2 13 6 \\\\r\\\\n7 9 1 15 10 11 2 13 14 5 4 6 8 12 3 \\\\r\\\\n8 4 9 15 1 7 5 11 2 10 12 13 3 14 6 \\\\r\\\\n13 2 10 7 11 6 5 15 12 4 9 8 1 14 3 \\\\r\\\\n1 8 2 4 14 5 6 7 10 9 12 15 3 11 13 \\\\r\\\\n4 10 14 3 5 8 9 13 6 2 12 1 7 11 15 \\\\r\\\\n13 10 14 5 3 8 1 15 2 4 9 12 11 6 7 \\\\r\\\\n14 15 9 12 5 13 3 6 8 7 10 11 2 4 1 \\\\r\\\\n6 13 8 9 12 7 10 3 4 2 15 1 5 11 14 \\\\r\\\\n9 15 1 4 5 13 10 8 7 12 3 6 14 11 2 \\\\r\\\\n6 8 2 12 7 13 10 3 9 4 15 5 1 11 14 \\\\r\\\\n9 4 8 6 10 7 5 14 2 3 1 12 15 11 13 \\\\r\\\\n3 13 4 1 6 5 8 2 12 14 7 11 15 9 10 \\\\r\\\\n11 10 9 14 3 6 2 5 15 4 1 7 13 8 12 \\\\r\\\\n7 4 14 10 11 8 13 1 2 6 5 12 9 15 3 \\\\r\\\\n9 15 10 11 4 6 14 8 7 3 5 1 2 13 12 \\\\r\\\\n7 12 15 5 8 3 2 9 6 4 10 14 1 11 13 \\\\r\\\\n8 11 10 13 15 4 9 7 2 12 3 14 1 5 6 \\\\r\\\\n12 4 11 14 1 2 9 8 7 5 6 13 10 3 15 \\\\r\\\\n13 8 15 4 12 5 6 3 9 14 7 2 10 1 11 \\\\r\\\\n2 12 7 10 1 3 9 6 4 5 14 15 11 13 8 \\\\r\\\\n8 14 4 6 10 5 3 1 15 12 9 13 7 11 2 \\\\r\\\\n9 1 2 7 15 4 12 6 3 8 13 10 11 5 14 \\\\r\\\\n9 3 6 8 5 14 13 10 4 12 15 7 11 2 1 \\\\r\\\\n2 7 11 3 8 14 6 12 15 13 5 10 4 1 9 \\\\r\\\\n13 11 6 14 7 4 15 3 1 5 10 9 2 8 12 \\\\r\\\\n5 12 2 14 8 4 9 1 13 3 7 11 15 10 6 \\\\r\\\\n7 2 11 5 6 1 10 15 8 14 4 9 13 12 3 \\\\r\\\\n6 3 2 15 10 14 7 1 8 4 9 13 11 5 12 \\\\r\\\\n5 7 14 10 12 9 13 2 11 1 6 15 8 3 4 \\\\r\\\\n8 10 9 2 15 4 3 5 11 7 14 6 1 13 12 \\\\r\\\\n9 13 7 10 8 15 3 1 12 5 6 14 4 11 2 \\\\r\\\\n1 2 5 4 10 7 6 12 8 13 9 15 11 3 14 \\\\r\\\\n11 13 4 8 1 6 9 7 3 12 14 10 15 2 5 \\\\r\\\\n10 3 9 14 2 15 8 5 7 12 6 1 4 13 11 \\\\r\\\\n12 11 2 6 5 13 14 4 10 3 8 1 7 9 15 \\\\r\\\\n8 10 7 12 15 1 11 9 6 3 14 4 2 13 5 \\\\r\\\\n6 14 2 12 4 8 9 1 11 13 7 10 15 5 3 \\\\r\\\\n8 12 9 11 3 6 14 13 10 5 7 2 1 4 15 \\\\r\\\\n8 10 9 2 5 1 15 3 6 14 7 4 12 11 13 \\\\r\\\\n2 14 3 9 4 1 12 15 7 8 10 13 11 5 6 \\\\r\\\\n3 9 2 1 12 13 6 5 10 14 15 11 4 7 8 \\\\r\\\\n3 9 1 12 5 2 15 13 8 7 6 11 4 14 10 \\\\r\\\\n11 15 1 6 8 12 13 14 7 4 3 9 10 2 5 \\\\r\\\\n11 15 3 4 6 1 7 10 13 12 8 9 2 5 14 \\\\r\\\\n7 2 6 15 4 3 14 13 10 5 12 9 11 1 8 \\\\r\\\\n7 3 12 15 2 4 11 14 6 8 1 13 10 5 9 \\\\r\\\\n11 5 2 14 9 1 8 4 7 10 13 12 6 3 15 \\\\r\\\\n3 11 10 13 8 5 6 2 1 12 15 7 9 14 4 \\\\r\\\\n10 5 6 14 4 13 3 8 9 2 1 12 7 11 15 \\\\r\\\\n14 13 8 2 9 3 7 11 6 10 12 5 15 1 4 \\\\r\\\\n9 3 2 12 14 1 15 8 4 6 13 7 11 5 10 \\\\r\\\\n10 3 15 2 6 8 9 1 11 12 13 14 7 5 4 \\\\r\\\\n10 8 11 6 7 3 9 5 1 2 14 4 15 13 12 \\\\r\\\\n5 1 4 2 10 11 13 8 15 3 12 9 14 6 7 \\\\r\\\\n13 10 6 14 15 8 4 5 12 1 11 7 3 9 2 \\\\r\\\\n6 11 5 15 9 3 10 1 2 7 8 14 13 12 4 \\\\r\\\\n10 14 2 7 15 6 1 11 4 13 8 12 5 3 9 \\\\r\\\\n4 5 12 7 14 9 15 8 13 3 6 10 1 11 2 \\\\r\\\\n1 5 4 2 14 7 13 15 8 12 6 10 3 9 11 \\\\r\\\\n15 9 3 10 14 6 13 4 8 11 7 12 5 1 2 \\\\r\\\\n14 15 5 4 12 9 6 1 13 10 7 11 2 8 3 \\\\r\\\\n12 6 7 9 3 1 13 5 2 4 15 10 11 14 8 \\\\r\\\\n13 14 1 5 12 11 6 8 15 2 9 10 4 3 7 \\\\r\\\\n3 12 6 9 4 15 14 7 2 1 11 13 8 10 5 \\\\r\\\\n8 10 5 15 9 6 11 7 14 12 3 13 4 2 1 \\\\r\\\\n1 2 10 11 14 5 9 15 8 13 3 12 6 7 4 \\\\r\\\\n10 5 12 9 15 11 1 13 7 2 8 3 4 6 14 \\\\r\\\\n1 12 14 5 11 7 15 3 8 10 6 4 13 2 9 \\\\r\\\\n13 5 4 8 12 3 14 15 1 9 6 2 11 7 10 \\\\r\\\\n5 14 11 8 6 1 15 2 4 3 12 10 9 13 7 \\\\r\\\\n6 12 3 15 8 14 11 1 4 13 5 2 10 9 7 \\\\r\\\\n9 13 3 5 8 14 12 4 7 6 1 15 11 10 2 \\\\r\\\\n1 14 2 15 7 3 6 5 13 11 8 4 9 10 12 \\\\r\\\\n10 1 9 4 14 11 7 3 5 8 2 6 13 12 15 \\\\r\\\\n13 3 14 5 1 15 7 10 6 4 8 12 2 9 11 \\\\r\\\\n8 1 15 4 10 14 7 2 11 13 9 12 6 3 5 \\\\r\\\\n10 5 12 6 11 14 15 13 2 8 9 1 4 7 3 \\\\r\\\\n11 3 2 5 13 15 9 4 1 12 14 8 10 7 6 \\\\r\\\\n3 11 7 2 1 14 6 8 12 15 9 13 4 10 5 \\\\r\\\\n4 7 12 11 2 6 10 8 14 3 15 13 1 9 5 \\\\r\\\\n6 5 2 12 4 11 9 13 1 7 10 8 14 15 3 \\\\r\\\\n13 11 14 15 3 10 7 12 8 1 9 5 2 6 4 \\\\r\\\\n11 1 15 13 3 7 5 9 8 12 6 2 14 4 10 \\\\r\\\\n2 14 10 15 8 12 3 11 9 7 1 6 13 5 4 \\\\r\\\\n15 2 6 7 3 5 10 14 9 11 1 4 8 12 13 \\\\r\\\\n8 5 1 9 13 10 12 14 6 2 3 15 4 11 7 \\\\r\\\\n3 11 6 13 7 1 5 15 14 12 10 4 9 2 8 \\\\r\\\\n1 6 11 8 3 15 9 10 4 2 13 5 12 7 14 \\\\r\\\\n4 9 3 15 6 10 2 12 7 11 1 8 14 5 13 \\\\r\\\\n13 9 4 2 8 3 14 11 12 15 1 6 5 7 10 \\\\r\\\\n3 9 15 6 4 5 13 2 10 11 1 8 14 12 7 \\\\r\\\\n10 4 8 15 11 3 5 9 6 12 7 14 2 13 1 \\\\r\\\\n8 1 9 15 11 13 6 2 7 5 12 4 14 3 10 \\\\r\\\\n15 3 7 11 1 14 8 13 5 10 2 12 9 6 4 \\\\r\\\\n9 3 13 4 14 2 10 12 6 15 8 7 11 1 5 \\\\r\\\\n5 1 15 10 7 13 12 4 9 11 14 3 2 8 6 \\\\r\\\\n14 1 13 10 8 6 5 3 2 11 9 15 4 7 12 \\\\r\\\\n9 8 6 10 5 1 15 12 7 14 3 13 2 4 11 \\\\r\\\\n11 8 5 12 13 6 4 2 15 10 7 14 1 9 3 \\\\r\\\\n13 14 1 11 5 15 9 10 3 7 2 8 4 6 12 \\\\r\\\\n1 8 15 12 14 11 10 3 5 2 6 9 7 4 13 \\\\r\\\\n10 11 12 4 15 8 2 3 7 13 14 6 5 1 9 \\\\r\\\\n13 6 3 4 8 5 9 12 10 2 11 15 7 14 1 \\\\r\\\\n4 1 12 14 11 9 6 8 10 13 15 7 5 3 2 \\\\r\\\\n4 1 13 9 11 2 5 15 12 10 7 14 3 6 8 \\\\r\\\\n15 11 9 13 2 5 12 7 3 4 10 14 8 6 1 \\\\r\\\\n8 12 15 7 4 13 9 11 5 3 14 2 1 10 6 \\\\r\\\\n11 5 1 2 15 14 6 8 13 9 3 4 12 7 10 \\\\r\\\\n11 2 15 1 5 3 8 9 4 7 6 14 10 13 12 \\\\r\\\\n4 1 6 14 2 13 11 8 10 5 3 7 12 9 15 \\\\r\\\\n9 10 14 15 11 6 3 1 5 13 7 8 2 4 12 \\\\r\\\\n7 12 8 14 6 5 4 2 3 11 13 1 15 10 9 \\\\r\\\\n2 9 14 11 4 1 6 12 8 3 5 15 10 13 7 \\\\r\\\\n6 1 15 5 13 9 7 8 14 3 4 10 11 2 12 \\\\r\\\\n5 12 13 8 4 10 9 15 2 7 11 14 6 3 1 \\\\r\\\\n14 9 10 11 15 1 5 8 6 4 3 12 2 7 13 \\\\r\\\\n10 11 7 8 4 3 9 14 5 6 15 13 2 12 1 \\\\r\\\\n14 12 3 9 1 4 7 6 10 8 2 11 5 13 15 \\\\r\\\\n1 13 5 7 14 10 15 3 9 2 8 12 11 4 6 \\\\r\\\\n1 15 10 14 6 3 7 5 9 11 8 2 12 4 13 \\\\r\\\\n5 1 4 8 11 7 3 15 12 14 13 6 2 10 9 \\\\r\\\\n1 3 4 15 14 9 13 10 2 11 6 8 12 7 5 \\\\r\\\\n5 7 2 4 9 8 12 11 10 6 15 14 3 1 13 \\\\r\\\\n10 13 2 1 14 12 11 6 9 8 3 5 7 15 4 \\\\r\\\\n14 4 7 5 9 8 2 6 3 1 13 15 12 10 11 \\\\r\\\\n10 6 13 3 9 15 14 4 12 1 11 5 8 7 2 \\\\r\\\\n12 11 7 8 4 3 6 5 1 2 14 15 9 13 10 \\\\r\\\\n13 10 14 15 9 3 4 5 11 2 12 1 7 6 8 \\\\r\\\\n7 5 1 9 14 11 4 10 12 8 13 3 15 6 2 \\\\r\\\\n1 3 4 5 2 7 8 10 14 11 9 12 13 6 15 \\\\r\\\\n9 4 6 11 14 15 5 12 8 13 3 7 1 10 2 \\\\r\\\\n14 8 3 11 10 7 2 15 9 1 5 12 6 13 4 \\\\r\\\\n6 8 13 10 4 15 1 9 3 5 12 2 14 7 11 \\\\r\\\\n5 13 9 7 15 10 8 11 6 2 12 14 1 3 4 \\\\r\\\\n12 4 14 1 11 13 3 10 8 15 9 2 7 6 5 \\\\r\\\\n4 8 2 11 5 14 6 1 10 13 9 12 7 3 15 \\\\r\\\\n12 5 3 1 6 9 14 11 7 15 4 2 8 10 13 \\\\r\\\\n6 11 15 5 1 13 12 2 8 7 4 9 10 3 14 \\\\r\\\\n7 8 3 5 13 12 15 11 6 9 14 2 4 1 10 \\\\r\\\\n3 6 8 5 2 14 13 9 4 1 12 15 10 11 7 \\\\r\\\\n7 13 15 9 4 11 2 10 8 14 5 6 3 12 1 \\\\r\\\\n6 5 10 13 9 11 15 14 4 7 3 2 8 1 12 \\\\r\\\\n8 6 2 14 10 5 9 12 11 7 13 3 1 15 4 \\\\r\\\\n11 1 2 15 10 13 7 5 14 9 6 8 12 3 4 \\\\r\\\\n1 15 4 11 10 8 12 13 6 3 7 2 14 9 5 \\\\r\\\\n6 10 9 1 7 14 15 8 4 2 13 5 11 12 3 \\\\r\\\\n7 2 1 6 5 9 4 11 10 12 14 15 13 3 8 \\\\r\\\\n12 1 2 5 9 15 8 11 13 6 10 3 14 7 4 \\\\r\\\\n2 4 8 14 3 1 13 11 10 15 12 6 5 7 9 \\\\r\\\\n11 9 5 10 7 8 3 4 6 1 2 12 14 15 13 \\\\r\\\\n5 9 13 3 15 4 6 1 2 8 10 14 12 11 7 \\\\r\\\\n4 5 9 8 6 3 13 12 11 14 15 10 1 7 2 \\\\r\\\\n11 14 2 13 6 7 3 12 5 9 10 8 15 1 4 \\\\r\\\\n10 11 3 1 8 15 5 7 12 13 9 6 14 4 2 \\\\r\\\\n4 6 8 3 2 13 10 12 7 5 14 15 1 9 11 \\\\r\\\\n5 13 12 15 11 2 7 10 3 8 9 4 14 1 6 \\\\r\\\\n4 6 8 11 12 13 10 9 7 2 3 5 15 14 1 \\\\r\\\\n2 1 9 7 5 13 4 15 12 6 8 3 10 14 11 \\\\r\\\\n11 14 7 8 10 6 15 9 1 5 4 13 3 2 12 \\\\r\\\\n8 13 14 12 9 4 11 15 3 1 2 7 5 10 6 \\\\r\\\\n2 14 15 1 9 7 10 11 6 8 5 13 12 3 4 \\\\r\\\\n7 4 3 15 12 11 14 13 2 10 6 9 5 8 1 \\\\r\\\\n9 10 2 5 3 8 11 13 1 4 15 12 7 14 6 \\\\r\\\\n12 8 2 15 6 5 10 14 9 4 13 11 3 1 7 \\\\r\\\\n12 14 15 8 2 5 4 11 7 10 6 9 1 13 3 \\\\r\\\\n14 15 6 9 13 7 8 10 11 5 12 1 3 4 2 \\\\r\\\\n12 1 11 4 8 7 10 6 9 3 2 14 13 5 15 \\\\r\\\\n4 3 2 10 9 11 1 5 12 15 7 14 6 8 13 \\\\r\\\\n12 14 9 6 1 7 15 10 3 11 2 4 5 8 13 \\\\r\\\\n14 12 3 7 6 11 5 1 10 4 9 2 13 15 8 \\\\r\\\\n2 7 12 13 8 9 14 3 1 11 6 4 15 5 10 \\\\r\\\\n1 5 6 14 11 7 3 8 2 9 10 4 15 13 12 \\\\r\\\\n2 6 4 9 1 11 8 14 13 15 5 7 12 10 3 \\\\r\\\\n15 8 6 5 13 7 2 10 12 11 1 3 4 9 14 \\\\r\\\\n13 2 4 7 11 8 9 15 3 10 5 14 12 6 1 \\\\r\\\\n14 3 1 2 4 13 12 11 6 10 9 8 15 7 5 \\\\r\\\\n9 3 10 5 15 6 12 11 7 8 2 4 1 14 13 \\\\r\\\\n4 3 9 6 12 10 14 15 8 2 13 1 7 11 5 \\\\r\\\\n4 1 5 13 2 11 7 3 6 15 9 8 14 12 10 \\\\r\\\\n10 15 11 2 1 7 4 13 14 5 6 3 8 9 12 \\\\r\\\\n10 2 11 5 1 6 15 7 8 9 12 14 4 3 13 \\\\r\\\\n13 3 4 11 8 6 1 9 14 7 15 10 12 2 5 \\\\r\\\\n6 11 8 5 4 13 12 7 3 2 14 9 10 1 15 \\\\r\\\\n13 8 9 11 1 12 10 4 14 15 6 3 7 2 5 \\\\r\\\\n1 8 5 14 3 11 9 2 15 10 12 6 4 13 7 \\\\r\\\\n4 5 14 2 13 12 10 8 3 7 11 1 9 15 6 \\\\r\\\\n12 3 6 8 9 5 10 2 4 11 15 13 7 1 14 \\\\r\\\\n5 9 1 15 6 12 4 10 3 8 7 14 11 2 13 \\\\r\\\\n8 14 11 12 7 2 10 15 5 3 1 4 13 9 6 \\\\r\\\\n14 12 15 9 10 1 4 8 13 2 7 5 6 3 11 \\\\r\\\\n1 7 3 13 15 12 6 8 9 5 11 2 4 10 14 \\\\r\\\\n14 2 7 4 12 10 6 1 5 3 13 9 8 15 11 \\\\r\\\\n6 10 9 11 14 7 13 3 2 15 5 8 12 1 4 \\\\r\\\\n4 9 3 5 8 15 11 6 12 2 10 1 7 14 13 \\\\r\\\\n8 13 3 4 12 15 1 11 5 7 6 9 10 14 2 \\\\r\\\\n9 6 15 5 14 11 4 2 12 10 1 3 8 13 7 \\\\r\\\\n10 4 8 12 6 3 11 2 1 13 9 5 14 15 7 \\\\r\\\\n9 14 4 2 10 7 15 8 3 13 12 11 6 5 1 \\\\r\\\\n8 13 15 1 9 6 10 14 12 2 3 4 5 11 7 \\\\r\\\\n13 1 15 4 2 12 7 10 6 5 14 3 8 11 9 \\\\r\\\\n8 3 7 6 4 14 11 15 1 5 2 9 10 12 13 \\\\r\\\\n13 10 11 5 15 3 1 12 7 2 6 14 4 8 9 \\\\r\\\\n7 9 15 8 13 6 2 3 12 4 14 11 1 5 10 \\\\r\\\\n12 10 9 15 2 5 4 14 1 3 6 8 7 13 11 \\\\r\\\\n7 8 10 11 14 4 13 6 15 9 2 12 1 3 5 \\\\r\\\\n14 13 12 3 5 15 8 6 10 11 7 4 1 2 9 \\\\r\\\\n4 12 13 15 5 10 7 9 1 2 11 3 8 6 14 \\\\r\\\\n4 7 12 14 1 15 5 11 8 6 9 10 2 3 13 \\\\r\\\\n8 15 14 4 6 11 5 7 13 2 9 1 10 3 12 \\\\r\\\\n7 2 4 14 15 6 10 9 8 3 1 5 12 13 11 \\\\r\\\\n5 1 9 11 3 14 4 10 8 2 13 6 7 15 12 \\\\r\\\\n4 9 12 3 15 11 2 5 14 8 13 7 1 6 10 \\\\r\\\\n2 4 3 13 14 1 5 11 10 7 8 6 12 15 9 \\\\r\\\\n10 4 7 6 9 14 11 5 13 15 12 1 8 3 2 \\\\r\\\\n7 1 11 2 8 15 13 3 12 9 6 10 14 4 5 \\\\r\\\\n14 8 5 11 6 9 12 13 10 4 15 2 1 7 3 \\\\r\\\\n6 13 14 12 1 15 9 7 5 3 11 10 8 4 2 \\\\r\\\\n8 15 10 5 14 2 4 12 13 1 11 9 7 6 3 \\\\r\\\\n14 7 11 13 3 8 9 2 4 15 5 1 10 12 6 \\\\r\\\\n7 4 13 8 5 12 2 15 9 11 6 10 14 1 3 \\\\r\\\\n11 14 6 3 8 2 4 12 7 13 5 1 10 15 9 \\\\r\\\\n10 8 5 11 12 4 15 9 1 14 2 13 7 6 3 \\\\r\\\\n11 3 7 15 8 9 1 14 2 12 5 6 13 4 10 \\\\r\\\\n14 12 15 11 10 9 5 4 2 6 3 7 8 1 13 \\\\r\\\\n3 5 2 15 8 9 10 6 13 12 1 14 4 7 11 \\\\r\\\\n2 10 5 3 7 15 9 8 12 11 4 6 14 13 1 \\\\r\\\\n12 9 5 15 8 6 14 13 2 1 3 10 11 4 7 \\\\r\\\\n15 11 13 8 9 2 3 7 6 10 1 14 4 5 12 \\\\r\\\\n14 5 9 1 15 4 8 10 13 12 6 7 3 2 11 \\\\r\\\\n14 1 5 2 15 13 4 8 6 7 3 10 9 12 11 \\\\r\\\\n2 10 3 11 15 7 9 14 12 6 4 1 13 8 5 \\\\r\\\\n2 4 3 1 14 12 5 13 10 9 11 8 15 7 6 \\\\r\\\\n11 9 3 12 10 2 13 14 4 7 8 1 5 6 15 \\\\r\\\\n15 6 12 11 10 13 7 5 2 8 4 14 1 9 3 \\\\r\\\\n3 7 10 11 8 2 1 9 14 12 5 13 15 6 4 \\\\r\\\\n7 15 14 4 8 1 3 9 13 6 2 10 12 11 5 \\\\r\\\\n5 12 6 11 13 8 2 10 4 7 1 14 9 3 15 \\\\r\\\\n8 11 12 3 7 6 9 10 2 14 5 1 13 4 15 \\\\r\\\\n9 12 2 1 6 8 10 14 5 3 15 13 7 4 11 \\\\r\\\\n1 8 14 2 9 13 5 11 10 15 3 12 4 7 6 \\\\r\\\\n7 5 15 4 11 10 1 9 6 3 12 2 14 13 8 \\\\r\\\\n11 4 10 13 2 3 14 7 1 5 12 6 15 9 8 \\\\r\\\\n8 13 10 3 11 12 2 15 6 1 7 4 9 5 14 \\\\r\\\\n8 1 5 4 12 14 13 3 11 10 9 2 15 7 6 \\\\r\\\\n2 11 14 6 4 8 9 1 12 5 13 7 10 3 15 \\\\r\\\\n11 1 9 6 12 8 3 10 14 4 7 13 15 2 5 \\\\r\\\\n11 12 10 14 2 13 1 3 6 7 9 4 8 5 15 \\\\r\\\\n11 13 10 15 14 5 3 6 12 8 7 4 9 1 2 \\\\r\\\\n1 6 11 14 4 5 8 9 15 2 10 12 13 7 3 \\\\r\\\\n15 7 11 8 12 14 9 13 6 3 2 5 4 10 1 \\\\r\\\\n10 3 12 4 11 13 6 14 7 5 9 1 8 2 15 \\\\r\\\\n1 10 3 8 5 6 13 12 4 14 7 15 2 9 11 \\\\r\\\\n2 5 12 15 9 13 3 14 8 10 7 1 6 11 4 \\\\r\\\\n13 4 6 9 2 8 11 1 12 15 10 7 14 3 5 \\\\r\\\\n13 14 8 1 10 6 5 9 3 12 11 15 4 2 7 \\\\r\\\\n15 9 4 1 7 11 13 12 2 10 6 3 14 8 5 \\\\r\\\\n4 3 2 6 14 1 13 8 9 11 7 5 15 12 10 \\\\r\\\\n4 8 11 3 2 6 7 12 14 1 10 15 9 13 5 \\\\r\\\\n11 2 15 10 5 9 4 3 13 7 8 6 12 14 1 \\\\r\\\\n6 3 5 8 2 1 7 9 12 11 13 15 10 4 14 \\\\r\\\\n10 9 4 8 15 5 12 6 7 3 14 11 1 2 13 \\\\r\\\\n7 4 5 2 10 15 11 1 12 8 6 9 14 3 13 \\\\r\\\\n13 4 11 9 6 3 5 15 7 10 1 8 12 14 2 \\\\r\\\\n5 14 12 4 6 1 7 10 8 13 11 3 9 2 15 \\\\r\\\\n6 1 13 3 10 12 9 11 14 4 7 15 5 8 2 \\\\r\\\\n11 6 15 14 2 13 3 5 7 8 9 12 4 10 1 \\\\r\\\\n14 9 2 8 3 13 4 10 6 12 1 5 11 15 7 \\\\r\\\\n6 7 5 9 2 4 15 14 3 12 13 10 1 8 11 \\\\r\\\\n8 3 7 9 14 5 12 13 11 2 6 1 4 10 15 \\\\r\\\\n8 11 9 10 4 7 1 14 3 6 5 2 12 15 13 \\\\r\\\\n6 14 12 2 8 7 13 10 1 5 11 3 4 9 15 \\\\r\\\\n4 13 8 3 9 2 11 1 14 6 5 12 15 7 10 \\\\r\\\\n3 13 5 6 15 8 1 11 4 12 14 7 9 2 10 \\\\r\\\\n11 7 15 8 9 14 1 6 3 12 5 10 2 13 4 \\\\r\\\\n4 10 2 8 1 12 6 3 9 14 7 15 11 5 13 \\\\r\\\\n12 10 8 15 1 9 14 11 6 3 4 2 5 13 7 \\\\r\\\\n14 12 9 11 7 13 4 15 8 2 6 1 3 10 5 \\\\r\\\\n5 13 8 11 10 6 12 9 7 14 15 2 3 1 4 \\\\r\\\\n10 5 7 11 1 9 3 14 8 6 12 4 2 15 13 \\\\r\\\\n2 12 15 1 3 7 4 14 6 11 5 10 8 9 13 \\\\r\\\\n14 11 12 8 3 9 2 10 5 1 4 7 15 13 6 \\\\r\\\\n2 4 15 9 8 6 10 5 3 11 12 1 14 7 13 \\\\r\\\\n14 10 2 7 5 15 12 3 1 6 13 8 9 4 11 \\\\r\\\\n1 8 11 6 10 14 5 15 13 9 7 4 12 3 2 \\\\r\\\\n1 5 10 8 9 13 15 6 11 14 4 2 3 12 7 \\\\r\\\\n1 11 10 15 13 4 2 9 5 7 8 3 6 14 12 \\\\r\\\\n10 6 7 15 1 11 13 3 4 12 14 2 8 9 5 \\\\r\\\\n9 6 15 14 12 10 2 7 11 3 5 1 4 13 8 \\\\r\\\\n13 5 8 9 15 4 1 14 2 10 11 3 7 12 6 \\\\r\\\\n13 2 4 5 3 11 15 8 14 7 9 10 12 6 1 \\\\r\\\\n15 2 11 13 1 6 5 8 4 10 9 7 14 12 3 \\\\r\\\\n12 14 9 10 4 7 6 8 13 15 2 1 11 3 5 \\\\r\\\\n13 11 6 4 1 5 14 15 7 9 2 3 12 10 8 \\\\r\\\\n4 9 3 6 11 2 5 1 12 13 14 8 10 7 15 \\\\r\\\\n15 1 10 2 13 12 7 5 6 8 14 11 4 9 3 \\\\r\\\\n12 4 14 5 1 8 6 2 11 3 9 7 15 13 10 \\\\r\\\\n7 12 1 4 11 10 8 9 3 6 15 5 2 13 14 \\\\r\\\\n3 10 6 13 2 15 4 7 12 5 9 1 14 8 11 \\\\r\\\\n4 3 13 8 6 11 10 12 2 1 14 7 15 5 9 \\\\r\\\\n7 2 10 15 11 1 13 4 3 6 12 9 5 8 14 \\\\r\\\\n15 14 10 8 3 11 6 1 9 2 7 5 12 4 13 \\\\r\\\\n6 1 2 11 3 15 4 14 12 8 9 10 5 7 13 \\\\r\\\\n14 1 11 9 15 2 12 7 13 8 3 10 5 6 4 \\\\r\\\\n4 10 3 9 5 2 12 15 6 11 7 14 13 8 1 \\\\r\\\\n4 9 14 8 3 12 13 7 15 5 2 11 1 10 6 \\\\r\\\\n3 7 12 10 4 15 2 8 13 14 6 9 1 11 5 \\\\r\\\\n11 13 6 15 3 2 4 1 8 7 14 12 10 9 5 \\\\r\\\\n3 13 8 9 4 5 10 1 6 7 2 12 11 15 14 \\\\r\\\\n2 14 3 1 6 5 13 11 10 15 4 12 7 8 9 \\\\r\\\\n2 8 11 4 7 6 3 12 5 1 9 13 10 15 14 \\\\r\\\\n14 2 10 9 11 3 5 8 13 4 12 15 7 6 1 \\\\r\\\\n13 2 7 9 15 11 5 4 12 1 10 6 8 3 14 \\\\r\\\\n10 15 3 2 6 13 7 14 1 8 11 4 5 12 9 \\\\r\\\\n6 5 1 13 7 12 11 8 4 3 14 2 15 9 10 \\\\r\\\\n1 11 3 4 9 6 8 10 13 2 12 7 15 5 14 \\\\r\\\\n14 10 5 6 13 15 4 7 3 2 1 11 12 9 8 \\\\r\\\\n4 5 11 13 9 6 12 1 7 8 10 3 15 14 2 \\\\r\\\\n14 8 11 4 6 13 7 1 2 5 10 9 3 12 15 \\\\r\\\\n1 14 12 10 3 13 4 7 9 8 5 15 6 11 2 \\\\r\\\\n15 4 8 12 7 9 11 13 3 2 10 14 6 1 5 \\\\r\\\\n4 12 7 15 2 11 5 1 9 10 3 14 6 13 8 \\\\r\\\\n6 7 5 1 13 11 10 15 2 4 12 3 14 8 9 \\\\r\\\\n2 4 9 13 1 6 10 15 3 7 14 11 8 5 12 \\\\r\\\\n3 6 12 1 8 4 5 2 14 10 15 7 11 9 13 \\\\r\\\\n12 5 14 7 10 3 13 1 4 8 11 9 6 15 2 \\\\r\\\\n7 3 13 10 15 14 12 11 8 6 9 2 1 5 4 \\\\r\\\\n1 13 11 5 14 4 9 6 8 15 10 12 3 2 7 \\\\r\\\\n3 10 5 14 9 13 7 8 6 1 15 12 4 11 2 \\\\r\\\\n11 1 14 9 4 13 3 12 7 5 6 10 8 2 15 \\\\r\\\\n7 10 6 4 14 12 11 5 15 9 8 3 2 13 1 \\\\r\\\\n1 8 4 12 11 2 14 9 13 5 15 7 6 10 3 \\\\r\\\\n2 4 3 9 14 11 5 7 12 1 6 8 13 10 15 \\\\r\\\\n7 2 10 9 4 11 8 12 5 6 15 1 14 13 3 \\\\r\\\\n9 11 4 1 5 10 13 15 8 7 2 12 3 14 6 \\\\r\\\\n2 8 13 7 9 3 14 15 5 11 6 12 4 1 10 \\\\r\\\\n11 4 1 2 6 14 7 10 5 12 8 9 13 15 3 \\\\r\\\\n3 11 4 5 2 1 7 12 14 15 9 8 6 13 10 \\\\r\\\\n14 1 3 7 12 5 6 9 13 15 4 10 8 11 2 \\\\r\\\\n14 3 13 5 7 15 4 2 8 9 6 12 10 11 1 \\\\r\\\\n15 11 5 7 14 9 2 8 6 13 12 4 10 3 1 \\\\r\\\\n5 12 8 2 1 10 7 11 14 13 6 3 4 9 15 \\\\r\\\\n1 8 2 7 5 6 3 9 14 15 13 10 12 11 4 \\\\r\\\\n8 10 15 5 4 11 2 12 13 14 6 3 7 1 9 \\\\r\\\\n11 5 13 12 2 10 8 1 7 3 15 6 9 14 4 \\\\r\\\\n4 6 8 9 3 13 10 2 12 1 5 7 15 14 11 \\\\r\\\\n14 5 1 11 13 4 3 15 12 6 9 7 2 8 10 \\\\r\\\\n7 2 11 5 15 6 12 3 4 1 13 10 8 14 9 \\\\r\\\\n5 12 11 4 13 2 10 6 3 7 14 15 8 1 9 \\\\r\\\\n13 10 9 3 4 8 1 5 11 14 2 12 7 6 15 \\\\r\\\\n3 2 11 6 13 4 14 7 15 8 9 10 1 12 5 \\\\r\\\\n12 15 3 6 2 13 14 11 5 10 8 1 4 7 9 \\\\r\\\\n7 13 11 10 1 6 5 12 9 2 15 4 14 8 3 \\\\r\\\\n15 10 9 8 7 12 5 1 14 11 3 2 4 6 13 \\\\r\\\\n15 2 9 11 6 4 3 13 1 8 5 10 12 7 14 \\\\r\\\\n3 5 2 4 9 8 6 12 10 1 15 7 11 13 14 \\\\r\\\\n4 5 7 8 6 15 14 10 1 12 11 2 9 3 13 \\\\r\\\\n3 10 7 13 9 11 14 15 8 2 4 1 12 5 6 \\\\r\\\\n2 15 4 6 5 9 7 3 11 8 10 12 13 1 14 \\\\r\\\\n5 1 12 6 11 9 8 13 4 2 7 10 14 15 3 \\\\r\\\\n10 11 5 3 9 4 8 15 7 2 1 14 6 12 13 \\\\r\\\\n5 15 11 4 12 1 10 14 13 2 9 3 8 7 6 \\\\r\\\\n10 1 4 8 12 14 6 13 3 5 11 9 15 2 7 \\\\r\\\\n3 5 12 10 11 8 14 9 13 6 15 1 2 4 7 \\\\r\\\\n1 9 15 14 2 12 3 13 7 5 11 4 10 8 6 \\\\r\\\\n4 6 1 8 15 14 5 13 3 12 10 9 11 7 2 \\\\r\\\\n2 6 14 9 4 15 10 8 1 11 3 5 7 13 12 \\\\r\\\\n14 11 7 15 10 5 4 8 2 12 9 1 6 13 3 \\\\r\\\\n13 14 4 1 6 2 15 11 9 3 12 7 10 8 5 \\\\r\\\\n2 13 11 10 5 6 4 7 12 1 8 3 9 14 15 \\\\r\\\\n3 4 2 12 8 10 6 14 5 13 15 1 7 9 11 \\\\r\\\\n6 8 10 5 1 9 2 13 11 7 15 14 3 4 12 \\\\r\\\\n1 6 10 12 15 11 3 8 7 9 13 14 4 5 2 \\\\r\\\\n13 9 1 12 5 15 4 2 11 3 10 14 6 8 7 \\\\r\\\\n11 8 14 6 3 1 7 2 9 15 5 12 13 4 10 \\\\r\\\\n5 4 13 10 8 14 1 15 9 12 6 7 3 2 11 \\\\r\\\\n9 15 8 2 7 14 12 3 6 10 5 13 1 11 4 \\\\r\\\\n2 8 13 9 1 6 3 14 7 12 11 15 10 5 4 \\\\r\\\\n7 10 3 12 9 5 15 14 4 11 13 2 8 6 1 \\\\r\\\\n6 2 7 12 1 13 14 11 9 10 15 5 4 3 8 \\\\r\\\\n1 10 8 4 13 12 6 2 7 15 14 3 9 11 5 \\\\r\\\\n13 15 1 9 7 11 10 4 6 14 8 2 5 3 12 \\\\r\\\\n3 6 8 11 15 14 13 4 12 1 9 7 5 10 2 \\\\r\\\\n12 14 7 10 5 13 2 8 11 6 15 4 1 3 9 \\\\r\\\\n11 10 12 3 4 1 5 14 2 6 15 8 7 9 13 \\\\r\\\\n12 6 10 5 4 7 3 2 9 13 8 1 14 11 15 \\\\r\\\\n8 6 7 10 4 13 5 15 11 3 14 12 9 1 2 \\\\r\\\\n8 3 10 7 15 2 14 6 13 11 12 1 4 5 9 \\\\r\\\\n7 14 10 4 6 12 2 9 13 5 1 3 8 11 15 \\\\r\\\\n3 1 7 14 15 9 11 6 12 5 2 10 8 13 4 \\\\r\\\\n6 14 4 8 10 15 3 1 9 13 7 2 5 12 11 \\\\r\\\\n2 6 5 10 13 12 8 14 4 15 11 3 1 9 7 \\\\r\\\\n12 14 3 15 13 6 9 11 8 1 10 5 4 2 7 \\\\r\\\\n14 2 3 6 10 13 4 15 7 8 9 12 5 1 11 \\\\r\\\\n12 11 9 8 10 15 5 6 4 3 7 1 13 2 14 \\\\r\\\\n15 8 1 4 12 3 9 11 10 7 5 13 14 6 2 \\\\r\\\\n1 5 12 3 15 2 7 9 13 8 4 14 10 6 11 \\\\r\\\\n4 8 1 9 10 14 11 6 2 13 15 7 12 5 3 \\\\r\\\\n10 14 12 15 6 9 2 8 3 13 7 5 1 11 4 \\\\r\\\\n1 2 15 10 3 6 11 4 12 14 8 5 7 9 13 \\\\r\\\\n12 3 6 11 2 4 9 7 14 8 15 10 5 13 1 \\\\r\\\\n10 1 9 13 8 2 3 12 14 15 4 7 6 11 5 \\\\r\\\\n5 14 15 12 3 10 1 6 4 13 7 9 11 8 2 \\\\r\\\\n1 14 6 2 10 4 15 3 8 13 7 11 5 12 9 \\\\r\\\\n8 4 5 11 2 10 13 15 12 7 1 3 14 9 6 \\\\r\\\\n7 6 8 5 4 3 13 11 1 10 12 14 9 15 2 \\\\r\\\\n14 4 7 6 9 11 5 13 10 15 1 12 3 2 8 \\\\r\\\\n7 2 13 5 1 3 6 8 14 11 15 9 10 4 12 \\\\r\\\\n9 15 14 6 3 1 8 11 2 13 5 12 7 10 4 \\\\r\\\\n13 6 10 8 15 11 12 2 4 7 14 9 3 1 5 \\\\r\\\\n5 10 14 11 6 12 2 15 13 1 8 3 4 9 7 \\\\r\\\\n4 15 10 11 9 1 3 12 5 6 2 8 13 14 7 \\\\r\\\\n6 4 13 11 5 1 8 14 7 3 15 12 10 2 9 \\\\r\\\\n11 4 7 6 12 1 14 3 13 8 15 2 10 9 5 \\\\r\\\\n14 8 13 3 5 10 11 9 15 4 6 7 12 2 1 \\\\r\\\\n8 15 3 2 4 11 10 6 1 12 13 7 5 9 14 \\\\r\\\\n3 9 11 14 4 10 8 5 6 15 13 7 12 1 2 \\\\r\\\\n5 3 9 2 15 13 8 11 12 10 1 4 14 7 6 \\\\r\\\\n12 8 3 15 14 9 4 6 11 10 2 5 1 13 7 \\\\r\\\\n2 1 9 10 4 8 3 15 14 6 11 5 13 12 7 \\\\r\\\\n\\"}\\n]\\n", "source_code": "\\n// NOTE: The actual exam will not use Websheets (instead, the PA submit system).\\n// It''s recommended to practice and test on your own machine and copy here to check.\\n \\\\[\\n\\n/****************************************************************************\\n* Solution for Hats Part 2\\n*\\n* Read in list size and permutations of that size.\\n* Determine the max cycle length of each permutation.\\n* Compute and print the average max cycle length.\\n*****************************************************************************/\\n\\n#include <iostream>\\nusing namespace std;\\n\\n// determine longest cycle to get own hat back\\nint maxCycleLength(int arr[], int N) {\\n int max = 0; // max cycle length\\n int cycle; // current cycle length\\n\\n // for each person\\n for (int i = 0; i < N; i++) {\\n int j = i;\\n cycle = 1; // minimal cycle has 1 person \\n\\n // while person j doesn''t have person i''s hat\\n while (arr[j] != i+1) {\\n j = arr[j] - 1; // new person j to look for\\n cycle++;\\n }\\n \\n if (max < cycle) max = cycle; // new longest cycle\\n }\\n\\n // return longest cycle length\\n return max;\\n}\\n \\nint main() {\\n // the # of items in the permutation\\n int N;\\n cin >> N;\\n \\n // space to hold permutation\\n int arr[100];\\n\\n // running sum for max cycle lengths\\n int sum = 0;\\n\\n // how many derangements have we seen?\\n int count = 0;\\n \\n // Read until there are no more permutations left on StdIn.\\n while (!cin.fail()) {\\n // fill array\\n for (int i = 0; i < N; i++) {\\n cin >> arr[i];\\n }\\n\\n if (!cin.fail()) {\\n // count it and find its max cycle length\\n count++;\\n sum += maxCycleLength(arr, N);\\n }\\n } \\n // compute and print average with the given format\\n cout << \\"Average max cycle length: \\" << (double) sum / count << endl;\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:05', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(254, '[email protected]', 'cpp/exam_practice/FoodPart2', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPlease see <a href=\\"http://bits.usc.edu/cs103/programming-exam/\\">the programming exam page</a>.\\n<br>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"3\\\\nCanada 13\\\\nMexico 14\\\\nUSA 14\\", \\"args\\": [\\"3\\"]},\\n {\\"stdin\\": \\"6\\\\nGER 13\\\\nBEL 15\\\\nAUT 17\\\\nCHF 19\\\\nLUX 14\\\\nLIE 8\\", \\"args\\": [\\"2\\"]},\\n {\\"stdin\\": \\"1\\\\nPangaea 10\\", \\"args\\": [\\"1\\"]},\\n {\\"stdin\\": \\"2\\\\nA 5\\\\nB 5\\", \\"args\\": [\\"2\\"]},\\n {\\"stdin\\": \\"2\\\\nA 5\\\\nB 8\\", \\"args\\": [\\"2\\"]},\\n {\\"stdin\\": \\"2\\\\nA 8\\\\nB 5\\", \\"args\\": [\\"2\\"]},\\n {\\"stdin\\": \\"3\\\\nA 8\\\\nB 8\\\\nC 1\\", \\"args\\": [\\"3\\"]},\\n {\\"stdin\\": \\"4\\\\nA 8\\\\nB 5\\\\nC 8\\\\nD 5\\", \\"args\\": [\\"1\\"]},\\n {\\"stdin\\": \\"4\\\\nA 8\\\\nB 5\\\\nC 8\\\\nD 5\\", \\"args\\": [\\"4\\"]},\\n {\\"stdin\\": \\"7\\\\nA 8\\\\nB 6\\\\nC 7\\\\nD 5\\\\nE 3\\\\nF 10\\\\nG 9\\", \\"args\\": [\\"3\\"]},\\n {\\"stdin\\": \\"7\\\\nA 8\\\\nB 6\\\\nC 7\\\\nD 5\\\\nE 3\\\\nF 10\\\\nG 9\\", \\"args\\": [\\"7\\"]},\\n {\\"stdin\\": \\"9\\\\nA 3\\\\nB 14\\\\nC 15\\\\nD 9\\\\nE 2\\\\nF 6\\\\nG 5\\\\nH 3\\\\nI 5\\", \\"args\\": [\\"1\\"]},\\n {\\"stdin\\": \\"9\\\\nA 3\\\\nB 14\\\\nC 15\\\\nD 9\\\\nE 2\\\\nF 6\\\\nG 5\\\\nH 3\\\\nI 5\\", \\"args\\": [\\"3\\"]},\\n {\\"stdin\\": \\"9\\\\nA 3\\\\nB 14\\\\nC 15\\\\nD 9\\\\nE 2\\\\nF 6\\\\nG 5\\\\nH 3\\\\nI 5\\", \\"args\\": [\\"9\\"]}\\n]\\n", "source_code": "\\n// NOTE: The actual exam will not use Websheets (instead, the PA submit system).\\n// It''s recommended to practice and test on your own machine and copy here to check.\\n\\\\[\\n/******************************************************************* \\n Reference solution for Foodlympics Part Two: Gourmet Glory\\n\\n Description: Reads in names and scores for C countries. Prints out the N\\n top-score countries in order. \\n**************************************************************************/\\n\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\n// find the highest value in scores. set this value to 0, and \\n// return the corresponding element of countries.\\n// C is the number of countries\\nstring best(string countries[], int C, int scores[]) {\\n\\n // max is the maximum score seen so far\\n int max = scores[0];\\n\\n // bestIndex is the index of the (earliest) max-score country\\n int bestIndex = 0; \\n \\n // find index of max-score country\\n for (int i = 0; i < C; i++) {\\n if (scores[i] > max) {\\n max = scores[i];\\n bestIndex = i;\\n }\\n }\\n \\n // do required update and return the winner\\n scores[bestIndex] = 0;\\n return countries[bestIndex];\\n}\\n\\n// read in a file of scores, and take N from the command-line.\\n// then print out the top N ranking countries from best to worst.\\nint main(int argc, char* argv[]) {\\n\\n int C; // number of countries\\n cin >> C;\\n\\n int N = atoi(argv[1]); // how many to rank\\n\\n string countries[100];\\n int scores[100];\\n\\n // read the rest of the input\\n for (int i = 0; i < C; i++) {\\n cin >> countries[i];\\n cin >> scores[i];\\n }\\n \\n // now print the results\\n for (int i = 0; i < N; i++) {\\n string nextRanked = best(countries, C, scores);\\n cout << \\"Rank \\" << i+1 << \\": \\" << nextRanked << endl;\\n }\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(255, '[email protected]', 'cpp/exam_practice/SnowMelt', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPlease see <a href=\\"http://bits.usc.edu/cs103/programming-exam/\\">the programming exam page</a>.\\n<br>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\", \\"args\\": [\\"5\\"]},\\n {\\"stdin\\": \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\", \\"args\\": [\\"10\\"]},\\n {\\"stdin\\": \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\", \\"args\\": [\\"2\\"]},\\n {\\"stdin\\": \\"8.0 21\\\\n2.0 24\\\\n0.0 45\\\\n2.4 30\\\\n1.9 19\\\\n4.4 26\\", \\"args\\": [\\"5\\", \\"10\\"]},\\n {\\"stdin\\": \\"8.0 12\\\\n12.0 -5\\\\n0.0 -2\\\\n2.4 6\\\\n0.9 23\\\\n0.1 23\\\\n1.3 39\\", \\"args\\": [\\"0\\", \\"3\\", \\"6\\"]},\\n {\\"stdin\\": \\"0.0 13\\", \\"args\\": [\\"5\\", \\"10\\", \\"20\\"]},\\n {\\"stdin\\": \\"108.0 200\\\\n102.7 200\\\\n10000 200\\", \\"args\\": [\\"0\\", \\"7\\", \\"14\\"]},\\n {\\"stdin\\": \\"102.0 -199\\\\n100.0 -145\\\\n102.4 -200\\\\n101.9 -119\\\\n104.4 -126\\", \\"args\\": [\\"3\\", \\"9\\", \\"20\\"]},\\n {\\"stdin\\": \\"1.6 27\\\\n0.1 -4\\\\n1.5 26\\\\n3.4 77\\\\n7.7 -13\\\\n3.6 75\\\\n6.0 -10\\\\n7.5 49\\\\n6.2 -6\\\\n4.7 -36\\\\n8.1 49\\\\n7.6 -18\\\\n0.8 -25\\\\n2.0 31\\\\n1.1 69\\\\n6.6 27\\\\n9.6 -26\\\\n4.4 -7\\\\n8.6 -11\\\\n3.1 51\\\\n8.0 -26\\\\n3.1 71\\\\n2.3 -4\\\\n6.6 50\\\\n3.0 36\\\\n4.0 62\\\\n1.4 30\\\\n2.8 -4\\\\n5.3 53\\\\n4.5 12\\\\n6.9 -34\\\\n9.5 25\\\\n9.6 31\\\\n6.8 -20\\\\n6.6 36\\\\n9.3 59\\\\n1.8 32\\\\n7.4 8\\\\n0.2 -35\\\\n5.8 14\\\\n3.3 7\\\\n1.4 33\\\\n0.0 0\\\\n2.3 42\\\\n2.1 15\\\\n8.7 40\\\\n3.9 -30\\\\n0.5 76\\\\n3.7 -11\\\\n10.0 74\\\\n9.3 18\\\\n2.3 21\\\\n8.1 23\\\\n3.0 77\\\\n3.0 60\\\\n9.8 3\\\\n7.3 12\\\\n2.8 -11\\\\n0.8 35\\\\n1.6 24\\\\n9.2 -27\\\\n6.2 -16\\\\n0.5 51\\\\n8.4 77\\\\n9.5 -40\\\\n7.0 -2\\\\n6.6 -16\\\\n8.2 -30\\\\n1.5 65\\\\n5.6 52\\\\n1.1 -40\\\\n7.0 71\\\\n8.7 -15\\\\n7.8 -10\\\\n8.2 14\\\\n4.3 -7\\\\n8.6 61\\\\n8.1 -39\\\\n5.7 4\\\\n3.1 53\\\\n1.0 74\\\\n8.0 20\\\\n8.8 -14\\\\n3.3 60\\\\n1.7 16\\\\n2.6 -9\\\\n1.6 1\\\\n7.0 51\\\\n7.2 -21\\\\n6.1 33\\\\n3.5 20\\\\n6.5 9\\\\n5.5 -15\\\\n2.0 39\\\\n0.5 7\\\\n1.2 39\\\\n\\", \\"args\\": [\\"2\\", \\"12\\", \\"30\\"]}\\n]\\n", "source_code": "\\n// NOTE: The actual exam will not use Websheets (instead, the PA submit system).\\n// It''s recommended to practice and test on your own machine and copy here to check.\\n \\\\[\\n\\n/****************************************************************************\\n* Solution for Exam Part 2: SnowMelt\\n*\\n* Description: Simulates how fast the snow will melt \\n* based on how much salt is used and temp\\n* ***************************************************************************/\\n\\n#include <cmath>\\n#include <iostream>\\n#include <algorithm>\\n#include <iomanip>\\nusing namespace std;\\n\\n// using current snow, temperature and salt solution\\n// how much snow will melt?\\ndouble meltage(double currSnow, int temp, int salt) {\\n double result = pow(1 + currSnow, (temp - 32 + 2*salt)/18.0);\\n result = min(currSnow, result);\\n return result;\\n}\\n \\n// formatted printing of a double[] array\\nvoid printArray(double arr[], double length) {\\n for (int i = 0; i < length; i++)\\n cout << setw(8) << setprecision(3) << arr[i];\\n\\n // new line after all entries printed\\n cout << endl;\\n}\\n \\n// Part 2B: input data file from standard input\\n// input salt solution ints from command-line\\n// output remaining snow for each day for each salt solution\\nint main(int argc, char* argv[]) {\\n // store salt for scenarios\\n int N = argc-1;\\n int salt[100];\\n for (int i = 0; i < N; i++)\\n salt[i] = atoi(argv[i+1]);\\n \\n // array of snow left on ground for each scenario\\n double snowLeft[100];\\n \\n // input snow in inches and temp in degrees F for each day\\n while (true) {\\n // read data from standard input\\n double newSnow;\\n cin >> newSnow;\\n int temp;\\n cin >> temp;\\n if (cin.fail())\\n return 0; // input is done\\n \\n // compute meltage for one day with each salt value\\n for (int i = 0; i < N; i++) {\\n snowLeft[i] = snowLeft[i] + newSnow;\\n double melt = meltage(snowLeft[i], temp, salt[i]);\\n // how much snow left after the melting?\\n snowLeft[i] = snowLeft[i] - melt;\\n }\\n printArray(snowLeft, N);\\n }\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:05', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(256, '[email protected]', 'cpp/exam_practice/HatsPart1', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nPlease see <a href=\\"http://bits.usc.edu/cs103/programming-exam/\\">the programming exam page</a>.\\n<br>\\nWe recommend doing this practice in a timed environment; give yourself 90 minutes.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"9\\\\n9 8 7 6 5 4 3 2 1\\\\n3 7 6 9 8 2 1 5 4\\"},\\n {\\"stdin\\": \\"6\\\\n1 2 6 4 3 5\\\\n6 1 5 4 3 2\\"},\\n {\\"stdin\\": \\"9\\\\n1 2 3 4 5 6 7 8 9\\\\n9 8 7 6 5 4 3 2 1\\\\n2 1 4 3 6 5 8 7 9\\\\n8 9 2 1 4 7 5 3 6\\\\n3 7 6 9 8 2 1 5 4\\"},\\n {\\"stdin\\": \\"15\\\\r\\\\n13 2 6 4 5 8 1 7 14 12 3 10 11 9 15 \\\\r\\\\n12 8 7 5 9 10 1 14 13 2 4 3 11 15 6 \\\\r\\\\n11 3 14 15 12 9 8 1 5 7 10 4 6 13 2 \\\\r\\\\n3 2 4 14 6 7 12 13 9 5 8 11 15 10 1 \\\\r\\\\n7 12 3 4 6 2 8 10 5 13 1 14 9 15 11 \\\\r\\\\n14 7 4 9 1 5 3 12 11 8 10 13 2 6 15 \\\\r\\\\n12 7 3 2 14 1 5 15 6 8 4 13 10 11 9 \\\\r\\\\n1 9 11 14 6 10 5 12 3 8 13 2 15 7 4 \\\\r\\\\n15 10 2 5 12 1 8 7 11 6 13 3 9 14 4 \\\\r\\\\n14 7 6 8 9 4 2 10 5 12 3 1 11 13 15 \\\\r\\\\n9 10 15 12 2 13 11 7 1 8 3 5 4 14 6 \\\\r\\\\n11 4 15 8 10 9 13 2 14 1 3 6 5 7 12 \\\\r\\\\n2 12 4 10 3 6 15 13 1 8 14 7 5 9 11 \\\\r\\\\n14 3 12 11 4 7 9 6 10 2 13 8 1 5 15 \\\\r\\\\n1 10 5 3 12 11 7 15 8 13 6 4 9 2 14 \\\\r\\\\n11 13 7 2 6 14 1 12 3 5 9 10 4 15 8 \\\\r\\\\n6 9 11 3 12 5 1 7 13 2 15 14 8 4 10 \\\\r\\\\n3 14 4 2 10 8 13 1 5 15 6 7 11 12 9 \\\\r\\\\n7 10 6 15 9 11 14 13 8 1 4 5 2 3 12 \\\\r\\\\n7 2 3 5 14 12 13 9 11 8 6 4 1 15 10 \\\\r\\\\n10 2 8 15 5 1 9 4 3 11 13 7 6 12 14 \\\\r\\\\n1 11 10 6 2 4 8 13 14 12 7 3 15 9 5 \\\\r\\\\n2 14 6 11 7 4 10 13 1 5 15 3 9 12 8 \\\\r\\\\n7 10 4 3 8 1 15 14 2 5 6 11 12 9 13 \\\\r\\\\n10 4 15 5 12 2 8 6 14 1 13 3 9 7 11 \\\\r\\\\n7 11 15 9 2 3 10 4 5 14 8 12 13 6 1 \\\\r\\\\n8 10 15 5 2 11 3 9 1 13 7 12 6 4 14 \\\\r\\\\n14 1 15 9 12 13 6 2 11 3 5 10 7 4 8 \\\\r\\\\n2 8 10 1 11 12 3 13 9 4 14 15 7 5 6 \\\\r\\\\n10 14 9 2 5 6 1 8 13 4 15 11 3 12 7 \\\\r\\\\n5 7 11 1 14 9 4 15 2 3 13 10 8 6 12 \\\\r\\\\n4 8 3 13 2 7 9 14 5 10 1 6 15 12 11 \\\\r\\\\n12 10 11 14 4 5 9 8 15 7 13 2 1 3 6 \\\\r\\\\n7 5 15 3 13 9 8 6 2 1 12 10 4 11 14 \\\\r\\\\n10 8 4 11 1 2 9 13 5 12 6 7 15 14 3 \\\\r\\\\n3 9 15 7 11 1 2 13 5 14 4 10 12 6 8 \\\\r\\\\n10 2 9 4 11 3 15 1 14 7 8 12 6 13 5 \\\\r\\\\n2 12 5 14 8 11 7 6 1 9 4 15 10 13 3 \\\\r\\\\n6 10 13 1 5 8 4 3 12 14 2 7 15 9 11 \\\\r\\\\n6 14 12 8 11 13 15 10 9 4 7 1 3 2 5 \\\\r\\\\n7 11 9 4 3 13 15 12 6 14 10 8 5 1 2 \\\\r\\\\n14 6 8 3 9 4 13 11 2 10 15 12 7 5 1 \\\\r\\\\n14 4 6 3 15 8 11 9 12 10 1 7 5 13 2 \\\\r\\\\n4 14 13 2 3 12 5 15 10 11 1 8 6 7 9 \\\\r\\\\n5 8 11 6 4 1 13 7 3 15 9 12 2 10 14 \\\\r\\\\n2 10 14 11 3 7 5 9 4 15 6 1 8 12 13 \\\\r\\\\n10 1 5 14 3 4 15 12 8 13 7 11 6 2 9 \\\\r\\\\n15 7 1 10 4 11 13 8 6 12 2 5 3 9 14 \\\\r\\\\n14 4 13 2 6 12 11 3 7 8 15 9 1 5 10 \\\\r\\\\n9 8 12 11 5 3 10 14 13 1 6 15 2 7 4 \\\\r\\\\n13 12 10 3 15 1 7 5 4 6 11 8 9 14 2 \\\\r\\\\n2 13 8 6 3 7 4 9 5 12 10 14 1 11 15 \\\\r\\\\n4 1 8 5 15 12 6 10 13 2 3 14 11 9 7 \\\\r\\\\n5 1 9 8 14 12 2 15 4 11 7 3 10 6 13 \\\\r\\\\n8 4 13 3 11 7 10 2 15 6 14 9 5 1 12 \\\\r\\\\n10 11 6 2 3 7 8 13 15 12 14 1 4 9 5 \\\\r\\\\n10 4 14 3 1 5 7 6 13 15 9 11 12 8 2 \\\\r\\\\n4 13 8 11 9 14 10 1 15 6 5 2 7 3 12 \\\\r\\\\n12 14 1 15 9 10 5 7 11 8 4 13 6 2 3 \\\\r\\\\n2 8 9 11 4 6 15 10 12 7 14 13 3 1 5 \\\\r\\\\n3 10 6 13 8 2 14 11 5 15 4 7 1 12 9 \\\\r\\\\n7 1 5 9 8 12 3 6 4 15 11 13 10 14 2 \\\\r\\\\n15 2 5 6 3 10 8 14 1 7 12 11 9 4 13 \\\\r\\\\n4 13 5 11 10 7 9 15 3 14 12 2 8 6 1 \\\\r\\\\n13 7 5 6 10 3 2 1 11 9 8 14 12 4 15 \\\\r\\\\n11 14 10 3 12 9 2 15 13 8 5 4 1 6 7 \\\\r\\\\n14 15 9 12 3 8 10 2 6 13 4 7 11 5 1 \\\\r\\\\n11 12 4 8 13 14 1 6 10 15 2 3 5 9 7 \\\\r\\\\n3 8 4 1 12 15 7 14 9 6 10 11 5 13 2 \\\\r\\\\n8 2 13 7 6 10 1 14 4 11 15 9 3 12 5 \\\\r\\\\n6 2 5 13 8 4 15 1 7 12 10 9 3 14 11 \\\\r\\\\n9 3 13 11 5 14 15 7 1 4 2 10 6 8 12 \\\\r\\\\n7 4 1 2 9 15 14 3 5 6 11 10 12 8 13 \\\\r\\\\n14 5 9 11 8 10 3 6 4 1 13 2 15 12 7 \\\\r\\\\n1 11 3 7 2 5 13 12 10 15 4 14 6 8 9 \\\\r\\\\n3 1 10 8 4 9 14 12 2 6 15 5 7 11 13 \\\\r\\\\n4 5 7 10 12 14 9 15 8 3 2 11 13 6 1 \\\\r\\\\n5 10 6 12 2 15 1 14 4 3 13 7 11 9 8 \\\\r\\\\n5 12 1 7 6 15 14 10 9 3 13 2 4 8 11 \\\\r\\\\n2 14 12 7 9 6 3 5 13 15 4 11 1 8 10 \\\\r\\\\n1 11 4 10 7 14 8 2 6 3 13 5 15 12 9 \\\\r\\\\n12 5 9 14 6 4 7 11 1 15 3 13 10 8 2 \\\\r\\\\n1 12 15 14 2 6 5 7 3 9 8 4 13 10 11 \\\\r\\\\n14 8 15 6 5 3 12 2 9 10 11 7 1 13 4 \\\\r\\\\n9 7 2 13 1 6 4 11 12 8 15 5 10 3 14 \\\\r\\\\n15 10 3 1 2 9 6 13 12 8 7 14 11 5 4 \\\\r\\\\n1 13 11 2 3 15 14 8 6 9 4 12 5 7 10 \\\\r\\\\n5 13 6 15 1 10 7 8 9 3 12 14 4 2 11 \\\\r\\\\n1 8 14 5 15 4 10 7 3 2 6 9 13 12 11 \\\\r\\\\n9 11 6 1 3 10 13 15 14 8 5 4 12 2 7 \\\\r\\\\n5 2 12 10 1 11 13 8 14 9 7 15 4 6 3 \\\\r\\\\n3 6 5 15 12 7 13 8 14 4 2 1 11 10 9 \\\\r\\\\n15 10 6 2 4 12 13 8 9 14 7 1 3 5 11 \\\\r\\\\n11 9 13 8 14 12 6 2 7 4 3 10 1 5 15 \\\\r\\\\n11 2 9 6 10 12 5 13 1 4 7 15 3 8 14 \\\\r\\\\n10 15 2 6 5 4 11 9 13 8 14 3 1 12 7 \\\\r\\\\n1 15 7 4 3 12 9 2 14 11 8 10 5 13 6 \\\\r\\\\n4 1 14 12 13 6 15 10 2 7 8 11 3 9 5 \\\\r\\\\n11 9 6 15 1 4 13 10 3 12 14 5 2 8 7 \\\\r\\\\n5 13 15 14 1 7 10 11 4 9 3 12 2 8 6 \\\\r\\\\n1 7 10 11 12 4 13 5 15 3 14 6 2 8 9 \\\\r\\\\n5 7 9 15 12 10 2 8 1 4 13 11 3 6 14 \\\\r\\\\n12 3 8 10 9 1 15 11 14 13 2 4 5 7 6 \\\\r\\\\n3 15 8 13 12 10 1 2 11 9 7 14 4 5 6 \\\\r\\\\n1 11 4 6 13 10 15 2 8 12 14 7 3 5 9 \\\\r\\\\n11 7 2 13 1 8 5 12 10 14 4 9 3 15 6 \\\\r\\\\n9 4 13 6 1 5 14 12 15 8 2 11 10 3 7 \\\\r\\\\n14 15 8 9 6 12 5 1 11 4 13 2 10 7 3 \\\\r\\\\n5 10 7 12 3 2 8 6 4 11 1 15 13 14 9 \\\\r\\\\n7 1 8 5 4 6 10 2 9 12 15 3 14 11 13 \\\\r\\\\n10 6 8 12 9 11 1 13 2 3 14 4 5 7 15 \\\\r\\\\n4 7 13 11 6 15 5 8 2 1 9 14 12 10 3 \\\\r\\\\n5 6 10 7 12 14 2 1 9 11 3 15 8 4 13 \\\\r\\\\n8 5 2 11 7 14 15 3 6 10 9 12 1 13 4 \\\\r\\\\n13 14 3 9 7 1 11 4 8 12 2 10 5 6 15 \\\\r\\\\n3 12 9 1 2 5 15 14 7 10 6 11 8 13 4 \\\\r\\\\n10 5 1 7 9 14 12 6 3 8 13 15 4 2 11 \\\\r\\\\n10 7 13 15 11 5 14 6 9 1 2 4 3 8 12 \\\\r\\\\n7 9 5 14 11 4 3 12 13 15 2 6 8 1 10 \\\\r\\\\n3 10 7 14 9 2 6 15 12 4 8 13 5 1 11 \\\\r\\\\n3 9 12 1 4 11 13 15 6 5 8 10 7 14 2 \\\\r\\\\n9 1 8 2 6 10 3 12 11 4 15 5 14 13 7 \\\\r\\\\n15 11 6 3 8 12 1 5 2 13 7 10 14 9 4 \\\\r\\\\n7 13 6 5 2 14 11 8 1 12 9 15 10 4 3 \\\\r\\\\n15 11 7 8 1 14 2 9 12 13 4 3 5 6 10 \\\\r\\\\n9 6 10 4 15 3 12 5 1 11 13 2 8 7 14 \\\\r\\\\n4 15 5 1 6 9 2 11 8 10 12 3 7 13 14 \\\\r\\\\n6 4 8 13 12 2 10 15 7 3 5 14 9 1 11 \\\\r\\\\n10 12 3 2 9 8 13 6 4 15 5 1 11 14 7 \\\\r\\\\n9 12 1 6 8 5 2 13 4 7 3 10 14 11 15 \\\\r\\\\n6 10 15 3 11 9 4 5 13 7 1 14 2 8 12 \\\\r\\\\n12 6 2 8 1 11 9 15 3 14 5 4 10 13 7 \\\\r\\\\n2 15 8 6 12 3 7 10 4 14 1 11 9 13 5 \\\\r\\\\n4 14 7 2 6 5 12 9 13 3 10 8 15 1 11 \\\\r\\\\n10 11 1 5 9 13 14 8 12 15 2 7 4 6 3 \\\\r\\\\n12 7 2 11 9 14 5 1 8 6 15 10 13 4 3 \\\\r\\\\n14 13 12 3 15 5 1 4 11 10 7 2 8 6 9 \\\\r\\\\n9 15 14 5 11 7 13 12 1 3 4 2 6 10 8 \\\\r\\\\n10 1 3 9 4 14 2 11 12 15 13 7 6 8 5 \\\\r\\\\n15 3 13 6 12 2 1 7 5 8 9 11 14 4 10 \\\\r\\\\n7 14 3 9 1 15 4 2 8 13 12 11 10 6 5 \\\\r\\\\n1 2 8 7 5 4 3 11 14 6 13 10 9 15 12 \\\\r\\\\n10 9 6 1 8 11 7 4 14 3 2 5 13 12 15 \\\\r\\\\n8 9 1 2 3 15 6 10 12 13 14 7 5 11 4 \\\\r\\\\n15 13 6 2 9 1 14 7 3 10 11 8 12 5 4 \\\\r\\\\n13 15 12 1 5 9 7 11 8 6 4 10 3 14 2 \\\\r\\\\n3 13 11 9 12 15 4 1 8 6 5 7 14 10 2 \\\\r\\\\n7 3 9 14 13 4 8 5 10 6 2 11 1 15 12 \\\\r\\\\n9 2 1 14 12 4 15 8 6 13 10 11 5 3 7 \\\\r\\\\n1 15 4 12 7 9 10 14 8 5 3 2 13 6 11 \\\\r\\\\n11 7 2 13 3 9 8 12 4 1 10 5 6 15 14 \\\\r\\\\n11 15 4 7 8 14 9 6 3 1 2 10 12 13 5 \\\\r\\\\n2 7 3 10 15 1 12 9 4 13 6 8 5 11 14 \\\\r\\\\n2 1 9 5 3 13 7 15 6 4 11 12 14 10 8 \\\\r\\\\n4 9 1 6 5 10 14 8 15 12 7 13 11 3 2 \\\\r\\\\n15 12 7 4 2 8 5 10 13 14 9 3 6 11 1 \\\\r\\\\n2 4 14 7 12 15 11 10 1 9 5 6 13 3 8 \\\\r\\\\n5 7 2 4 12 11 15 6 14 1 9 8 10 13 3 \\\\r\\\\n12 6 9 8 13 14 15 3 4 7 2 10 5 11 1 \\\\r\\\\n11 10 1 14 7 2 3 8 13 15 6 5 9 4 12 \\\\r\\\\n10 8 4 7 2 3 6 13 1 11 14 5 12 15 9 \\\\r\\\\n7 4 3 2 8 9 14 1 12 15 6 11 10 13 5 \\\\r\\\\n13 10 6 11 9 4 5 14 7 2 1 8 3 12 15 \\\\r\\\\n4 7 13 2 1 11 15 12 8 5 6 3 14 9 10 \\\\r\\\\n6 11 10 12 2 9 4 3 15 5 14 7 1 8 13 \\\\r\\\\n6 11 2 12 7 15 14 4 5 9 13 3 8 1 10 \\\\r\\\\n7 11 5 13 8 4 3 2 12 6 9 14 15 10 1 \\\\r\\\\n10 3 6 1 5 13 9 15 2 8 7 4 11 14 12 \\\\r\\\\n10 6 14 12 11 7 8 4 15 13 1 9 3 5 2 \\\\r\\\\n11 14 1 8 10 13 5 6 4 3 15 12 2 9 7 \\\\r\\\\n7 6 13 15 3 14 1 12 2 11 8 4 9 10 5 \\\\r\\\\n9 8 12 14 5 2 13 6 7 10 4 1 15 3 11 \\\\r\\\\n5 15 1 4 13 14 8 11 2 10 9 3 6 7 12 \\\\r\\\\n10 13 15 12 8 7 2 5 1 3 4 9 6 14 11 \\\\r\\\\n1 9 11 8 12 3 14 10 5 2 15 7 6 4 13 \\\\r\\\\n10 4 7 11 14 5 6 8 9 2 12 3 13 15 1 \\\\r\\\\n10 4 6 11 2 14 9 12 1 13 3 8 7 5 15 \\\\r\\\\n3 9 7 5 1 15 2 11 4 13 10 8 14 6 12 \\\\r\\\\n13 8 14 15 11 12 6 7 1 4 3 9 2 10 5 \\\\r\\\\n8 9 14 3 1 6 4 2 7 12 15 5 11 10 13 \\\\r\\\\n1 11 9 7 14 5 3 2 12 10 4 6 15 13 8 \\\\r\\\\n10 2 7 3 5 13 11 4 14 8 12 6 15 9 1 \\\\r\\\\n2 5 4 12 1 10 14 7 9 15 11 8 6 3 13 \\\\r\\\\n7 11 2 6 5 8 1 14 10 13 3 12 15 9 4 \\\\r\\\\n13 6 3 2 9 8 5 1 7 14 15 10 4 11 12 \\\\r\\\\n6 5 12 14 10 15 1 3 7 9 11 13 2 8 4 \\\\r\\\\n11 9 7 12 4 10 2 13 3 6 1 15 14 5 8 \\\\r\\\\n11 9 6 13 7 8 12 14 4 2 5 1 15 3 10 \\\\r\\\\n12 4 13 6 5 10 9 3 1 2 8 11 14 15 7 \\\\r\\\\n8 2 6 9 5 7 4 14 11 12 15 3 13 1 10 \\\\r\\\\n5 2 11 3 13 12 15 9 14 4 8 7 1 6 10 \\\\r\\\\n10 1 9 12 11 7 6 15 2 4 8 14 13 3 5 \\\\r\\\\n15 10 4 1 3 5 7 9 13 8 12 14 6 11 2 \\\\r\\\\n9 4 13 1 7 10 14 15 5 2 8 12 6 3 11 \\\\r\\\\n13 11 1 2 10 12 9 3 7 14 4 15 5 6 8 \\\\r\\\\n14 2 7 10 1 8 12 11 6 9 15 5 4 13 3 \\\\r\\\\n4 14 15 3 5 7 8 12 6 1 13 10 11 2 9 \\\\r\\\\n8 4 2 14 15 10 13 11 7 9 6 1 5 12 3 \\\\r\\\\n3 14 11 10 6 1 2 5 9 12 4 15 13 8 7 \\\\r\\\\n3 5 12 4 11 9 6 14 13 1 10 15 8 2 7 \\\\r\\\\n14 10 3 5 11 1 15 13 12 8 4 9 6 7 2 \\\\r\\\\n5 12 13 14 3 11 10 7 4 9 1 15 8 6 2 \\\\r\\\\n6 11 10 15 12 4 7 5 3 14 1 13 9 2 8 \\\\r\\\\n3 14 6 10 15 5 13 9 4 12 11 8 2 1 7 \\\\r\\\\n7 9 10 3 6 2 11 5 1 15 14 4 12 8 13 \\\\r\\\\n5 15 4 2 1 11 13 9 10 14 8 6 12 3 7 \\\\r\\\\n2 4 11 14 7 12 5 13 10 6 9 3 15 1 8 \\\\r\\\\n1 8 3 12 15 11 5 6 10 13 4 7 2 14 9 \\\\r\\\\n11 12 1 13 4 15 9 3 2 5 8 14 7 10 6 \\\\r\\\\n5 15 8 11 4 10 6 12 13 2 1 7 9 3 14 \\\\r\\\\n11 13 4 7 10 1 14 3 6 15 9 2 5 8 12 \\\\r\\\\n1 9 10 8 5 11 15 13 14 7 4 12 2 3 6 \\\\r\\\\n11 2 7 9 13 10 4 8 5 14 6 12 1 3 15 \\\\r\\\\n15 12 7 11 4 6 5 8 10 9 13 3 14 1 2 \\\\r\\\\n4 7 9 15 13 12 11 5 3 1 10 6 14 8 2 \\\\r\\\\n7 6 3 11 5 9 4 15 8 14 2 12 10 1 13 \\\\r\\\\n6 8 9 7 13 12 15 11 5 3 1 2 4 10 14 \\\\r\\\\n2 7 14 4 1 5 6 15 11 3 8 12 10 13 9 \\\\r\\\\n11 4 8 6 1 3 5 12 9 10 14 15 7 13 2 \\\\r\\\\n11 4 10 7 15 9 1 5 13 6 14 3 8 2 12 \\\\r\\\\n11 2 8 10 14 1 5 15 6 3 7 13 4 9 12 \\\\r\\\\n15 6 4 9 11 5 3 10 12 2 1 13 8 14 7 \\\\r\\\\n2 3 15 8 11 9 6 4 12 14 10 1 13 7 5 \\\\r\\\\n10 7 6 15 8 13 11 2 12 9 14 1 5 4 3 \\\\r\\\\n12 6 11 10 8 3 1 15 7 5 14 9 2 13 4 \\\\r\\\\n8 15 5 11 7 2 1 4 3 10 13 6 12 14 9 \\\\r\\\\n11 5 9 6 10 3 14 13 1 7 15 12 4 8 2 \\\\r\\\\n6 11 7 10 4 15 3 14 1 13 8 2 5 12 9 \\\\r\\\\n10 9 15 2 13 12 14 6 3 1 4 7 8 11 5 \\\\r\\\\n2 15 1 7 12 11 3 5 8 9 14 4 13 10 6 \\\\r\\\\n13 1 14 5 6 9 3 11 10 8 12 2 7 15 4 \\\\r\\\\n1 14 3 10 5 8 7 2 13 4 6 12 11 15 9 \\\\r\\\\n3 7 12 2 8 15 5 13 10 9 4 14 6 11 1 \\\\r\\\\n2 5 11 15 9 13 14 3 4 10 8 6 12 1 7 \\\\r\\\\n11 15 2 3 7 10 14 9 4 5 12 6 8 13 1 \\\\r\\\\n7 14 13 10 9 4 1 6 11 8 15 2 3 12 5 \\\\r\\\\n7 4 3 6 14 11 1 2 10 12 9 5 15 13 8 \\\\r\\\\n9 3 7 8 1 15 2 13 12 6 4 11 14 5 10 \\\\r\\\\n10 9 8 13 14 12 4 5 6 11 15 1 2 7 3 \\\\r\\\\n14 8 1 12 15 5 2 9 3 7 6 11 13 4 10 \\\\r\\\\n1 5 8 4 7 9 3 10 6 11 12 14 15 13 2 \\\\r\\\\n8 1 6 15 12 13 4 11 7 10 9 3 5 14 2 \\\\r\\\\n9 11 5 1 3 2 14 4 7 6 13 12 15 10 8 \\\\r\\\\n10 14 1 12 7 11 8 2 4 15 3 6 9 13 5 \\\\r\\\\n5 11 10 3 7 2 14 9 8 1 12 15 6 13 4 \\\\r\\\\n9 3 12 2 7 6 5 1 14 11 8 13 10 4 15 \\\\r\\\\n5 4 12 1 6 14 3 15 2 7 13 11 10 8 9 \\\\r\\\\n3 4 11 10 1 14 8 5 6 13 12 7 15 2 9 \\\\r\\\\n7 11 8 10 13 3 12 4 2 14 9 15 6 1 5 \\\\r\\\\n2 4 1 10 7 3 6 15 11 14 12 9 8 5 13 \\\\r\\\\n1 14 10 2 5 6 13 8 15 12 7 3 4 9 11 \\\\r\\\\n15 6 5 14 10 4 7 1 13 9 2 3 8 12 11 \\\\r\\\\n2 3 9 10 7 11 15 6 13 5 4 8 12 1 14 \\\\r\\\\n11 12 5 14 8 1 2 4 10 3 7 15 13 9 6 \\\\r\\\\n10 9 11 8 12 4 13 15 3 1 2 6 7 5 14 \\\\r\\\\n5 11 14 6 2 1 12 4 9 13 7 8 15 3 10 \\\\r\\\\n7 2 1 15 13 6 9 11 10 3 14 5 4 8 12 \\\\r\\\\n9 8 12 2 1 5 4 13 3 10 7 6 11 15 14 \\\\r\\\\n14 12 15 1 7 11 8 2 4 6 13 9 5 10 3 \\\\r\\\\n14 3 7 6 1 5 15 13 12 4 11 10 2 9 8 \\\\r\\\\n9 13 11 10 7 15 2 1 12 6 4 3 5 14 8 \\\\r\\\\n10 4 5 12 1 8 3 2 7 13 6 11 15 9 14 \\\\r\\\\n13 2 8 1 14 3 11 9 4 5 15 12 6 7 10 \\\\r\\\\n3 11 1 5 6 14 10 4 15 12 7 2 9 8 13 \\\\r\\\\n5 8 2 11 1 13 4 3 9 12 7 14 10 15 6 \\\\r\\\\n14 1 12 10 2 9 6 4 8 7 3 13 5 15 11 \\\\r\\\\n11 2 14 5 15 9 10 3 8 1 4 13 7 6 12 \\\\r\\\\n1 6 5 3 15 13 2 14 10 4 11 12 9 8 7 \\\\r\\\\n14 3 10 6 9 1 4 15 5 12 7 8 2 11 13 \\\\r\\\\n14 3 5 15 2 1 12 7 9 6 11 10 13 8 4 \\\\r\\\\n1 10 9 13 15 8 5 11 2 6 7 3 4 14 12 \\\\r\\\\n3 12 15 10 8 14 5 1 11 7 9 4 13 2 6 \\\\r\\\\n15 5 6 14 4 10 1 12 3 11 8 9 13 2 7 \\\\r\\\\n13 2 8 9 11 14 10 12 1 5 7 6 4 15 3 \\\\r\\\\n8 13 1 5 7 11 4 14 12 9 10 3 15 6 2 \\\\r\\\\n9 14 12 8 1 6 13 10 15 7 11 3 2 5 4 \\\\r\\\\n3 11 2 7 12 9 1 15 10 13 6 8 14 4 5 \\\\r\\\\n7 11 10 14 3 4 2 5 15 9 6 12 1 8 13 \\\\r\\\\n14 1 2 3 5 4 7 8 10 9 6 13 11 15 12 \\\\r\\\\n9 3 2 7 13 1 4 11 6 8 5 14 10 12 15 \\\\r\\\\n14 13 12 8 9 3 5 4 2 6 10 7 1 11 15 \\\\r\\\\n10 8 7 6 5 12 1 11 4 14 2 13 9 3 15 \\\\r\\\\n6 10 12 2 15 14 7 13 4 1 9 8 11 5 3 \\\\r\\\\n4 6 7 1 8 12 2 9 10 3 11 13 5 15 14 \\\\r\\\\n2 1 12 15 13 10 4 11 14 3 7 6 8 5 9 \\\\r\\\\n9 12 14 15 11 2 8 13 6 1 7 5 10 4 3 \\\\r\\\\n14 6 15 2 4 5 1 3 10 9 12 11 13 7 8 \\\\r\\\\n8 10 14 15 3 6 2 7 11 12 4 13 1 9 5 \\\\r\\\\n6 12 5 14 15 9 10 1 11 4 3 13 8 2 7 \\\\r\\\\n11 10 15 13 6 9 2 4 3 5 7 12 1 14 8 \\\\r\\\\n6 4 2 5 8 7 11 9 3 13 15 10 12 1 14 \\\\r\\\\n12 1 3 7 14 9 10 6 15 11 4 8 13 2 5 \\\\r\\\\n14 10 12 15 7 6 9 5 1 8 11 3 13 2 4 \\\\r\\\\n11 3 12 1 8 6 10 15 9 5 13 4 2 7 14 \\\\r\\\\n10 12 1 6 4 13 3 15 5 9 7 11 2 14 8 \\\\r\\\\n3 13 2 7 6 10 11 9 1 14 15 5 12 8 4 \\\\r\\\\n15 9 13 11 1 14 2 5 12 7 8 3 10 6 4 \\\\r\\\\n8 3 5 12 11 7 13 6 1 14 4 15 2 9 10 \\\\r\\\\n9 15 13 14 5 8 6 12 2 4 3 1 7 11 10 \\\\r\\\\n4 13 2 7 5 6 3 10 14 15 8 11 12 1 9 \\\\r\\\\n9 1 7 12 2 8 5 3 14 4 11 15 13 10 6 \\\\r\\\\n6 10 1 13 15 3 2 14 12 11 8 5 4 9 7 \\\\r\\\\n10 1 11 8 5 14 6 3 15 4 9 2 12 7 13 \\\\r\\\\n8 4 13 2 1 7 9 15 6 14 5 10 11 3 12 \\\\r\\\\n4 5 7 9 8 1 6 3 15 12 10 13 11 14 2 \\\\r\\\\n15 3 8 2 1 6 5 11 10 13 12 4 9 14 7 \\\\r\\\\n15 9 6 1 7 13 12 5 14 11 10 2 3 4 8 \\\\r\\\\n11 12 13 9 5 4 10 14 1 2 6 8 15 3 7 \\\\r\\\\n10 9 13 11 4 14 1 15 2 6 7 5 3 12 8 \\\\r\\\\n11 10 3 6 14 15 1 9 8 12 13 2 5 7 4 \\\\r\\\\n2 3 7 11 1 4 14 12 8 15 6 5 9 10 13 \\\\r\\\\n13 6 14 10 8 9 4 3 11 5 2 1 7 15 12 \\\\r\\\\n4 3 9 14 1 6 15 10 13 2 12 8 11 5 7 \\\\r\\\\n4 6 11 10 15 13 3 2 12 5 14 8 1 7 9 \\\\r\\\\n9 5 3 7 15 14 12 4 6 2 1 13 11 10 8 \\\\r\\\\n11 2 10 6 15 5 9 13 4 1 8 7 3 12 14 \\\\r\\\\n14 13 5 3 4 2 9 15 6 11 1 10 7 12 8 \\\\r\\\\n7 10 8 9 14 11 15 1 2 3 13 5 6 12 4 \\\\r\\\\n7 8 11 6 4 3 2 10 9 14 5 13 15 12 1 \\\\r\\\\n9 7 12 1 8 10 14 13 4 5 3 2 6 11 15 \\\\r\\\\n11 7 13 1 4 12 8 3 14 2 15 6 10 9 5 \\\\r\\\\n4 7 8 9 10 11 6 1 12 2 15 13 14 5 3 \\\\r\\\\n8 15 12 13 4 3 2 14 10 7 6 1 11 5 9 \\\\r\\\\n12 9 10 2 3 4 1 8 11 5 15 7 13 6 14 \\\\r\\\\n15 7 5 12 11 1 13 2 8 4 9 10 6 14 3 \\\\r\\\\n5 12 10 3 8 2 11 4 15 14 6 13 7 1 9 \\\\r\\\\n8 12 7 13 3 1 10 6 2 14 11 5 15 9 4 \\\\r\\\\n6 5 1 3 14 7 13 2 12 8 4 11 15 10 9 \\\\r\\\\n4 9 5 13 7 15 1 12 8 2 3 10 11 6 14 \\\\r\\\\n7 11 2 9 12 15 1 4 10 14 6 13 3 8 5 \\\\r\\\\n4 2 8 11 6 10 7 12 15 14 9 13 3 5 1 \\\\r\\\\n7 10 9 5 14 1 2 11 6 8 12 4 3 13 15 \\\\r\\\\n4 12 14 8 7 2 11 10 6 15 9 1 3 13 5 \\\\r\\\\n15 9 8 13 10 14 5 12 3 7 2 11 6 4 1 \\\\r\\\\n4 15 12 3 13 6 8 9 14 5 2 1 11 7 10 \\\\r\\\\n12 5 1 2 3 4 6 13 10 15 8 14 7 9 11 \\\\r\\\\n5 11 9 4 10 6 12 13 15 1 3 7 14 2 8 \\\\r\\\\n5 11 8 13 1 10 14 9 3 15 2 4 6 7 12 \\\\r\\\\n10 1 12 11 9 7 6 3 13 14 15 5 8 4 2 \\\\r\\\\n6 1 10 14 4 3 15 9 5 8 2 13 11 12 7 \\\\r\\\\n2 15 7 4 5 10 6 8 9 1 11 3 13 12 14 \\\\r\\\\n14 10 13 11 15 1 2 4 6 8 12 9 3 7 5 \\\\r\\\\n3 10 11 15 13 14 4 1 6 2 12 7 8 5 9 \\\\r\\\\n5 2 3 11 14 1 8 9 4 6 13 15 7 10 12 \\\\r\\\\n9 15 8 14 13 7 5 10 12 2 1 4 6 3 11 \\\\r\\\\n14 13 15 3 2 7 8 4 11 1 12 9 6 10 5 \\\\r\\\\n5 15 10 3 11 13 1 7 2 9 6 14 4 12 8 \\\\r\\\\n5 15 7 11 13 6 3 4 10 9 2 12 8 14 1 \\\\r\\\\n7 9 15 11 10 6 5 13 2 1 14 8 4 12 3 \\\\r\\\\n10 1 3 14 12 9 13 7 11 8 2 6 15 4 5 \\\\r\\\\n13 6 14 1 8 10 9 11 4 2 12 5 3 15 7 \\\\r\\\\n15 4 11 2 10 13 7 12 9 8 5 6 14 3 1 \\\\r\\\\n2 5 13 15 10 6 12 11 3 8 9 4 7 1 14 \\\\r\\\\n1 4 14 6 2 10 15 3 9 11 5 12 8 7 13 \\\\r\\\\n6 15 5 12 14 8 7 10 4 3 1 2 11 9 13 \\\\r\\\\n2 5 1 7 3 15 10 13 8 6 11 9 12 14 4 \\\\r\\\\n10 13 8 2 4 14 3 1 11 6 9 12 5 15 7 \\\\r\\\\n4 5 1 3 14 11 2 8 13 6 9 15 12 10 7 \\\\r\\\\n7 10 6 9 2 12 14 5 15 4 8 3 13 1 11 \\\\r\\\\n15 2 11 4 13 8 10 1 14 9 7 6 5 12 3 \\\\r\\\\n6 13 9 4 14 5 15 10 11 8 12 7 2 3 1 \\\\r\\\\n5 8 1 13 3 11 2 9 6 7 10 14 15 12 4 \\\\r\\\\n8 15 6 3 14 2 7 9 13 10 1 5 11 4 12 \\\\r\\\\n9 1 3 7 5 10 11 8 12 15 14 2 6 13 4 \\\\r\\\\n11 14 6 8 13 3 2 15 4 7 10 12 1 9 5 \\\\r\\\\n2 1 10 12 9 13 14 15 6 8 3 7 4 11 5 \\\\r\\\\n7 3 6 5 1 2 10 14 15 11 9 13 8 4 12 \\\\r\\\\n4 2 7 5 11 8 15 14 6 13 1 9 10 12 3 \\\\r\\\\n1 5 2 10 13 6 11 15 9 7 12 8 14 3 4 \\\\r\\\\n13 2 10 8 9 6 11 14 4 7 3 1 5 12 15 \\\\r\\\\n1 3 7 13 9 11 2 15 8 10 6 14 4 12 5 \\\\r\\\\n11 5 15 12 6 2 7 1 13 4 14 9 8 10 3 \\\\r\\\\n12 3 11 7 9 4 2 13 8 15 5 14 10 1 6 \\\\r\\\\n1 15 7 9 8 10 12 11 4 3 6 13 2 5 14 \\\\r\\\\n12 11 5 14 1 2 6 8 10 7 3 15 9 4 13 \\\\r\\\\n13 1 4 6 3 12 10 14 11 7 5 2 15 9 8 \\\\r\\\\n12 5 14 10 3 2 8 13 15 1 9 7 4 6 11 \\\\r\\\\n12 5 9 1 8 4 13 15 2 11 7 6 14 10 3 \\\\r\\\\n11 7 8 5 12 3 2 15 10 4 9 1 6 14 13 \\\\r\\\\n1 3 7 4 8 2 11 10 6 9 14 15 13 12 5 \\\\r\\\\n8 13 5 7 14 10 1 2 15 6 4 3 12 9 11 \\\\r\\\\n2 5 4 3 7 13 12 8 11 10 15 1 9 6 14 \\\\r\\\\n1 2 6 10 9 3 13 12 5 15 11 7 14 8 4 \\\\r\\\\n2 8 3 12 7 13 14 10 15 5 6 11 1 9 4 \\\\r\\\\n6 10 14 8 12 9 5 15 2 1 11 13 7 3 4 \\\\r\\\\n1 13 6 3 11 2 10 14 4 9 15 8 12 5 7 \\\\r\\\\n11 8 10 15 14 13 6 3 1 4 2 5 12 9 7 \\\\r\\\\n8 10 3 9 6 7 11 13 15 4 12 2 1 5 14 \\\\r\\\\n4 3 1 5 11 12 8 9 2 14 15 10 7 13 6 \\\\r\\\\n8 2 13 10 15 11 4 14 3 7 12 9 6 1 5 \\\\r\\\\n4 1 7 15 5 12 14 10 8 13 2 3 9 6 11 \\\\r\\\\n7 4 6 1 3 13 9 14 2 15 8 12 5 11 10 \\\\r\\\\n7 3 11 12 10 6 15 13 8 14 2 9 1 5 4 \\\\r\\\\n2 3 1 4 10 15 6 5 12 8 7 14 13 9 11 \\\\r\\\\n14 10 9 8 7 2 15 12 1 3 4 13 6 5 11 \\\\r\\\\n1 4 13 8 5 7 2 15 3 14 11 10 9 12 6 \\\\r\\\\n7 14 12 6 5 15 4 1 3 2 11 9 13 10 8 \\\\r\\\\n6 7 11 4 5 10 3 13 9 1 2 14 15 12 8 \\\\r\\\\n2 12 7 14 1 9 15 6 10 4 8 13 3 5 11 \\\\r\\\\n4 15 13 8 10 12 9 1 7 11 5 6 14 3 2 \\\\r\\\\n12 9 5 10 14 8 6 13 11 1 3 7 4 2 15 \\\\r\\\\n12 5 7 9 6 1 15 8 14 2 3 4 11 13 10 \\\\r\\\\n6 12 7 8 5 14 4 10 15 1 3 11 13 2 9 \\\\r\\\\n10 6 1 3 4 11 8 12 15 7 14 9 2 5 13 \\\\r\\\\n8 11 2 15 5 1 6 3 13 4 12 10 9 7 14 \\\\r\\\\n13 3 11 1 15 8 4 10 5 6 7 9 2 14 12 \\\\r\\\\n1 8 3 13 10 15 12 5 14 7 6 4 11 9 2 \\\\r\\\\n5 3 9 11 14 1 15 10 7 8 6 13 4 2 12 \\\\r\\\\n11 7 12 13 10 1 14 8 15 2 5 9 3 6 4 \\\\r\\\\n10 12 9 7 4 6 8 15 5 14 11 13 3 1 2 \\\\r\\\\n13 4 2 3 12 1 5 8 7 10 9 14 15 11 6 \\\\r\\\\n8 1 15 2 10 5 4 3 11 14 6 7 13 9 12 \\\\r\\\\n10 11 12 1 8 4 2 6 15 7 5 3 14 13 9 \\\\r\\\\n11 12 14 7 6 5 1 15 3 2 10 4 9 13 8 \\\\r\\\\n13 15 11 6 2 4 7 10 8 3 5 9 1 12 14 \\\\r\\\\n10 4 1 5 3 6 9 13 2 12 14 8 15 11 7 \\\\r\\\\n9 4 14 8 6 1 13 10 2 3 12 11 15 5 7 \\\\r\\\\n10 12 5 6 11 1 8 2 3 7 14 4 13 15 9 \\\\r\\\\n10 2 7 1 12 6 3 5 9 8 4 13 15 11 14 \\\\r\\\\n8 15 3 12 6 7 4 5 2 13 14 9 1 10 11 \\\\r\\\\n13 10 11 12 14 15 6 1 5 8 4 9 7 3 2 \\\\r\\\\n5 7 1 10 12 2 4 9 13 3 8 15 14 6 11 \\\\r\\\\n1 13 8 10 6 5 4 9 15 2 12 3 7 14 11 \\\\r\\\\n15 11 13 10 5 4 3 12 6 2 1 8 7 9 14 \\\\r\\\\n9 7 6 5 4 11 14 15 10 1 3 8 13 2 12 \\\\r\\\\n9 6 7 1 14 11 13 2 15 10 8 4 5 12 3 \\\\r\\\\n1 6 11 5 14 9 2 4 10 13 12 15 3 8 7 \\\\r\\\\n15 4 5 8 6 1 11 3 7 13 9 10 2 14 12 \\\\r\\\\n8 14 1 6 11 2 3 7 15 13 5 9 4 10 12 \\\\r\\\\n11 10 15 7 14 9 2 5 13 3 8 6 12 1 4 \\\\r\\\\n3 10 14 15 9 8 2 6 11 7 4 13 1 5 12 \\\\r\\\\n6 4 1 3 10 2 7 13 8 15 12 9 14 11 5 \\\\r\\\\n10 5 4 13 3 14 9 2 15 8 6 11 12 7 1 \\\\r\\\\n14 2 6 11 8 1 7 4 3 10 5 13 9 15 12 \\\\r\\\\n12 14 3 6 11 8 15 10 1 5 2 4 13 9 7 \\\\r\\\\n8 5 13 2 12 9 15 10 4 3 1 7 14 6 11 \\\\r\\\\n14 4 11 6 15 3 1 8 2 10 7 12 5 13 9 \\\\r\\\\n2 11 8 6 1 7 13 4 9 12 3 10 15 14 5 \\\\r\\\\n10 8 15 7 13 3 14 1 5 9 11 2 12 4 6 \\\\r\\\\n4 6 13 2 15 11 9 5 3 8 1 7 12 10 14 \\\\r\\\\n3 9 8 7 15 1 11 6 5 12 13 14 2 4 10 \\\\r\\\\n14 11 8 6 4 15 10 9 2 1 12 3 13 5 7 \\\\r\\\\n15 1 7 5 8 4 9 13 14 6 10 12 2 3 11 \\\\r\\\\n8 14 12 9 10 5 15 11 3 1 4 7 13 2 6 \\\\r\\\\n7 12 11 15 10 5 9 13 4 1 3 14 2 6 8 \\\\r\\\\n5 8 3 1 9 4 11 14 15 6 7 12 13 2 10 \\\\r\\\\n8 9 3 12 11 4 13 2 1 6 7 10 14 5 15 \\\\r\\\\n4 8 13 11 3 6 5 9 15 10 1 7 12 2 14 \\\\r\\\\n7 9 15 10 2 11 8 13 12 5 3 4 6 14 1 \\\\r\\\\n1 12 10 3 15 5 4 2 8 11 7 14 9 13 6 \\\\r\\\\n15 9 1 2 7 14 13 3 4 5 11 10 12 6 8 \\\\r\\\\n7 15 13 4 10 5 11 2 3 1 12 8 6 9 14 \\\\r\\\\n4 8 12 1 10 6 9 3 5 11 7 13 14 15 2 \\\\r\\\\n11 14 7 6 10 13 3 8 2 12 4 1 15 9 5 \\\\r\\\\n9 10 6 11 2 4 14 7 8 13 5 12 1 3 15 \\\\r\\\\n2 12 6 8 10 13 5 7 1 4 9 11 15 3 14 \\\\r\\\\n14 6 15 11 13 3 9 5 4 10 2 8 1 7 12 \\\\r\\\\n14 2 7 9 13 4 10 1 8 11 12 15 5 6 3 \\\\r\\\\n1 12 10 4 7 3 5 6 13 14 8 9 2 11 15 \\\\r\\\\n9 12 14 8 11 10 5 15 13 6 2 4 3 1 7 \\\\r\\\\n4 8 2 9 1 14 7 13 5 10 6 12 11 3 15 \\\\r\\\\n11 15 10 12 9 2 1 7 6 14 8 4 3 13 5 \\\\r\\\\n15 12 8 9 14 5 3 10 7 4 1 6 11 13 2 \\\\r\\\\n2 12 1 15 6 5 14 13 11 9 3 4 8 7 10 \\\\r\\\\n3 13 10 4 9 7 8 12 14 15 11 5 6 2 1 \\\\r\\\\n13 7 11 15 4 8 6 1 10 9 12 2 5 3 14 \\\\r\\\\n10 4 6 13 9 11 7 3 12 8 15 14 2 1 5 \\\\r\\\\n8 2 11 1 12 13 5 7 6 4 14 10 15 9 3 \\\\r\\\\n4 13 12 2 14 3 11 10 9 7 5 1 15 8 6 \\\\r\\\\n2 6 7 4 11 12 15 8 1 10 14 13 5 3 9 \\\\r\\\\n3 1 4 5 13 2 7 8 11 6 10 14 9 15 12 \\\\r\\\\n3 15 2 7 6 14 13 1 5 8 11 10 12 4 9 \\\\r\\\\n12 10 1 13 8 4 11 3 2 15 7 6 5 14 9 \\\\r\\\\n6 5 11 1 12 9 10 14 4 2 8 7 3 13 15 \\\\r\\\\n10 6 2 11 8 9 5 12 15 13 4 7 3 1 14 \\\\r\\\\n5 13 3 15 6 7 11 2 4 12 1 14 10 9 8 \\\\r\\\\n8 2 3 4 6 14 15 10 13 7 1 9 11 5 12 \\\\r\\\\n8 4 1 2 11 13 12 3 5 15 7 6 10 9 14 \\\\r\\\\n12 2 15 4 14 6 13 3 11 1 7 10 9 5 8 \\\\r\\\\n12 2 8 14 15 4 6 5 1 10 7 3 13 11 9 \\\\r\\\\n8 4 10 14 3 6 15 2 12 1 7 9 5 13 11 \\\\r\\\\n12 15 11 10 3 6 2 9 7 13 5 14 1 8 4 \\\\r\\\\n7 9 2 4 6 3 1 10 8 5 11 14 15 12 13 \\\\r\\\\n5 14 8 12 4 2 11 13 6 1 15 3 10 7 9 \\\\r\\\\n5 6 7 15 14 1 3 9 2 10 8 4 12 11 13 \\\\r\\\\n4 8 9 6 13 11 10 15 12 7 3 5 2 1 14 \\\\r\\\\n8 5 1 13 11 10 14 3 7 4 6 9 2 15 12 \\\\r\\\\n6 14 12 15 7 2 11 8 3 1 4 9 13 5 10 \\\\r\\\\n12 4 11 14 3 9 2 7 5 15 10 8 13 6 1 \\\\r\\\\n11 6 3 4 13 5 15 14 2 12 10 9 7 1 8 \\\\r\\\\n8 7 5 11 14 13 1 3 4 9 12 10 2 15 6 \\\\r\\\\n12 2 15 4 13 6 7 11 3 1 14 8 5 10 9 \\\\r\\\\n13 11 10 2 12 14 6 8 1 7 9 3 15 4 5 \\\\r\\\\n1 3 12 8 14 15 13 9 10 11 4 7 5 6 2 \\\\r\\\\n4 5 9 11 8 15 6 12 10 14 2 13 1 7 3 \\\\r\\\\n13 12 3 7 8 11 9 15 5 2 14 4 10 1 6 \\\\r\\\\n7 11 3 8 2 10 6 4 15 13 12 1 5 14 9 \\\\r\\\\n15 3 12 9 1 8 5 2 6 10 13 14 11 4 7 \\\\r\\\\n13 8 12 14 1 4 5 9 11 10 6 2 15 7 3 \\\\r\\\\n11 14 5 3 4 1 10 8 12 15 6 7 13 9 2 \\\\r\\\\n13 8 12 7 5 4 11 14 6 3 1 2 9 10 15 \\\\r\\\\n6 1 15 11 10 2 9 13 8 14 4 5 12 3 7 \\\\r\\\\n1 5 9 14 10 8 2 3 6 7 15 13 11 12 4 \\\\r\\\\n3 15 1 7 8 9 12 2 13 10 5 6 4 14 11 \\\\r\\\\n8 10 2 13 14 9 3 1 6 15 11 12 4 5 7 \\\\r\\\\n13 7 8 2 14 10 5 6 12 11 15 3 1 4 9 \\\\r\\\\n1 2 13 14 11 12 7 8 10 9 6 15 3 4 5 \\\\r\\\\n15 5 14 7 1 6 10 4 9 8 3 11 13 12 2 \\\\r\\\\n4 7 2 5 9 3 6 13 8 15 1 14 12 10 11 \\\\r\\\\n10 12 4 7 9 3 13 1 5 2 11 15 14 8 6 \\\\r\\\\n1 3 10 11 13 6 9 2 5 14 15 4 7 8 12 \\\\r\\\\n10 8 13 14 4 5 1 12 7 15 11 2 6 9 3 \\\\r\\\\n7 6 15 4 5 10 2 1 11 12 14 3 8 9 13 \\\\r\\\\n15 11 6 9 7 2 12 1 10 8 5 4 3 13 14 \\\\r\\\\n8 11 13 15 6 1 9 4 10 5 12 2 14 3 7 \\\\r\\\\n11 4 13 5 15 2 12 14 1 10 3 7 6 8 9 \\\\r\\\\n5 13 14 10 11 3 15 12 2 8 1 9 7 4 6 \\\\r\\\\n5 15 6 8 13 4 2 9 7 12 3 11 10 1 14 \\\\r\\\\n4 6 1 12 5 7 9 2 10 15 8 13 3 14 11 \\\\r\\\\n12 3 10 2 14 15 7 4 9 11 13 6 5 1 8 \\\\r\\\\n10 3 14 11 1 9 2 4 13 8 6 5 12 7 15 \\\\r\\\\n6 3 10 1 13 7 4 8 12 14 2 5 11 15 9 \\\\r\\\\n1 9 12 2 7 6 14 4 8 15 5 10 3 11 13 \\\\r\\\\n9 7 11 3 10 6 13 14 2 4 1 15 12 8 5 \\\\r\\\\n9 7 8 4 14 12 6 3 5 1 10 11 15 13 2 \\\\r\\\\n4 11 1 6 9 3 8 10 13 14 2 15 5 7 12 \\\\r\\\\n11 1 14 10 12 6 5 15 13 3 7 8 2 9 4 \\\\r\\\\n6 13 7 10 4 5 14 3 9 1 8 12 2 11 15 \\\\r\\\\n12 2 1 3 6 5 10 15 4 7 11 9 8 14 13 \\\\r\\\\n11 3 7 5 10 4 1 14 9 15 6 2 13 12 8 \\\\r\\\\n10 13 14 1 3 11 8 7 6 9 4 2 15 12 5 \\\\r\\\\n11 12 4 2 3 8 9 13 6 10 14 7 15 5 1 \\\\r\\\\n2 5 13 6 1 8 4 11 9 14 10 7 12 15 3 \\\\r\\\\n12 2 10 4 1 13 7 14 11 5 9 15 3 6 8 \\\\r\\\\n15 12 3 7 6 1 14 9 5 10 13 8 11 4 2 \\\\r\\\\n12 2 7 8 1 10 15 13 6 3 5 9 4 14 11 \\\\r\\\\n5 11 14 13 1 9 12 4 6 2 8 7 15 10 3 \\\\r\\\\n9 15 1 4 5 7 6 10 13 14 8 3 2 12 11 \\\\r\\\\n6 8 13 3 2 5 4 10 15 1 7 14 12 11 9 \\\\r\\\\n4 14 3 1 11 5 10 12 7 6 8 15 9 2 13 \\\\r\\\\n4 1 15 2 10 9 12 7 8 5 3 14 6 11 13 \\\\r\\\\n11 10 12 1 5 9 4 6 14 2 13 8 7 15 3 \\\\r\\\\n2 14 9 8 6 7 15 3 12 5 1 4 11 10 13 \\\\r\\\\n4 15 7 11 10 3 5 6 8 14 13 1 2 9 12 \\\\r\\\\n5 3 4 12 6 14 8 9 13 15 11 7 10 1 2 \\\\r\\\\n12 3 13 4 14 10 2 8 7 15 5 1 11 9 6 \\\\r\\\\n14 10 15 5 3 1 8 7 12 13 9 2 4 11 6 \\\\r\\\\n6 2 15 14 12 1 9 11 8 3 13 7 4 5 10 \\\\r\\\\n11 6 5 12 9 1 14 4 2 15 7 8 10 13 3 \\\\r\\\\n13 4 11 6 7 10 8 12 1 2 15 14 3 5 9 \\\\r\\\\n1 7 10 9 5 4 15 2 14 11 8 6 12 13 3 \\\\r\\\\n4 15 8 3 13 2 6 10 5 9 7 12 14 11 1 \\\\r\\\\n7 9 5 2 15 14 1 3 8 12 10 13 4 6 11 \\\\r\\\\n6 10 15 14 3 1 11 4 7 8 12 13 2 5 9 \\\\r\\\\n12 3 1 9 13 6 8 5 4 11 7 14 10 15 2 \\\\r\\\\n11 1 4 6 9 15 10 8 14 3 2 13 5 7 12 \\\\r\\\\n13 3 4 7 6 15 1 2 14 8 5 10 11 12 9 \\\\r\\\\n11 3 9 10 12 1 15 13 6 8 5 2 7 4 14 \\\\r\\\\n7 6 3 13 8 11 1 14 15 10 12 9 2 5 4 \\\\r\\\\n10 14 15 8 4 7 11 9 5 13 2 1 12 3 6 \\\\r\\\\n11 4 2 1 6 10 3 12 7 15 9 5 8 13 14 \\\\r\\\\n10 1 13 2 5 8 14 15 6 4 9 3 7 12 11 \\\\r\\\\n6 8 13 11 14 1 12 7 2 10 3 5 4 9 15 \\\\r\\\\n4 2 5 6 7 9 3 8 11 12 1 13 14 10 15 \\\\r\\\\n13 9 8 15 14 5 3 7 11 6 10 1 2 4 12 \\\\r\\\\n2 12 7 14 5 9 8 4 10 1 11 6 15 3 13 \\\\r\\\\n7 14 5 11 4 6 9 2 15 12 1 10 13 3 8 \\\\r\\\\n2 14 5 7 1 8 4 10 15 13 6 12 3 9 11 \\\\r\\\\n3 9 8 1 12 7 5 6 4 13 10 11 14 15 2 \\\\r\\\\n10 6 11 3 5 15 9 2 4 7 14 8 1 12 13 \\\\r\\\\n2 12 11 14 15 13 6 3 9 10 1 8 4 7 5 \\\\r\\\\n5 8 15 3 7 2 4 13 12 9 1 11 6 10 14 \\\\r\\\\n10 1 11 15 14 12 7 8 5 6 9 13 2 4 3 \\\\r\\\\n3 10 12 14 15 9 5 7 2 1 6 11 13 4 8 \\\\r\\\\n2 9 1 12 7 15 4 5 14 6 8 13 3 11 10 \\\\r\\\\n14 15 3 5 10 4 13 7 6 11 2 12 8 9 1 \\\\r\\\\n7 12 9 1 6 3 15 10 8 5 4 11 14 13 2 \\\\r\\\\n10 1 6 11 3 15 12 4 2 8 13 14 5 7 9 \\\\r\\\\n2 4 11 12 14 5 15 7 1 3 9 8 13 10 6 \\\\r\\\\n9 7 11 8 15 6 12 14 5 3 1 10 2 4 13 \\\\r\\\\n14 8 10 3 12 15 11 4 7 1 9 5 2 13 6 \\\\r\\\\n7 9 1 15 10 11 2 13 14 5 4 6 8 12 3 \\\\r\\\\n8 4 9 15 1 7 5 11 2 10 12 13 3 14 6 \\\\r\\\\n13 2 10 7 11 6 5 15 12 4 9 8 1 14 3 \\\\r\\\\n1 8 2 4 14 5 6 7 10 9 12 15 3 11 13 \\\\r\\\\n4 10 14 3 5 8 9 13 6 2 12 1 7 11 15 \\\\r\\\\n13 10 14 5 3 8 1 15 2 4 9 12 11 6 7 \\\\r\\\\n14 15 9 12 5 13 3 6 8 7 10 11 2 4 1 \\\\r\\\\n6 13 8 9 12 7 10 3 4 2 15 1 5 11 14 \\\\r\\\\n9 15 1 4 5 13 10 8 7 12 3 6 14 11 2 \\\\r\\\\n6 8 2 12 7 13 10 3 9 4 15 5 1 11 14 \\\\r\\\\n9 4 8 6 10 7 5 14 2 3 1 12 15 11 13 \\\\r\\\\n3 13 4 1 6 5 8 2 12 14 7 11 15 9 10 \\\\r\\\\n11 10 9 14 3 6 2 5 15 4 1 7 13 8 12 \\\\r\\\\n7 4 14 10 11 8 13 1 2 6 5 12 9 15 3 \\\\r\\\\n9 15 10 11 4 6 14 8 7 3 5 1 2 13 12 \\\\r\\\\n7 12 15 5 8 3 2 9 6 4 10 14 1 11 13 \\\\r\\\\n8 11 10 13 15 4 9 7 2 12 3 14 1 5 6 \\\\r\\\\n12 4 11 14 1 2 9 8 7 5 6 13 10 3 15 \\\\r\\\\n13 8 15 4 12 5 6 3 9 14 7 2 10 1 11 \\\\r\\\\n2 12 7 10 1 3 9 6 4 5 14 15 11 13 8 \\\\r\\\\n8 14 4 6 10 5 3 1 15 12 9 13 7 11 2 \\\\r\\\\n9 1 2 7 15 4 12 6 3 8 13 10 11 5 14 \\\\r\\\\n9 3 6 8 5 14 13 10 4 12 15 7 11 2 1 \\\\r\\\\n2 7 11 3 8 14 6 12 15 13 5 10 4 1 9 \\\\r\\\\n13 11 6 14 7 4 15 3 1 5 10 9 2 8 12 \\\\r\\\\n5 12 2 14 8 4 9 1 13 3 7 11 15 10 6 \\\\r\\\\n7 2 11 5 6 1 10 15 8 14 4 9 13 12 3 \\\\r\\\\n6 3 2 15 10 14 7 1 8 4 9 13 11 5 12 \\\\r\\\\n5 7 14 10 12 9 13 2 11 1 6 15 8 3 4 \\\\r\\\\n8 10 9 2 15 4 3 5 11 7 14 6 1 13 12 \\\\r\\\\n9 13 7 10 8 15 3 1 12 5 6 14 4 11 2 \\\\r\\\\n1 2 5 4 10 7 6 12 8 13 9 15 11 3 14 \\\\r\\\\n11 13 4 8 1 6 9 7 3 12 14 10 15 2 5 \\\\r\\\\n10 3 9 14 2 15 8 5 7 12 6 1 4 13 11 \\\\r\\\\n12 11 2 6 5 13 14 4 10 3 8 1 7 9 15 \\\\r\\\\n8 10 7 12 15 1 11 9 6 3 14 4 2 13 5 \\\\r\\\\n6 14 2 12 4 8 9 1 11 13 7 10 15 5 3 \\\\r\\\\n8 12 9 11 3 6 14 13 10 5 7 2 1 4 15 \\\\r\\\\n8 10 9 2 5 1 15 3 6 14 7 4 12 11 13 \\\\r\\\\n2 14 3 9 4 1 12 15 7 8 10 13 11 5 6 \\\\r\\\\n3 9 2 1 12 13 6 5 10 14 15 11 4 7 8 \\\\r\\\\n3 9 1 12 5 2 15 13 8 7 6 11 4 14 10 \\\\r\\\\n11 15 1 6 8 12 13 14 7 4 3 9 10 2 5 \\\\r\\\\n11 15 3 4 6 1 7 10 13 12 8 9 2 5 14 \\\\r\\\\n7 2 6 15 4 3 14 13 10 5 12 9 11 1 8 \\\\r\\\\n7 3 12 15 2 4 11 14 6 8 1 13 10 5 9 \\\\r\\\\n11 5 2 14 9 1 8 4 7 10 13 12 6 3 15 \\\\r\\\\n3 11 10 13 8 5 6 2 1 12 15 7 9 14 4 \\\\r\\\\n10 5 6 14 4 13 3 8 9 2 1 12 7 11 15 \\\\r\\\\n14 13 8 2 9 3 7 11 6 10 12 5 15 1 4 \\\\r\\\\n9 3 2 12 14 1 15 8 4 6 13 7 11 5 10 \\\\r\\\\n10 3 15 2 6 8 9 1 11 12 13 14 7 5 4 \\\\r\\\\n10 8 11 6 7 3 9 5 1 2 14 4 15 13 12 \\\\r\\\\n5 1 4 2 10 11 13 8 15 3 12 9 14 6 7 \\\\r\\\\n13 10 6 14 15 8 4 5 12 1 11 7 3 9 2 \\\\r\\\\n6 11 5 15 9 3 10 1 2 7 8 14 13 12 4 \\\\r\\\\n10 14 2 7 15 6 1 11 4 13 8 12 5 3 9 \\\\r\\\\n4 5 12 7 14 9 15 8 13 3 6 10 1 11 2 \\\\r\\\\n1 5 4 2 14 7 13 15 8 12 6 10 3 9 11 \\\\r\\\\n15 9 3 10 14 6 13 4 8 11 7 12 5 1 2 \\\\r\\\\n14 15 5 4 12 9 6 1 13 10 7 11 2 8 3 \\\\r\\\\n12 6 7 9 3 1 13 5 2 4 15 10 11 14 8 \\\\r\\\\n13 14 1 5 12 11 6 8 15 2 9 10 4 3 7 \\\\r\\\\n3 12 6 9 4 15 14 7 2 1 11 13 8 10 5 \\\\r\\\\n8 10 5 15 9 6 11 7 14 12 3 13 4 2 1 \\\\r\\\\n1 2 10 11 14 5 9 15 8 13 3 12 6 7 4 \\\\r\\\\n10 5 12 9 15 11 1 13 7 2 8 3 4 6 14 \\\\r\\\\n1 12 14 5 11 7 15 3 8 10 6 4 13 2 9 \\\\r\\\\n13 5 4 8 12 3 14 15 1 9 6 2 11 7 10 \\\\r\\\\n5 14 11 8 6 1 15 2 4 3 12 10 9 13 7 \\\\r\\\\n6 12 3 15 8 14 11 1 4 13 5 2 10 9 7 \\\\r\\\\n9 13 3 5 8 14 12 4 7 6 1 15 11 10 2 \\\\r\\\\n1 14 2 15 7 3 6 5 13 11 8 4 9 10 12 \\\\r\\\\n10 1 9 4 14 11 7 3 5 8 2 6 13 12 15 \\\\r\\\\n13 3 14 5 1 15 7 10 6 4 8 12 2 9 11 \\\\r\\\\n8 1 15 4 10 14 7 2 11 13 9 12 6 3 5 \\\\r\\\\n10 5 12 6 11 14 15 13 2 8 9 1 4 7 3 \\\\r\\\\n11 3 2 5 13 15 9 4 1 12 14 8 10 7 6 \\\\r\\\\n3 11 7 2 1 14 6 8 12 15 9 13 4 10 5 \\\\r\\\\n4 7 12 11 2 6 10 8 14 3 15 13 1 9 5 \\\\r\\\\n6 5 2 12 4 11 9 13 1 7 10 8 14 15 3 \\\\r\\\\n13 11 14 15 3 10 7 12 8 1 9 5 2 6 4 \\\\r\\\\n11 1 15 13 3 7 5 9 8 12 6 2 14 4 10 \\\\r\\\\n2 14 10 15 8 12 3 11 9 7 1 6 13 5 4 \\\\r\\\\n15 2 6 7 3 5 10 14 9 11 1 4 8 12 13 \\\\r\\\\n8 5 1 9 13 10 12 14 6 2 3 15 4 11 7 \\\\r\\\\n3 11 6 13 7 1 5 15 14 12 10 4 9 2 8 \\\\r\\\\n1 6 11 8 3 15 9 10 4 2 13 5 12 7 14 \\\\r\\\\n4 9 3 15 6 10 2 12 7 11 1 8 14 5 13 \\\\r\\\\n13 9 4 2 8 3 14 11 12 15 1 6 5 7 10 \\\\r\\\\n3 9 15 6 4 5 13 2 10 11 1 8 14 12 7 \\\\r\\\\n10 4 8 15 11 3 5 9 6 12 7 14 2 13 1 \\\\r\\\\n8 1 9 15 11 13 6 2 7 5 12 4 14 3 10 \\\\r\\\\n15 3 7 11 1 14 8 13 5 10 2 12 9 6 4 \\\\r\\\\n9 3 13 4 14 2 10 12 6 15 8 7 11 1 5 \\\\r\\\\n5 1 15 10 7 13 12 4 9 11 14 3 2 8 6 \\\\r\\\\n14 1 13 10 8 6 5 3 2 11 9 15 4 7 12 \\\\r\\\\n9 8 6 10 5 1 15 12 7 14 3 13 2 4 11 \\\\r\\\\n11 8 5 12 13 6 4 2 15 10 7 14 1 9 3 \\\\r\\\\n13 14 1 11 5 15 9 10 3 7 2 8 4 6 12 \\\\r\\\\n1 8 15 12 14 11 10 3 5 2 6 9 7 4 13 \\\\r\\\\n10 11 12 4 15 8 2 3 7 13 14 6 5 1 9 \\\\r\\\\n13 6 3 4 8 5 9 12 10 2 11 15 7 14 1 \\\\r\\\\n4 1 12 14 11 9 6 8 10 13 15 7 5 3 2 \\\\r\\\\n4 1 13 9 11 2 5 15 12 10 7 14 3 6 8 \\\\r\\\\n15 11 9 13 2 5 12 7 3 4 10 14 8 6 1 \\\\r\\\\n8 12 15 7 4 13 9 11 5 3 14 2 1 10 6 \\\\r\\\\n11 5 1 2 15 14 6 8 13 9 3 4 12 7 10 \\\\r\\\\n11 2 15 1 5 3 8 9 4 7 6 14 10 13 12 \\\\r\\\\n4 1 6 14 2 13 11 8 10 5 3 7 12 9 15 \\\\r\\\\n9 10 14 15 11 6 3 1 5 13 7 8 2 4 12 \\\\r\\\\n7 12 8 14 6 5 4 2 3 11 13 1 15 10 9 \\\\r\\\\n2 9 14 11 4 1 6 12 8 3 5 15 10 13 7 \\\\r\\\\n6 1 15 5 13 9 7 8 14 3 4 10 11 2 12 \\\\r\\\\n5 12 13 8 4 10 9 15 2 7 11 14 6 3 1 \\\\r\\\\n14 9 10 11 15 1 5 8 6 4 3 12 2 7 13 \\\\r\\\\n10 11 7 8 4 3 9 14 5 6 15 13 2 12 1 \\\\r\\\\n14 12 3 9 1 4 7 6 10 8 2 11 5 13 15 \\\\r\\\\n1 13 5 7 14 10 15 3 9 2 8 12 11 4 6 \\\\r\\\\n1 15 10 14 6 3 7 5 9 11 8 2 12 4 13 \\\\r\\\\n5 1 4 8 11 7 3 15 12 14 13 6 2 10 9 \\\\r\\\\n1 3 4 15 14 9 13 10 2 11 6 8 12 7 5 \\\\r\\\\n5 7 2 4 9 8 12 11 10 6 15 14 3 1 13 \\\\r\\\\n10 13 2 1 14 12 11 6 9 8 3 5 7 15 4 \\\\r\\\\n14 4 7 5 9 8 2 6 3 1 13 15 12 10 11 \\\\r\\\\n10 6 13 3 9 15 14 4 12 1 11 5 8 7 2 \\\\r\\\\n12 11 7 8 4 3 6 5 1 2 14 15 9 13 10 \\\\r\\\\n13 10 14 15 9 3 4 5 11 2 12 1 7 6 8 \\\\r\\\\n7 5 1 9 14 11 4 10 12 8 13 3 15 6 2 \\\\r\\\\n1 3 4 5 2 7 8 10 14 11 9 12 13 6 15 \\\\r\\\\n9 4 6 11 14 15 5 12 8 13 3 7 1 10 2 \\\\r\\\\n14 8 3 11 10 7 2 15 9 1 5 12 6 13 4 \\\\r\\\\n6 8 13 10 4 15 1 9 3 5 12 2 14 7 11 \\\\r\\\\n5 13 9 7 15 10 8 11 6 2 12 14 1 3 4 \\\\r\\\\n12 4 14 1 11 13 3 10 8 15 9 2 7 6 5 \\\\r\\\\n4 8 2 11 5 14 6 1 10 13 9 12 7 3 15 \\\\r\\\\n12 5 3 1 6 9 14 11 7 15 4 2 8 10 13 \\\\r\\\\n6 11 15 5 1 13 12 2 8 7 4 9 10 3 14 \\\\r\\\\n7 8 3 5 13 12 15 11 6 9 14 2 4 1 10 \\\\r\\\\n3 6 8 5 2 14 13 9 4 1 12 15 10 11 7 \\\\r\\\\n7 13 15 9 4 11 2 10 8 14 5 6 3 12 1 \\\\r\\\\n6 5 10 13 9 11 15 14 4 7 3 2 8 1 12 \\\\r\\\\n8 6 2 14 10 5 9 12 11 7 13 3 1 15 4 \\\\r\\\\n11 1 2 15 10 13 7 5 14 9 6 8 12 3 4 \\\\r\\\\n1 15 4 11 10 8 12 13 6 3 7 2 14 9 5 \\\\r\\\\n6 10 9 1 7 14 15 8 4 2 13 5 11 12 3 \\\\r\\\\n7 2 1 6 5 9 4 11 10 12 14 15 13 3 8 \\\\r\\\\n12 1 2 5 9 15 8 11 13 6 10 3 14 7 4 \\\\r\\\\n2 4 8 14 3 1 13 11 10 15 12 6 5 7 9 \\\\r\\\\n11 9 5 10 7 8 3 4 6 1 2 12 14 15 13 \\\\r\\\\n5 9 13 3 15 4 6 1 2 8 10 14 12 11 7 \\\\r\\\\n4 5 9 8 6 3 13 12 11 14 15 10 1 7 2 \\\\r\\\\n11 14 2 13 6 7 3 12 5 9 10 8 15 1 4 \\\\r\\\\n10 11 3 1 8 15 5 7 12 13 9 6 14 4 2 \\\\r\\\\n4 6 8 3 2 13 10 12 7 5 14 15 1 9 11 \\\\r\\\\n5 13 12 15 11 2 7 10 3 8 9 4 14 1 6 \\\\r\\\\n4 6 8 11 12 13 10 9 7 2 3 5 15 14 1 \\\\r\\\\n2 1 9 7 5 13 4 15 12 6 8 3 10 14 11 \\\\r\\\\n11 14 7 8 10 6 15 9 1 5 4 13 3 2 12 \\\\r\\\\n8 13 14 12 9 4 11 15 3 1 2 7 5 10 6 \\\\r\\\\n2 14 15 1 9 7 10 11 6 8 5 13 12 3 4 \\\\r\\\\n7 4 3 15 12 11 14 13 2 10 6 9 5 8 1 \\\\r\\\\n9 10 2 5 3 8 11 13 1 4 15 12 7 14 6 \\\\r\\\\n12 8 2 15 6 5 10 14 9 4 13 11 3 1 7 \\\\r\\\\n12 14 15 8 2 5 4 11 7 10 6 9 1 13 3 \\\\r\\\\n14 15 6 9 13 7 8 10 11 5 12 1 3 4 2 \\\\r\\\\n12 1 11 4 8 7 10 6 9 3 2 14 13 5 15 \\\\r\\\\n4 3 2 10 9 11 1 5 12 15 7 14 6 8 13 \\\\r\\\\n12 14 9 6 1 7 15 10 3 11 2 4 5 8 13 \\\\r\\\\n14 12 3 7 6 11 5 1 10 4 9 2 13 15 8 \\\\r\\\\n2 7 12 13 8 9 14 3 1 11 6 4 15 5 10 \\\\r\\\\n1 5 6 14 11 7 3 8 2 9 10 4 15 13 12 \\\\r\\\\n2 6 4 9 1 11 8 14 13 15 5 7 12 10 3 \\\\r\\\\n15 8 6 5 13 7 2 10 12 11 1 3 4 9 14 \\\\r\\\\n13 2 4 7 11 8 9 15 3 10 5 14 12 6 1 \\\\r\\\\n14 3 1 2 4 13 12 11 6 10 9 8 15 7 5 \\\\r\\\\n9 3 10 5 15 6 12 11 7 8 2 4 1 14 13 \\\\r\\\\n4 3 9 6 12 10 14 15 8 2 13 1 7 11 5 \\\\r\\\\n4 1 5 13 2 11 7 3 6 15 9 8 14 12 10 \\\\r\\\\n10 15 11 2 1 7 4 13 14 5 6 3 8 9 12 \\\\r\\\\n10 2 11 5 1 6 15 7 8 9 12 14 4 3 13 \\\\r\\\\n13 3 4 11 8 6 1 9 14 7 15 10 12 2 5 \\\\r\\\\n6 11 8 5 4 13 12 7 3 2 14 9 10 1 15 \\\\r\\\\n13 8 9 11 1 12 10 4 14 15 6 3 7 2 5 \\\\r\\\\n1 8 5 14 3 11 9 2 15 10 12 6 4 13 7 \\\\r\\\\n4 5 14 2 13 12 10 8 3 7 11 1 9 15 6 \\\\r\\\\n12 3 6 8 9 5 10 2 4 11 15 13 7 1 14 \\\\r\\\\n5 9 1 15 6 12 4 10 3 8 7 14 11 2 13 \\\\r\\\\n8 14 11 12 7 2 10 15 5 3 1 4 13 9 6 \\\\r\\\\n14 12 15 9 10 1 4 8 13 2 7 5 6 3 11 \\\\r\\\\n1 7 3 13 15 12 6 8 9 5 11 2 4 10 14 \\\\r\\\\n14 2 7 4 12 10 6 1 5 3 13 9 8 15 11 \\\\r\\\\n6 10 9 11 14 7 13 3 2 15 5 8 12 1 4 \\\\r\\\\n4 9 3 5 8 15 11 6 12 2 10 1 7 14 13 \\\\r\\\\n8 13 3 4 12 15 1 11 5 7 6 9 10 14 2 \\\\r\\\\n9 6 15 5 14 11 4 2 12 10 1 3 8 13 7 \\\\r\\\\n10 4 8 12 6 3 11 2 1 13 9 5 14 15 7 \\\\r\\\\n9 14 4 2 10 7 15 8 3 13 12 11 6 5 1 \\\\r\\\\n8 13 15 1 9 6 10 14 12 2 3 4 5 11 7 \\\\r\\\\n13 1 15 4 2 12 7 10 6 5 14 3 8 11 9 \\\\r\\\\n8 3 7 6 4 14 11 15 1 5 2 9 10 12 13 \\\\r\\\\n13 10 11 5 15 3 1 12 7 2 6 14 4 8 9 \\\\r\\\\n7 9 15 8 13 6 2 3 12 4 14 11 1 5 10 \\\\r\\\\n12 10 9 15 2 5 4 14 1 3 6 8 7 13 11 \\\\r\\\\n7 8 10 11 14 4 13 6 15 9 2 12 1 3 5 \\\\r\\\\n14 13 12 3 5 15 8 6 10 11 7 4 1 2 9 \\\\r\\\\n4 12 13 15 5 10 7 9 1 2 11 3 8 6 14 \\\\r\\\\n4 7 12 14 1 15 5 11 8 6 9 10 2 3 13 \\\\r\\\\n8 15 14 4 6 11 5 7 13 2 9 1 10 3 12 \\\\r\\\\n7 2 4 14 15 6 10 9 8 3 1 5 12 13 11 \\\\r\\\\n5 1 9 11 3 14 4 10 8 2 13 6 7 15 12 \\\\r\\\\n4 9 12 3 15 11 2 5 14 8 13 7 1 6 10 \\\\r\\\\n2 4 3 13 14 1 5 11 10 7 8 6 12 15 9 \\\\r\\\\n10 4 7 6 9 14 11 5 13 15 12 1 8 3 2 \\\\r\\\\n7 1 11 2 8 15 13 3 12 9 6 10 14 4 5 \\\\r\\\\n14 8 5 11 6 9 12 13 10 4 15 2 1 7 3 \\\\r\\\\n6 13 14 12 1 15 9 7 5 3 11 10 8 4 2 \\\\r\\\\n8 15 10 5 14 2 4 12 13 1 11 9 7 6 3 \\\\r\\\\n14 7 11 13 3 8 9 2 4 15 5 1 10 12 6 \\\\r\\\\n7 4 13 8 5 12 2 15 9 11 6 10 14 1 3 \\\\r\\\\n11 14 6 3 8 2 4 12 7 13 5 1 10 15 9 \\\\r\\\\n10 8 5 11 12 4 15 9 1 14 2 13 7 6 3 \\\\r\\\\n11 3 7 15 8 9 1 14 2 12 5 6 13 4 10 \\\\r\\\\n14 12 15 11 10 9 5 4 2 6 3 7 8 1 13 \\\\r\\\\n3 5 2 15 8 9 10 6 13 12 1 14 4 7 11 \\\\r\\\\n2 10 5 3 7 15 9 8 12 11 4 6 14 13 1 \\\\r\\\\n12 9 5 15 8 6 14 13 2 1 3 10 11 4 7 \\\\r\\\\n15 11 13 8 9 2 3 7 6 10 1 14 4 5 12 \\\\r\\\\n14 5 9 1 15 4 8 10 13 12 6 7 3 2 11 \\\\r\\\\n14 1 5 2 15 13 4 8 6 7 3 10 9 12 11 \\\\r\\\\n2 10 3 11 15 7 9 14 12 6 4 1 13 8 5 \\\\r\\\\n2 4 3 1 14 12 5 13 10 9 11 8 15 7 6 \\\\r\\\\n11 9 3 12 10 2 13 14 4 7 8 1 5 6 15 \\\\r\\\\n15 6 12 11 10 13 7 5 2 8 4 14 1 9 3 \\\\r\\\\n3 7 10 11 8 2 1 9 14 12 5 13 15 6 4 \\\\r\\\\n7 15 14 4 8 1 3 9 13 6 2 10 12 11 5 \\\\r\\\\n5 12 6 11 13 8 2 10 4 7 1 14 9 3 15 \\\\r\\\\n8 11 12 3 7 6 9 10 2 14 5 1 13 4 15 \\\\r\\\\n9 12 2 1 6 8 10 14 5 3 15 13 7 4 11 \\\\r\\\\n1 8 14 2 9 13 5 11 10 15 3 12 4 7 6 \\\\r\\\\n7 5 15 4 11 10 1 9 6 3 12 2 14 13 8 \\\\r\\\\n11 4 10 13 2 3 14 7 1 5 12 6 15 9 8 \\\\r\\\\n8 13 10 3 11 12 2 15 6 1 7 4 9 5 14 \\\\r\\\\n8 1 5 4 12 14 13 3 11 10 9 2 15 7 6 \\\\r\\\\n2 11 14 6 4 8 9 1 12 5 13 7 10 3 15 \\\\r\\\\n11 1 9 6 12 8 3 10 14 4 7 13 15 2 5 \\\\r\\\\n11 12 10 14 2 13 1 3 6 7 9 4 8 5 15 \\\\r\\\\n11 13 10 15 14 5 3 6 12 8 7 4 9 1 2 \\\\r\\\\n1 6 11 14 4 5 8 9 15 2 10 12 13 7 3 \\\\r\\\\n15 7 11 8 12 14 9 13 6 3 2 5 4 10 1 \\\\r\\\\n10 3 12 4 11 13 6 14 7 5 9 1 8 2 15 \\\\r\\\\n1 10 3 8 5 6 13 12 4 14 7 15 2 9 11 \\\\r\\\\n2 5 12 15 9 13 3 14 8 10 7 1 6 11 4 \\\\r\\\\n13 4 6 9 2 8 11 1 12 15 10 7 14 3 5 \\\\r\\\\n13 14 8 1 10 6 5 9 3 12 11 15 4 2 7 \\\\r\\\\n15 9 4 1 7 11 13 12 2 10 6 3 14 8 5 \\\\r\\\\n4 3 2 6 14 1 13 8 9 11 7 5 15 12 10 \\\\r\\\\n4 8 11 3 2 6 7 12 14 1 10 15 9 13 5 \\\\r\\\\n11 2 15 10 5 9 4 3 13 7 8 6 12 14 1 \\\\r\\\\n6 3 5 8 2 1 7 9 12 11 13 15 10 4 14 \\\\r\\\\n10 9 4 8 15 5 12 6 7 3 14 11 1 2 13 \\\\r\\\\n7 4 5 2 10 15 11 1 12 8 6 9 14 3 13 \\\\r\\\\n13 4 11 9 6 3 5 15 7 10 1 8 12 14 2 \\\\r\\\\n5 14 12 4 6 1 7 10 8 13 11 3 9 2 15 \\\\r\\\\n6 1 13 3 10 12 9 11 14 4 7 15 5 8 2 \\\\r\\\\n11 6 15 14 2 13 3 5 7 8 9 12 4 10 1 \\\\r\\\\n14 9 2 8 3 13 4 10 6 12 1 5 11 15 7 \\\\r\\\\n6 7 5 9 2 4 15 14 3 12 13 10 1 8 11 \\\\r\\\\n8 3 7 9 14 5 12 13 11 2 6 1 4 10 15 \\\\r\\\\n8 11 9 10 4 7 1 14 3 6 5 2 12 15 13 \\\\r\\\\n6 14 12 2 8 7 13 10 1 5 11 3 4 9 15 \\\\r\\\\n4 13 8 3 9 2 11 1 14 6 5 12 15 7 10 \\\\r\\\\n3 13 5 6 15 8 1 11 4 12 14 7 9 2 10 \\\\r\\\\n11 7 15 8 9 14 1 6 3 12 5 10 2 13 4 \\\\r\\\\n4 10 2 8 1 12 6 3 9 14 7 15 11 5 13 \\\\r\\\\n12 10 8 15 1 9 14 11 6 3 4 2 5 13 7 \\\\r\\\\n14 12 9 11 7 13 4 15 8 2 6 1 3 10 5 \\\\r\\\\n5 13 8 11 10 6 12 9 7 14 15 2 3 1 4 \\\\r\\\\n10 5 7 11 1 9 3 14 8 6 12 4 2 15 13 \\\\r\\\\n2 12 15 1 3 7 4 14 6 11 5 10 8 9 13 \\\\r\\\\n14 11 12 8 3 9 2 10 5 1 4 7 15 13 6 \\\\r\\\\n2 4 15 9 8 6 10 5 3 11 12 1 14 7 13 \\\\r\\\\n14 10 2 7 5 15 12 3 1 6 13 8 9 4 11 \\\\r\\\\n1 8 11 6 10 14 5 15 13 9 7 4 12 3 2 \\\\r\\\\n1 5 10 8 9 13 15 6 11 14 4 2 3 12 7 \\\\r\\\\n1 11 10 15 13 4 2 9 5 7 8 3 6 14 12 \\\\r\\\\n10 6 7 15 1 11 13 3 4 12 14 2 8 9 5 \\\\r\\\\n9 6 15 14 12 10 2 7 11 3 5 1 4 13 8 \\\\r\\\\n13 5 8 9 15 4 1 14 2 10 11 3 7 12 6 \\\\r\\\\n13 2 4 5 3 11 15 8 14 7 9 10 12 6 1 \\\\r\\\\n15 2 11 13 1 6 5 8 4 10 9 7 14 12 3 \\\\r\\\\n12 14 9 10 4 7 6 8 13 15 2 1 11 3 5 \\\\r\\\\n13 11 6 4 1 5 14 15 7 9 2 3 12 10 8 \\\\r\\\\n4 9 3 6 11 2 5 1 12 13 14 8 10 7 15 \\\\r\\\\n15 1 10 2 13 12 7 5 6 8 14 11 4 9 3 \\\\r\\\\n12 4 14 5 1 8 6 2 11 3 9 7 15 13 10 \\\\r\\\\n7 12 1 4 11 10 8 9 3 6 15 5 2 13 14 \\\\r\\\\n3 10 6 13 2 15 4 7 12 5 9 1 14 8 11 \\\\r\\\\n4 3 13 8 6 11 10 12 2 1 14 7 15 5 9 \\\\r\\\\n7 2 10 15 11 1 13 4 3 6 12 9 5 8 14 \\\\r\\\\n15 14 10 8 3 11 6 1 9 2 7 5 12 4 13 \\\\r\\\\n6 1 2 11 3 15 4 14 12 8 9 10 5 7 13 \\\\r\\\\n14 1 11 9 15 2 12 7 13 8 3 10 5 6 4 \\\\r\\\\n4 10 3 9 5 2 12 15 6 11 7 14 13 8 1 \\\\r\\\\n4 9 14 8 3 12 13 7 15 5 2 11 1 10 6 \\\\r\\\\n3 7 12 10 4 15 2 8 13 14 6 9 1 11 5 \\\\r\\\\n11 13 6 15 3 2 4 1 8 7 14 12 10 9 5 \\\\r\\\\n3 13 8 9 4 5 10 1 6 7 2 12 11 15 14 \\\\r\\\\n2 14 3 1 6 5 13 11 10 15 4 12 7 8 9 \\\\r\\\\n2 8 11 4 7 6 3 12 5 1 9 13 10 15 14 \\\\r\\\\n14 2 10 9 11 3 5 8 13 4 12 15 7 6 1 \\\\r\\\\n13 2 7 9 15 11 5 4 12 1 10 6 8 3 14 \\\\r\\\\n10 15 3 2 6 13 7 14 1 8 11 4 5 12 9 \\\\r\\\\n6 5 1 13 7 12 11 8 4 3 14 2 15 9 10 \\\\r\\\\n1 11 3 4 9 6 8 10 13 2 12 7 15 5 14 \\\\r\\\\n14 10 5 6 13 15 4 7 3 2 1 11 12 9 8 \\\\r\\\\n4 5 11 13 9 6 12 1 7 8 10 3 15 14 2 \\\\r\\\\n14 8 11 4 6 13 7 1 2 5 10 9 3 12 15 \\\\r\\\\n1 14 12 10 3 13 4 7 9 8 5 15 6 11 2 \\\\r\\\\n15 4 8 12 7 9 11 13 3 2 10 14 6 1 5 \\\\r\\\\n4 12 7 15 2 11 5 1 9 10 3 14 6 13 8 \\\\r\\\\n6 7 5 1 13 11 10 15 2 4 12 3 14 8 9 \\\\r\\\\n2 4 9 13 1 6 10 15 3 7 14 11 8 5 12 \\\\r\\\\n3 6 12 1 8 4 5 2 14 10 15 7 11 9 13 \\\\r\\\\n12 5 14 7 10 3 13 1 4 8 11 9 6 15 2 \\\\r\\\\n7 3 13 10 15 14 12 11 8 6 9 2 1 5 4 \\\\r\\\\n1 13 11 5 14 4 9 6 8 15 10 12 3 2 7 \\\\r\\\\n3 10 5 14 9 13 7 8 6 1 15 12 4 11 2 \\\\r\\\\n11 1 14 9 4 13 3 12 7 5 6 10 8 2 15 \\\\r\\\\n7 10 6 4 14 12 11 5 15 9 8 3 2 13 1 \\\\r\\\\n1 8 4 12 11 2 14 9 13 5 15 7 6 10 3 \\\\r\\\\n2 4 3 9 14 11 5 7 12 1 6 8 13 10 15 \\\\r\\\\n7 2 10 9 4 11 8 12 5 6 15 1 14 13 3 \\\\r\\\\n9 11 4 1 5 10 13 15 8 7 2 12 3 14 6 \\\\r\\\\n2 8 13 7 9 3 14 15 5 11 6 12 4 1 10 \\\\r\\\\n11 4 1 2 6 14 7 10 5 12 8 9 13 15 3 \\\\r\\\\n3 11 4 5 2 1 7 12 14 15 9 8 6 13 10 \\\\r\\\\n14 1 3 7 12 5 6 9 13 15 4 10 8 11 2 \\\\r\\\\n14 3 13 5 7 15 4 2 8 9 6 12 10 11 1 \\\\r\\\\n15 11 5 7 14 9 2 8 6 13 12 4 10 3 1 \\\\r\\\\n5 12 8 2 1 10 7 11 14 13 6 3 4 9 15 \\\\r\\\\n1 8 2 7 5 6 3 9 14 15 13 10 12 11 4 \\\\r\\\\n8 10 15 5 4 11 2 12 13 14 6 3 7 1 9 \\\\r\\\\n11 5 13 12 2 10 8 1 7 3 15 6 9 14 4 \\\\r\\\\n4 6 8 9 3 13 10 2 12 1 5 7 15 14 11 \\\\r\\\\n14 5 1 11 13 4 3 15 12 6 9 7 2 8 10 \\\\r\\\\n7 2 11 5 15 6 12 3 4 1 13 10 8 14 9 \\\\r\\\\n5 12 11 4 13 2 10 6 3 7 14 15 8 1 9 \\\\r\\\\n13 10 9 3 4 8 1 5 11 14 2 12 7 6 15 \\\\r\\\\n3 2 11 6 13 4 14 7 15 8 9 10 1 12 5 \\\\r\\\\n12 15 3 6 2 13 14 11 5 10 8 1 4 7 9 \\\\r\\\\n7 13 11 10 1 6 5 12 9 2 15 4 14 8 3 \\\\r\\\\n15 10 9 8 7 12 5 1 14 11 3 2 4 6 13 \\\\r\\\\n15 2 9 11 6 4 3 13 1 8 5 10 12 7 14 \\\\r\\\\n3 5 2 4 9 8 6 12 10 1 15 7 11 13 14 \\\\r\\\\n4 5 7 8 6 15 14 10 1 12 11 2 9 3 13 \\\\r\\\\n3 10 7 13 9 11 14 15 8 2 4 1 12 5 6 \\\\r\\\\n2 15 4 6 5 9 7 3 11 8 10 12 13 1 14 \\\\r\\\\n5 1 12 6 11 9 8 13 4 2 7 10 14 15 3 \\\\r\\\\n10 11 5 3 9 4 8 15 7 2 1 14 6 12 13 \\\\r\\\\n5 15 11 4 12 1 10 14 13 2 9 3 8 7 6 \\\\r\\\\n10 1 4 8 12 14 6 13 3 5 11 9 15 2 7 \\\\r\\\\n3 5 12 10 11 8 14 9 13 6 15 1 2 4 7 \\\\r\\\\n1 9 15 14 2 12 3 13 7 5 11 4 10 8 6 \\\\r\\\\n4 6 1 8 15 14 5 13 3 12 10 9 11 7 2 \\\\r\\\\n2 6 14 9 4 15 10 8 1 11 3 5 7 13 12 \\\\r\\\\n14 11 7 15 10 5 4 8 2 12 9 1 6 13 3 \\\\r\\\\n13 14 4 1 6 2 15 11 9 3 12 7 10 8 5 \\\\r\\\\n2 13 11 10 5 6 4 7 12 1 8 3 9 14 15 \\\\r\\\\n3 4 2 12 8 10 6 14 5 13 15 1 7 9 11 \\\\r\\\\n6 8 10 5 1 9 2 13 11 7 15 14 3 4 12 \\\\r\\\\n1 6 10 12 15 11 3 8 7 9 13 14 4 5 2 \\\\r\\\\n13 9 1 12 5 15 4 2 11 3 10 14 6 8 7 \\\\r\\\\n11 8 14 6 3 1 7 2 9 15 5 12 13 4 10 \\\\r\\\\n5 4 13 10 8 14 1 15 9 12 6 7 3 2 11 \\\\r\\\\n9 15 8 2 7 14 12 3 6 10 5 13 1 11 4 \\\\r\\\\n2 8 13 9 1 6 3 14 7 12 11 15 10 5 4 \\\\r\\\\n7 10 3 12 9 5 15 14 4 11 13 2 8 6 1 \\\\r\\\\n6 2 7 12 1 13 14 11 9 10 15 5 4 3 8 \\\\r\\\\n1 10 8 4 13 12 6 2 7 15 14 3 9 11 5 \\\\r\\\\n13 15 1 9 7 11 10 4 6 14 8 2 5 3 12 \\\\r\\\\n3 6 8 11 15 14 13 4 12 1 9 7 5 10 2 \\\\r\\\\n12 14 7 10 5 13 2 8 11 6 15 4 1 3 9 \\\\r\\\\n11 10 12 3 4 1 5 14 2 6 15 8 7 9 13 \\\\r\\\\n12 6 10 5 4 7 3 2 9 13 8 1 14 11 15 \\\\r\\\\n8 6 7 10 4 13 5 15 11 3 14 12 9 1 2 \\\\r\\\\n8 3 10 7 15 2 14 6 13 11 12 1 4 5 9 \\\\r\\\\n7 14 10 4 6 12 2 9 13 5 1 3 8 11 15 \\\\r\\\\n3 1 7 14 15 9 11 6 12 5 2 10 8 13 4 \\\\r\\\\n6 14 4 8 10 15 3 1 9 13 7 2 5 12 11 \\\\r\\\\n2 6 5 10 13 12 8 14 4 15 11 3 1 9 7 \\\\r\\\\n12 14 3 15 13 6 9 11 8 1 10 5 4 2 7 \\\\r\\\\n14 2 3 6 10 13 4 15 7 8 9 12 5 1 11 \\\\r\\\\n12 11 9 8 10 15 5 6 4 3 7 1 13 2 14 \\\\r\\\\n15 8 1 4 12 3 9 11 10 7 5 13 14 6 2 \\\\r\\\\n1 5 12 3 15 2 7 9 13 8 4 14 10 6 11 \\\\r\\\\n4 8 1 9 10 14 11 6 2 13 15 7 12 5 3 \\\\r\\\\n10 14 12 15 6 9 2 8 3 13 7 5 1 11 4 \\\\r\\\\n1 2 15 10 3 6 11 4 12 14 8 5 7 9 13 \\\\r\\\\n12 3 6 11 2 4 9 7 14 8 15 10 5 13 1 \\\\r\\\\n10 1 9 13 8 2 3 12 14 15 4 7 6 11 5 \\\\r\\\\n5 14 15 12 3 10 1 6 4 13 7 9 11 8 2 \\\\r\\\\n1 14 6 2 10 4 15 3 8 13 7 11 5 12 9 \\\\r\\\\n8 4 5 11 2 10 13 15 12 7 1 3 14 9 6 \\\\r\\\\n7 6 8 5 4 3 13 11 1 10 12 14 9 15 2 \\\\r\\\\n14 4 7 6 9 11 5 13 10 15 1 12 3 2 8 \\\\r\\\\n7 2 13 5 1 3 6 8 14 11 15 9 10 4 12 \\\\r\\\\n9 15 14 6 3 1 8 11 2 13 5 12 7 10 4 \\\\r\\\\n13 6 10 8 15 11 12 2 4 7 14 9 3 1 5 \\\\r\\\\n5 10 14 11 6 12 2 15 13 1 8 3 4 9 7 \\\\r\\\\n4 15 10 11 9 1 3 12 5 6 2 8 13 14 7 \\\\r\\\\n6 4 13 11 5 1 8 14 7 3 15 12 10 2 9 \\\\r\\\\n11 4 7 6 12 1 14 3 13 8 15 2 10 9 5 \\\\r\\\\n14 8 13 3 5 10 11 9 15 4 6 7 12 2 1 \\\\r\\\\n8 15 3 2 4 11 10 6 1 12 13 7 5 9 14 \\\\r\\\\n3 9 11 14 4 10 8 5 6 15 13 7 12 1 2 \\\\r\\\\n5 3 9 2 15 13 8 11 12 10 1 4 14 7 6 \\\\r\\\\n12 8 3 15 14 9 4 6 11 10 2 5 1 13 7 \\\\r\\\\n2 1 9 10 4 8 3 15 14 6 11 5 13 12 7 \\\\r\\\\n\\"}\\n]\\n", "source_code": "\\n// NOTE: The actual exam will not use Websheets (instead, the PA submit system).\\n// It''s recommended to practice and test on your own machine and copy here to check.\\n \\\\[\\n\\n/****************************************************************************\\n* Solution for Hats Part 1\\n*\\n* Read in list size and permutations of that size.\\n* Determine if each is a \\"derangement\\". \\n* Print out the first derangement if it exists.\\n* Print out the number of derangements.\\n*****************************************************************************/\\n\\n#include <iostream>\\nusing namespace std;\\n\\n// print the first derangement with the given format\\nvoid printD(int r[], int length) {\\n cout << \\"First derangement:\\";\\n for (int i = 0; i < length; i++)\\n cout << \\" \\" << r[i];\\n cout << endl;\\n}\\n \\n// return true if r holds a derangement, false otherwise\\nbool isD(int r[], int length) {\\n for (int i = 0; i < length; i++) {\\n if (r[i] == i+1) //i+1 to account for C++ 0-based arrays\\n return false;\\n }\\n return true;\\n}\\n\\nint main() {\\n // the # of items in permutation\\n int N;\\n cin >> N;\\n\\n // space to hold permutation\\n int arr[100];\\n\\n // how many derangements have we seen?\\n int count = 0; \\n \\n // Read until there are no more permutations left on StdIn.\\n while (!cin.fail()) {\\n // fill array\\n for (int i = 0; i < N; i++)\\n cin >> arr[i];\\n\\n if (!cin.fail()) {\\n\\n // if arr is a derangement, count i\\n // and print it if it''s the first.\\n if (isD(arr, N)) { \\n if (count == 0) \\n printD(arr, N); \\n count++; \\n }\\n }\\n }\\n cout << \\"Number of derangements: \\" << count << endl;;\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(257, '[email protected]', 'cpp/vectors/examples/vector_eg', '{"sharing": "open", "attempts_until_ref": "1", "description": "An example of vectors.", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <string>\\n#include <vector>\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n vector<string> words; // CONSTRUCT\\n words.push_back(\\"Hello\\"); // ADD to back end\\n words.push_back(\\"World\\"); \\n cout << words.size() << endl; // get SIZE\\n cout << words[0] << \\" \\" << words.at(1) << endl; // [i], at(): ACCESS\\n \\n vector<int> nums(10); // CONSTRUCT with initial size 10\\n // or use: vector<int> nums; nums.resize(10);\\n for (int i=0; i<10; i++)\\n nums[i] = i*i; // assign\\n cout << nums.back() << endl; // ACCESS from back end\\n nums.pop_back(); // DELETE (pop) from back end\\n \\n // FYI: iterator-type iteration (stay tuned in CS 104) \\n // but... it is more straightforward to use a normal for loop with size()\\n for (vector<int>::iterator it=nums.begin(); it != nums.end(); it++)\\n cout << *it << \\" \\";\\n\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(258, '[email protected]', 'cpp/vectors/matrix', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefining vectors-of-vectors with a given size.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <vector>\\n#include <iostream>\\nusing namespace std;\\n\\nvoid print_matrix(vector<vector<int> > M) {\\n for (int r=0; r<\\\\[M.size()]\\\\; r++) {\\n for (int c=0; c<\\\\[M[0].size()]\\\\; c++) {\\n cout << M[r][c] << \\" \\";\\n }\\n cout << endl;\\n }\\n}\\n\\nint main() {\\n // create a 3-by-3 matrix of zeros\\n vector<vector<int> > nine_zeros(3, vector<int>(3, 0));\\n // create a 2 row, 4 column matrix of ones\\n vector<vector<int> > two_by_four\\\\[(2, vector<int>(4, 1))]\\\\;\\n\\n print_matrix(nine_zeros);\\n cout << endl;\\n print_matrix(two_by_four);\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(259, '[email protected]', 'cpp/vectors/vector_fill_cons', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nUsing the vector fill constructor.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <vector>\\n#include <iostream>\\nusing namespace std;\\n\\nvoid print_vector(vector<int> v) {\\n for (int i=0; i<\\\\[v.size()]\\\\; i++) {\\n cout << v[i] << \\" \\";\\n }\\n cout << endl;\\n}\\n\\nint main() {\\n // create the phone number 8 8 8 8 8 8 8 8 8 8\\n vector<int> phone_number(10, 8);\\n // create the zip code 9 9 9 9 9\\n vector<int> zip_code(\\\\[5, 9]\\\\);\\n\\n print_vector(phone_number);\\n print_vector(zip_code);\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(260, '[email protected]', 'cpp/vectors/middle', '{"attempts_until_ref": "1", "sharing": "open", "description": "Define a function <tt>middle</tt> that takes\\na <tt>vector<string></tt>; it should \\nreturn the middle string. (You can assume the length is odd.)\\n<p>See the test <tt>main</tt> for an example of calling it.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <vector>\\n#include <iostream>\\nusing namespace std;\\n\\nstring middle(\\\\[vector<string>]\\\\ v) {\\n\\\\[\\n return v[v.size()/2]; // rounds down\\n]\\\\\\n}\\n\\nint main() {\\n vector<string> words;\\n words.push_back(\\"Doc\\");\\n cout << middle(words) << endl; // Doc\\n words.push_back(\\"Grumpy\\");\\n words.push_back(\\"Happy\\");\\n cout << middle(words) << endl; // Grumpy\\n words.push_back(\\"Sleepy\\");\\n words.push_back(\\"Bashful\\");\\n cout << middle(words) << endl; // Happy\\n words.push_back(\\"Sneezy\\");\\n words.push_back(\\"Dopey\\");\\n cout << middle(words) << endl; // Sleepy\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(261, '[email protected]', 'cpp/vectors/vector_test', '{"attempts_until_ref": "1", "sharing": "open", "description": "Fill in the blanks with appropriate code to implement\\nthe directions given in the comments.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <vector>\\n\\nusing namespace std;\\n\\nvoid print_list(vector<int> &myvec)\\n{\\n // declare an i counter\\n \\\\[int ]\\\\ i;\\n // complete the for loop and its body\\n for(\\\\[ i=0 ]\\\\ ; \\\\[ i < myvec.size() ]\\\\; i++ ){\\n cout << \\\\[ myvec[i] ]\\\\ << \\" \\";\\n }\\n cout << endl;\\n}\\n\\n\\nint main(int argc, char *argv[])\\n{\\n vector<int> lst;\\n\\n cout << \\"Added 1, 2, 3, and 9 to list 1\\" << endl;\\n // add code to put 1, 2, 3, and 9 into the vector in that order\\n \\\\[\\n lst.push_back(1);\\n lst.push_back(2);\\n lst.push_back(3);\\n lst.push_back(9);\\n ]\\\\\\n\\n print_list( lst );\\n\\n // print out the number of items (list size) in the list\\n cout << \\\\[ lst.size() ]\\\\ << endl;\\n\\n\\n\\n // print out the front item\\n cout << \\\\[ lst.front() ]\\\\ << endl;\\n\\n // delete the item at index 1 in the lines of code after the cout\\n cout << \\"Removing second item (i.e. at index 1): \\" << endl;\\n \\n \\\\[\\n lst.erase(lst.begin()+1);\\n ]\\\\\\n\\n // will print the resulting list\\n print_list( lst );\\n\\n // add code to put 120, 121, 122 onto the front of the list \\n // so that 120 is at location 0, 121 at location 1, etc.\\n // use the insert() method after the cout line below\\n cout << \\"Adding 120, 121, 122\\" << endl;\\n\\n \\\\[\\n lst.insert(lst.begin(), 120);\\n lst.insert(lst.begin()+1, 121);\\n lst.insert(lst.begin()+2, 122);\\n\\n ]\\\\\\n\\n\\n\\n print_list( lst );\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(262, '[email protected]', 'cpp/vectors/concat', '{"attempts_until_ref": "1", "sharing": "open", "description": "Define a function <tt>concat</tt> that takes\\ntwo <tt>vector<int></tt> objects; it should \\nreturn the concatenation of them\\ninto a single vector. See <tt>main</tt> for an example.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <vector>\\n#include <iostream>\\nusing namespace std;\\n\\n// print out contents of vector, with a space after each one\\nvoid print_vec(vector<int> V) {\\n for (int i=0; i<\\\\[V.size()]\\\\; i++) \\n cout << V[i] << \\" \\";\\n cout << endl;\\n}\\n\\n\\\\[\\nvector<int> concat(vector<int> A, vector<int> B) {\\n vector<int> result;\\n for (int i=0; i<A.size(); i++)\\n result.push_back(A[i]);\\n for (int i=0; i<B.size(); i++)\\n result.push_back(B[i]);\\n return result;\\n}\\n]\\\\\\n\\nint main() {\\n // primes is 2 3 5\\n vector<int> primes;\\n primes.push_back(2); primes.push_back(3); primes.push_back(5);\\n\\n // squares is 0 1 4 9 16\\n vector<int> squares;\\n squares.resize(5);\\n for (int i=0; i<5; i++) squares[i] = i*i;\\n\\n print_vec(concat(primes, squares)); // 2 3 5 0 1 4 9 16\\n print_vec(concat(squares, primes)); // 0 1 4 9 16 2 3 5\\n vector<int> primes_twice = concat(primes, primes);\\n print_vec(concat(primes_twice, primes_twice)); // primes 4 times\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(263, '[email protected]', 'cpp/vectors/parity_counts', '{"attempts_until_ref": "1", "sharing": "open", "description": "Define a function <tt>parity_counts</tt> that takes\\none <tt>vector<int></tt> objects as input.\\nIt should return a vector containing two ints: the first counting\\nhow many inputs were even, the second counting how many were odd.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <vector>\\n#include <iostream>\\nusing namespace std;\\n\\n\\\\[\\nvector<int> parity_counts(vector<int> nums) {\\n int evens = 0;\\n int odds = 0;\\n for (int i=0; i<nums.size(); i++) {\\n if (nums[i]%2==0)\\n evens++;\\n else\\n odds++;\\n }\\n vector<int> result;\\n result.push_back(evens);\\n result.push_back(odds);\\n return result;\\n}\\n]\\\\\\n\\n// print out contents of vector, with a space after each one\\n\\\\hide[\\nvoid print_vec(vector<int> V) {\\n for (int i=0; i<V.size(); i++) \\n cout << V[i] << \\" \\";\\n cout << endl;\\n}\\n]\\\\\\n\\\\fake[\\nvoid print_vec(vector<int> V); // see concat exercise\\n]\\\\\\n\\nint main() {\\n // primes is 2 3 5\\n vector<int> primes;\\n primes.push_back(2); primes.push_back(3); primes.push_back(5);\\n print_vec(parity_counts(primes));\\n\\n // squares is 0 1 4 9 16\\n vector<int> squares;\\n squares.resize(5);\\n for (int i=0; i<5; i++) squares[i] = i*i;\\n print_vec(parity_counts(squares));\\n\\n vector<int> empty_vector;\\n print_vec(parity_counts(empty_vector));\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(264, '[email protected]', 'cpp/vectors/rpn', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\n<i>Postfix notation</i> transforms mathematical expressions by putting \\neach operator <i>after</i> its arguments. So <tt>1 + 2</tt> becomes \\n<tt>1 2 +</tt> and <tt>5 * 2</tt> becomes <tt>5 2 *</tt>. \\n<p>An advantage\\nover normal (infix) expressions is that parentheses are not needed.\\nFor example <tt>4 3 * 2 1 * +</tt> is the prefix version of <tt>4*3+2*1</tt>\\nwhile <tt>4 3 2 + * 1 *</tt> is the prefix version of <tt>4*(3+2)*1</tt>.\\n<p>Write an evaluator for prefix notation (just the <tt>*</tt> and <tt>+</tt>\\noperators) by using a vector as a stack.\\nEach time you read a number, place it at the end of the stack. Each time\\nyou read an operator, combine the last two elements of the stack.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"1 2 +\\"},\\n {\\"stdin\\": \\"5 2 *\\"},\\n {\\"stdin\\": \\"4 3 * 2 1 * +\\"},\\n {\\"stdin\\": \\"4 3 2 + * 1 *\\"},\\n {\\"stdin\\": \\"5 4 3 2 1 * * * *\\"},\\n {\\"stdin\\": \\"5 4 3 2 1 + + + +\\"},\\n {\\"stdin\\": \\"1 2 + 3 4 * 5 6 + 7 8 + 9 * + + *\\"}\\n]\\n", "source_code": "\\n#include <vector>\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\nint main() {\\n vector<int> memory;\\n string input;\\n // read each input\\n while (cin >> input) {\\n // if you read an operator, combine the last two elements of the stack\\n if (input == \\"+\\" || input == \\"*\\") {\\n\\\\[\\n int v1 = memory.back();\\n memory.pop_back();\\n int v2 = memory.back();\\n memory.pop_back();\\n]\\\\\\n if (input == \\"+\\")\\n \\\\[memory.push_back(v1+v2);]\\\\\\n else\\n \\\\[memory.push_back(v1*v2);]\\\\\\n }\\n // if you read a number, place it at the end of the stack\\n else {\\n memory.push_back(atoi(input.c_str()));\\n }\\n }\\n cout << memory.back();\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(265, '[email protected]', 'cpp/vectors/vv', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDeclare a vector of vectors. It is trying to create this matrix:\\n$$\\\\begin{bmatrix}1 & 5 \\\\\\\\ 2 & 8\\\\end{bmatrix}$$\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <vector>\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n // declare\\n\\\\[\\n vector<vector<int> > matrix;\\n\\\\show:\\n vector<vector<int>> matrix;\\n]\\\\\\n\\n // fill in\\n vector<int> row1;\\n row1.push_back(1);\\n row1.push_back(5);\\n vector<int> row2;\\n row2.push_back(2);\\n row2.push_back(8);\\n matrix.push_back(row1);\\n matrix.push_back(row2);\\n\\n // print out\\n for (int r=0; r<2; r++) {\\n for (int c=0; c<2; c++) {\\n // print out entry at row r, column c\\n cout << matrix\\\\[[r][c]]\\\\ << \\" \\";\\n }\\n cout << endl;\\n }\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(266, '[email protected]', 'cpp/misc/badsum', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWhat is the source of the bug?\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std; // access cout and endl\\n\\nint main() {\\n int sum;\\n\\\\hide[\\n sum = -234767;\\n]\\\\ \\n\\\\[\\n sum = 0;\\n for (int i=1; i<=100; i++) {\\n sum += i;\\n }\\n cout << sum;\\n\\\\show:\\n for (int i=1; i<=100; i++) {\\n sum += i;\\n }\\n cout << sum;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(267, '[email protected]', 'cpp/misc/const', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nShowing a usage of <tt>const</tt>.\\n", "cppflags_remove": "[\\"-Wno-write-strings\\"]", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid println(\\\\[const char*\\\\show:char*]\\\\ text) {\\n cout << text << endl;\\n}\\n\\nint main() {\\n println(\\"Hello!\\");\\n}\\n", "tests": "[\\n {}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:05', 'save', 'open'),
(268, '[email protected]', 'cpp/linkedlists/monkey_delend', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a member function <tt>string delEnd()</tt>\\nthat deletes the last item in the list, and returns the\\n<tt>string</tt> it contained (its <tt>name</tt>).\\n<p>If the list is empty, return an empty string (<tt>\\"\\"</tt>).\\n<p>Remember to deallocate the item removed from the list!\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n\\\\hide[\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll();\\n void addStart(string newName);\\n bool isEmpty();\\n int size();\\n string delEnd();\\n private: \\n Node* first;\\n};\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// we''ll provide a working copy of printAll for you \\nvoid MonkeyChain::printAll() {\\n // one possible approach: use a while loop\\n Node* current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != NULL) {\\n // print current node''s name; then repeat loop w/next one\\n cout << current->name << endl;\\n current = current->next;\\n }\\n}\\n\\n// add a new node, containing this name, at the start of the list\\nvoid MonkeyChain::addStart(string newName) {\\n Node* newFirst = new Node(newName);\\n Node* oldFirst = first;\\n first = newFirst;\\n first->next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n}\\n\\n// add a new node, containing this name, at the start of the list\\nbool MonkeyChain::isEmpty() {\\n return first == NULL;\\n}\\n\\n\\nint MonkeyChain::size() {\\n int count = 0;\\n Node* loc = first;\\n while (loc != NULL) {\\n count++;\\n loc = loc->next;\\n }\\n return count;\\n}\\n]\\\\\\n\\nstring MonkeyChain::delEnd() {\\n\\\\[\\n if (first == NULL) \\n return \\"\\";\\n else if (first->next == NULL) {\\n string result = first->name;\\n delete first;\\n first = NULL;\\n return result;\\n }\\n else {\\n Node* curr = first;\\n // find node holding the last node\\n while (curr->next->next != NULL)\\n curr = curr->next;\\n string result = curr->next->name;\\n delete curr->next;\\n curr->next = NULL;\\n return result;\\n } \\n]\\\\\\n}\\n\\nint main() {\\n MonkeyChain mc;\\n mc.threeKongs();\\n mc.addStart(\\"Bubbles\\");\\n cout << \\"Deleted: \\" << mc.delEnd() << endl;\\n mc.printAll(); cout << endl;\\n cout << \\"Deleted: \\" << mc.delEnd() << endl;\\n mc.printAll(); cout << endl;\\n cout << \\"Deleted: \\" << mc.delEnd() << endl;\\n cout << boolalpha << mc.isEmpty() << endl;\\n mc.printAll(); cout << endl;\\n cout << \\"Deleted: \\" << mc.delEnd() << endl;\\n cout << boolalpha << mc.isEmpty() << endl;\\n\\n // deleting from empty should do nothing:\\n cout << \\"Deleted: \\" << mc.delEnd() << endl;\\n cout << boolalpha << mc.isEmpty() << endl;\\n\\n // test your deallocation\\n for (int i=0; i<1000000; i++) {\\n mc.addStart(\\"A\\");\\n mc.addStart(\\"B\\");\\n mc.delEnd();\\n mc.delEnd();\\n }\\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(269, '[email protected]', 'cpp/linkedlists/monkey_size', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a member function <tt>int size()</tt>\\nthat tells the user how many items are in the list.\\n<p>Of course, you could do this by adding and maintaining a data member, \\nbut for this exercise, you''re not allowed to do this.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n\\\\hide[\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll();\\n void addStart(string newName);\\n bool isEmpty();\\n int size();\\n private: \\n Node* first;\\n};\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// we''ll provide a working copy of printAll for you \\nvoid MonkeyChain::printAll() {\\n // one possible approach: use a while loop\\n Node* current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != NULL) {\\n // print current node''s name; then repeat loop w/next one\\n cout << current->name << endl;\\n current = current->next;\\n }\\n}\\n\\n// add a new node, containing this name, at the start of the list\\nvoid MonkeyChain::addStart(string newName) {\\n Node* newFirst = new Node(newName);\\n Node* oldFirst = first;\\n first = newFirst;\\n first->next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n}\\n\\n// add a new node, containing this name, at the start of the list\\nbool MonkeyChain::isEmpty() {\\n return first == NULL;\\n}\\n\\n]\\\\\\nint MonkeyChain::size() {\\n\\\\[\\n int count = 0;\\n Node* loc = first;\\n while (loc != NULL) {\\n count++;\\n loc = loc->next;\\n }\\n return count;\\n]\\\\\\n}\\n\\nint main() {\\n MonkeyChain mc;\\n cout << mc.size() << endl;\\n mc.addStart(\\"King Kong\\");\\n cout << mc.size() << endl;\\n mc.addStart(\\"Bubbles\\");\\n cout << mc.size() << endl;\\n for (int i=0; i<10; i++) // add 10 monkeys\\n mc.addStart(\\"Another Monkey\\");\\n cout << mc.size() << endl;\\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(270, '[email protected]', 'cpp/linkedlists/monkey_delsearch', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a member function <tt>bool delSearch(string target)</tt>\\nthat searches for the target string in the list.\\n<br>If it finds this item, it should delete it and return <tt>true</tt>.\\n<br>If it it not found, return <tt>false</tt> and don''t alter the list.\\n<br>You can assume the item occurs at most once in the list.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n\\\\hide[\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll();\\n void addStart(string newName);\\n bool isEmpty();\\n int size();\\n string delEnd();\\n bool delSearch(string target);\\n private: \\n Node* first;\\n};\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// we''ll provide a working copy of printAll for you \\nvoid MonkeyChain::printAll() {\\n // one possible approach: use a while loop\\n Node* current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != NULL) {\\n // print current node''s name; then repeat loop w/next one\\n cout << current->name << endl;\\n current = current->next;\\n }\\n}\\n\\n// add a new node, containing this name, at the start of the list\\nvoid MonkeyChain::addStart(string newName) {\\n Node* newFirst = new Node(newName);\\n Node* oldFirst = first;\\n first = newFirst;\\n first->next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n}\\n\\n// add a new node, containing this name, at the start of the list\\nbool MonkeyChain::isEmpty() {\\n return first == NULL;\\n}\\n\\n\\nint MonkeyChain::size() {\\n int count = 0;\\n Node* loc = first;\\n while (loc != NULL) {\\n count++;\\n loc = loc->next;\\n }\\n return count;\\n}\\n]\\\\\\nbool MonkeyChain::delSearch(string target) {\\n\\\\[\\n if (isEmpty()) \\n return false;\\n else if (first->name == target) {\\n Node* oldFirst = first;\\n first = first->next;\\n delete oldFirst;\\n return true;\\n }\\n else {\\n // advance curr until curr->next is thing to delete\\n // why? then curr is the Node that must change\\n Node* curr = first;\\n // stop when we find it or curr->next doesn''t exist\\n while (curr->next != NULL \\n && curr->next->name != target)\\n curr = curr->next;\\n\\n if (curr->next == NULL)\\n return false; // not found\\n else {\\n Node* oldNode = curr->next;\\n curr->next = curr->next->next;\\n delete oldNode;\\n return true;\\n }\\n } \\n]\\\\\\n}\\n\\nint main() {\\n MonkeyChain mc;\\n mc.threeKongs();\\n mc.addStart(\\"Bubbles\\");\\n mc.addStart(\\"King Kong\\");\\n // list: KK, Bubbles, DK Sr, DK, DK Jr\\n cout << boolalpha;\\n\\n cout << \\"Deleted Diddy? \\" << mc.delSearch(\\"Diddy\\") << endl;\\n mc.printAll(); cout << endl;\\n\\n cout << \\"Deleted DK? \\" << mc.delSearch(\\"DK\\") << endl;\\n mc.printAll(); cout << endl;\\n\\n cout << \\"Deleted King Kong? \\" << mc.delSearch(\\"King Kong\\") << endl;\\n mc.printAll(); cout << endl;\\n\\n cout << \\"Deleted DK Jr? \\" << mc.delSearch(\\"DK Jr.\\") << endl;\\n mc.printAll(); cout << endl;\\n\\n cout << \\"Deleted DK Sr? \\" << mc.delSearch(\\"DK Sr.\\") << endl;\\n mc.printAll(); cout << endl;\\n\\n cout << \\"Deleted Bubbles? \\" << mc.delSearch(\\"Bubbles\\") << endl;\\n mc.printAll(); cout << endl;\\n\\n // test your deallocation\\n for (int i=0; i<500000; i++) {\\n mc.addStart(\\"A\\");\\n mc.addStart(\\"B\\");\\n mc.addStart(\\"C\\");\\n mc.delSearch(\\"A\\");\\n mc.delSearch(\\"D\\");\\n mc.delSearch(\\"C\\");\\n mc.delSearch(\\"B\\");\\n }\\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(271, '[email protected]', 'cpp/linkedlists/monkey_addstart', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a method <tt>addStart(string newName)</tt>\\nthat adds a new Node, containing this name,\\nat the start of the list.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll();\\n void addStart(string newName); // NEW!\\n private: \\n Node* first;\\n};\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// we''ll provide a working copy of printAll for you \\nvoid MonkeyChain::printAll() // ... { method body not shown }\\n\\\\hide[\\n{\\n // one possible approach: use a while loop\\n Node* current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != NULL) {\\n // print current node''s name; then repeat loop w/next one\\n cout << current->name << endl;\\n current = current->next;\\n }\\n}\\n]\\\\\\n\\n// add a new node, containing this name, at the start of the list\\nvoid MonkeyChain::addStart(string newName) {\\n Node* newFirst = new Node(newName);\\n\\\\[\\n Node* oldFirst = first;\\n first = newFirst;\\n first->next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n]\\\\\\n}\\n\\n\\nint main() {\\n MonkeyChain mc;\\n mc.threeKongs();\\n mc.addStart(\\"King Kong\\");\\n mc.printAll(); cout << endl;\\n mc.addStart(\\"Bubbles\\");\\n mc.printAll(); cout << endl;\\n\\n mc = MonkeyChain(); // test 2: insert into empty list\\n mc.addStart(\\"Test 2 Monkey\\");\\n mc.printAll(); \\n // TO-DO: clean up memory\\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(272, '[email protected]', 'cpp/linkedlists/monkey_traverse', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a method <tt>printAll()</tt>\\nthat prints out all names in the list, one per line.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll();\\n private: \\n Node* first;\\n};\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\nvoid MonkeyChain::printAll() {\\n // one possible approach: use a while loop\\n Node* current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (\\\\[current != NULL]\\\\) {\\n // print current node''s name; then repeat loop w/next one\\n\\\\[\\n cout << current->name << endl;\\n current = current->next;\\n]\\\\\\n }\\n}\\n\\n\\nint main() {\\n MonkeyChain mc;\\n mc.threeKongs();\\n mc.printAll(); cout << endl;\\n // double-check\\n mc.printAll(); \\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(273, '[email protected]', 'cpp/linkedlists/monkey_addend', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a method <tt>addEnd(string newName)</tt>\\nthat adds a new Node, containing this name,\\nat the end of the list.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll();\\n void addEnd(string newName); // NEW!\\n private: \\n Node* first;\\n};\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// we''ll provide a working copy of printAll for you \\nvoid MonkeyChain::printAll() // ... { method body not shown }\\n\\\\hide[\\n{\\n // one possible approach: use a while loop\\n Node* current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != NULL) {\\n // print current node''s name; then repeat loop w/next one\\n cout << current->name << endl;\\n current = current->next;\\n }\\n}\\n]\\\\\\n\\n// add a new node, containing this name, at the end of the list\\nvoid MonkeyChain::addEnd(string newName) {\\n Node* newLast = new Node(newName);\\n\\n // loop like printAll(), but stop *just before* the end.\\n // then, add the new node\\n\\\\[\\n if (first == NULL) {\\n first = newLast;\\n }\\n else {\\n Node* current = first;\\n while (current->next != NULL) {\\n current = current->next;\\n }\\n current->next = newLast;\\n }\\n]\\\\\\n}\\n\\n\\nint main() {\\n MonkeyChain mc;\\n mc.threeKongs();\\n mc.addEnd(\\"King Kong\\");\\n mc.printAll(); cout << endl;\\n mc.addEnd(\\"Bubbles\\");\\n mc.printAll(); cout << endl;\\n\\n mc = MonkeyChain(); // test 2: insert into empty list\\n mc.addEnd(\\"Test 2 Monkey A\\");\\n mc.printAll(); cout << endl;\\n mc.addEnd(\\"Test 2 Monkey B\\");\\n mc.printAll(); \\n // TO-DO: clean up memory\\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(274, '[email protected]', 'cpp/linkedlists/monkey_delstart', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a member function <tt>string delStart()</tt>\\nthat deletes the first item in the list, and returns the\\n<tt>string</tt> it contained (its <tt>name</tt>).\\n<p>If the list is empty, return an empty string (<tt>\\"\\"</tt>).\\n<p>Remember to deallocate the item removed from the list!\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n\\\\hide[\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll();\\n void addStart(string newName);\\n bool isEmpty();\\n int size();\\n string delStart();\\n private: \\n Node* first;\\n};\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// we''ll provide a working copy of printAll for you \\nvoid MonkeyChain::printAll() {\\n // one possible approach: use a while loop\\n Node* current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != NULL) {\\n // print current node''s name; then repeat loop w/next one\\n cout << current->name << endl;\\n current = current->next;\\n }\\n}\\n\\n// add a new node, containing this name, at the start of the list\\nvoid MonkeyChain::addStart(string newName) {\\n Node* newFirst = new Node(newName);\\n Node* oldFirst = first;\\n first = newFirst;\\n first->next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n}\\n\\n// add a new node, containing this name, at the start of the list\\nbool MonkeyChain::isEmpty() {\\n return first == NULL;\\n}\\n\\n\\nint MonkeyChain::size() {\\n int count = 0;\\n Node* loc = first;\\n while (loc != NULL) {\\n count++;\\n loc = loc->next;\\n }\\n return count;\\n}\\n]\\\\\\n\\nstring MonkeyChain::delStart() {\\n // is it empty?\\n if (\\\\[first == NULL]\\\\) {\\n return \\"\\";\\n }\\n else {\\n\\\\[\\n string result = first->name;\\n Node* newFirst = first->next;\\n delete first;\\n first = newFirst;\\n return result;\\n]\\\\\\n } \\n}\\n\\nint main() {\\n MonkeyChain mc;\\n mc.threeKongs();\\n cout << \\"Deleted: \\" << mc.delStart() << endl;\\n mc.printAll(); cout << endl;\\n cout << \\"Deleted: \\" << mc.delStart() << endl;\\n mc.printAll(); cout << endl;\\n cout << \\"Deleted: \\" << mc.delStart() << endl;\\n cout << boolalpha << mc.isEmpty() << endl;\\n\\n // deleting from empty should do nothing:\\n cout << \\"Deleted: \\" << mc.delStart() << endl;\\n cout << boolalpha << mc.isEmpty() << endl;\\n\\n // test your deallocation\\n for (int i=0; i<1000000; i++) {\\n mc.addStart(\\"A\\");\\n mc.addStart(\\"B\\");\\n mc.delStart();\\n mc.delStart();\\n }\\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(275, '[email protected]', 'cpp/linkedlists/monkey_isempty', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a member function <tt>bool isEmpty()</tt>\\nthat tells the user whether the list is empty.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n\\\\hide[\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\n// structure of items in list\\nstruct Node {\\n Node* next; // each node knows \\"next\\" node\\n string name; // and stores a value\\n Node(string initialName); // constructor for nodes\\n};\\n\\nNode::Node(string initialName) {name = initialName; next = NULL;}\\n\\nclass MonkeyChain {\\n public:\\n MonkeyChain();\\n void threeKongs();\\n void printAll();\\n void addStart(string newName);\\n bool isEmpty();\\n private: \\n Node* first;\\n};\\n\\nMonkeyChain::MonkeyChain() {first = NULL;}\\n\\n// a demo to create a length-3 list\\nvoid MonkeyChain::threeKongs() {\\n first = new Node(\\"DK Sr.\\");\\n first->next = new Node(\\"DK\\");\\n first->next->next = new Node(\\"DK Jr.\\");\\n}\\n\\n// we''ll provide a working copy of printAll for you \\nvoid MonkeyChain::printAll() {\\n // one possible approach: use a while loop\\n Node* current = first; // start at beginning\\n\\n // if current isn''t past the last node,\\n while (current != NULL) {\\n // print current node''s name; then repeat loop w/next one\\n cout << current->name << endl;\\n current = current->next;\\n }\\n}\\n\\n// add a new node, containing this name, at the start of the list\\nvoid MonkeyChain::addStart(string newName) {\\n Node* newFirst = new Node(newName);\\n Node* oldFirst = first;\\n first = newFirst;\\n first->next = oldFirst;\\n // there''s also a slightly trickier 2-line solution\\n}\\n\\n]\\\\\\n// add a new node, containing this name, at the start of the list\\nbool MonkeyChain::isEmpty() {\\n\\\\[\\n return first == NULL;\\n]\\\\\\n}\\n\\n\\nint main() {\\n cout << boolalpha;\\n MonkeyChain mc;\\n cout << mc.isEmpty() << endl;\\n mc.addStart(\\"King Kong\\");\\n cout << mc.isEmpty() << endl;\\n mc.addStart(\\"Bubbles\\");\\n cout << mc.isEmpty() << endl;\\n}\\n\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(276, '[email protected]', 'cpp/datastruct/qmerge', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite code to sort a list of integers using merge sort. You will use the <tt>deque<int></tt> template type.\\n<ol>\\n<li>\\nCreate a function <tt>deque<int> merge(deque<int> a, deque<int> b)</tt> which, assuming\\n <tt>a</tt> and <tt>b</tt> are both deques sorted in increasing order, returns a new deque\\nconsisting of all their elements combined, sorted in increasing order. E.g., if <tt>a</tt> is a deque into which\\n1 and 9 have been inserted, and <tt>b</tt> is a deque into which 2 and 6 have been inserted, then the returned\\ndeque should contain 1 first, then 2, 6, 9. \\n</li>\\n<li>\\nThen, create a function <tt>deque<int> merge_sort(deque<int> input)</tt> to implement merge sort.\\nIt should use <tt>size()</tt> from the <tt>deque</tt> API to break the deque into two \\n(non-ordered) deques each about half as big as the original. Then sort both halves recursively, and merge them.\\n</li>\\n</ol>\\n You will also need to use \\n<tt>bool deque::empty()</tt> as well as <tt>push_back()</tt>, <tt>front()</tt> and <tt>pop_front()</tt>.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"9 1 6 2\\"},\\n {\\"stdin\\": \\"3 7 8 2 4 5 2 4 1\\"},\\n {\\"stdin\\": \\"29 48 72 90 53 31 81 8 12 71 9 42 46 76 36 59 75 7 18 74 67 40 98 30 63 11 24 91 64 6 75 26 95 26 79 43 2 65 21 9 28 46 29 8 23 72 78 28 12 51 32 70 80 25 95 27 26 41 62 80 6 1 60 97 83 64 30 33 42 33 41 46 9 24 96 12 71 56 11 42 25 22 53 92 83 62 44 43 63 58 16 28 69 20 20 70 65 53 93 33\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <deque>\\nusing namespace std;\\n\\n// ASSUMING a and b are sorted in increasing order, return a new queue\\n// consisting of the elements of both in combined increasing order\\ndeque<int> merge(deque<int> a, deque<int> b) {\\n deque<int> result;\\n\\n // keep going as long as there are elements to merge in BOTH\\n while (\\\\[!a.empty() && !b.empty()]\\\\) {\\n // take the smaller element from either a or b, move it to result\\n\\\\[\\n if (b.front() < a.front()) {\\n result.push_back(b.front());\\n b.pop_front();\\n}\\n else {\\n result.push_back(a.front());\\n a.pop_front();\\n}\\n]\\\\\\n }\\n\\n // if anything is left over once one queue is empty, move it into result\\n\\\\[\\n while (!a.empty()) {\\n result.push_back(a.front());\\n a.pop_front();\\n }\\n while (!b.empty()) {\\n result.push_back(b.front());\\n b.pop_front();\\n }\\n]\\\\\\n return result;\\n}\\n\\n// return a new queue consisting of the same elements in sorted order\\ndeque<int> merge_sort(deque<int> input) {\\n if (input.size() == 1) { // base case\\n\\\\[\\n return input;\\n]\\\\\\n }\\n else {\\n // move half the elements into a new queue\\n\\\\[\\n int halfSize = input.size() / 2; \\n deque<int> firstHalf;\\n for (int i=0; i<halfSize; i++) {\\n firstHalf.push_back(input.front());\\n input.pop_front();\\n }\\n]\\\\\\n // sort both halves and merge\\n return \\\\[merge(merge_sort(firstHalf), merge_sort(input))]\\\\;\\n }\\n}\\n\\n// read all integers from input, sort them, and print them\\nint main(int argc, char* argv[]) {\\n deque<int> data;\\n int value;\\n while (cin >> value)\\n data.push_back(value);\\n deque<int> sortedData = merge_sort(data);\\n while (!sortedData.empty()) {\\n cout << sortedData.front() << \\" \\";\\n sortedData.pop_front();\\n }\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(277, '[email protected]', 'cpp/datastruct/line_edit', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nCreate a class <tt>LineEdit</tt> to implement a text editor — a very primitive text editor that can only hold one line of text, \\nand supports the following functions.\\n<pre>\\n// create a new LineEdit with given initial text\\n LineEdit(string text)\\n// get the current state of the editor\\n string to_string()\\n// add the given text at the end of the line\\n void append(string text) \\n// change the ith character to ch (you can assume it exists)\\n void replace(int i, char ch)\\n// undo the latest append/replace operation that hasn''t already been undone\\n void undo()\\n</pre>\\nFor example,\\n<pre>\\nLineEdit line(\\"datatype\\"); // line.to_string() is now \\"datatype\\"\\nline.replace(4, ''h''); // line.to_string() is now \\"datahype\\"\\nline.append(\\"st\\"); // line.to_string() is now \\"datahypest\\"\\nline.undo(); // line.to_string() is now \\"datahype\\"\\n</pre>\\nThe main purpose of this exercise is to gain familiarity with stacks —\\nuse <tt>deque<string></tt> to implement the history of changes and to\\nimplement the <tt>undo()</tt> functionality. If the client\\n calls <tt>undo()</tt> and everything has already been undone, then \\n<tt>undo()</tt> should just return without changing the state.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <deque>\\n#include <iostream>\\nusing namespace std;\\n\\nclass LineEdit {\\npublic:\\n LineEdit(string text);\\n string to_string();\\n void append(string text);\\n void replace(int i, char ch);\\n void undo();\\nprivate:\\n// data members\\n\\\\[\\n string state; // current state\\n deque<string> oldStates; // previous states for undo\\n]\\\\\\n};\\n\\n// create a new LineEdit with given initial text\\nLineEdit::LineEdit(string text) {\\n\\\\[\\n state = text;\\n]\\\\\\n}\\n\\n// get the current state of the editor\\nstring LineEdit::to_string() {\\n\\\\[\\n return state;\\n]\\\\\\n}\\n\\n// add the given text at the end of the line\\nvoid LineEdit::append(string text) {\\n\\\\[\\n oldStates.push_back(state);\\n state = state + text;\\n]\\\\\\n}\\n\\n// change the ith character to ch (you can assume it exists)\\nvoid LineEdit::replace(int i, char ch) {\\n\\\\[\\n oldStates.push_back(state);\\n state[i] = ch;\\n]\\\\\\n}\\n\\n// undo the latest append/replaceEach operation that hasn''t already been undone\\nvoid LineEdit::undo() {\\n// hint: use deque::empty()\\n\\\\[\\n if (!oldStates.empty()) { // avoid crashing when there''s nothing to undo\\n state = oldStates.back();\\n oldStates.pop_back();\\n }\\n]\\\\\\n}\\n\\n// test client\\nint main() {\\n // test 1\\n LineEdit line(\\"datatype\\");\\n cout << line.to_string() << endl;\\n line.replace(4, ''h'');\\n cout << line.to_string() << endl;\\n line.append(\\"st\\");\\n cout << line.to_string() << endl;\\n line.undo();\\n cout << line.to_string() << endl;\\n cout << endl;\\n\\n // test 2\\n LineEdit word(\\"CSCI 103\\");\\n cout << word.to_string() << endl;\\n word.replace(7, ''4'');\\n cout << word.to_string() << endl;\\n word.replace(1, ''X'');\\n cout << word.to_string() << endl;\\n word.undo();\\n cout << word.to_string() << endl;\\n word.append(\\" is the best\\"); \\n cout << word.to_string() << endl;\\n word.undo();\\n cout << word.to_string() << endl;\\n word.undo();\\n cout << word.to_string() << endl;\\n word.undo(); // nothing to undo, but shouldn''t crash\\n cout << word.to_string() << endl;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(278, '[email protected]', 'cpp/sstreams/wordcount', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that takes any number of lines from input, \\nand counts the number of words per line, writing each number on a line \\nby itself. For example, for the input\\n<pre>\\nMeasuring programming progress\\nby lines of code\\nis like measuring aircraft building progress\\nby weight\\n</pre>\\nthe output should be\\n<pre>\\n3\\n4\\n6\\n2\\n</pre>\\nUse an <tt>istringstream</tt> with <tt>>></tt> to skip whitespace.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"Measuring programming progress\\\\nby lines of code\\\\nis like measuring aircraft building progress\\\\nby weight\\"},\\n {\\"stdin\\": \\"\\\\nThere are only two kinds of programming languages\\\\nthose people always gripe about\\\\nand those nobody uses\\\\n\\"},\\n {\\"stdin\\": \\"Weeks of programming can save you hours of planning\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\n#include <string>\\n#include <sstream>\\nusing namespace std;\\n\\nint main() {\\n string line;\\n // read each line\\n while (getline(cin, line)) {\\n // create istringstream from line\\n istringstream \\\\[storage(line)]\\\\;\\n // loop through storage with >>, counting words\\n\\\\[\\n string word;\\n int count = 0;\\n while (storage >> word) {\\n count++;\\n }\\n]\\\\\\n // print word count\\n cout << \\\\[count]\\\\ << endl;\\n }\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(279, '[email protected]', 'cpp/sstreams/examples/stringstream_out', '{"sharing": "open", "attempts_until_ref": "1", "description": "An example of ostringstreams.", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <string>\\n#include <vector>\\n#include <iostream>\\n#include <sstream>\\nusing namespace std;\\n\\nint main() {\\n // CONSTRUCTOR\\n ostringstream buf;\\n \\n // INSERT, part 1\\n buf << \\"Eating text and numbers: \\";\\n \\n // INSERT, part 2\\n for (int i=0; i<10; i++)\\n buf << i;\\n\\n // get CONTENTS: str() member function\\n cout << \\"Length \\" << buf.str().length() << endl;\\n cout << buf.str();\\n\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(280, '[email protected]', 'cpp/sstreams/date', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>date(string month, int day, int year)</tt>\\nthat returns a <tt>string</tt> combining the elements in this format:\\n<pre>October 6, 1880</pre>\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\n#include <string>\\n#include <sstream>\\nusing namespace std;\\n\\nstring date(string month, int day, int year) {\\n// return date in format like: October 6, 1880\\n\\\\[\\n ostringstream buf;\\n buf << month << \\" \\" << day << \\", \\" << year;\\n return buf.str();\\n]\\\\\\n}\\n\\nint main() {\\n string date1 = date(\\"December\\", 30, 1950);\\n cout << boolalpha;\\n cout << \\"date1 OK? \\" << (\\"December 30, 1950\\" == date1) << endl;\\n \\n cout << date(\\"July\\", 4, 1776) << endl;\\n cout << date(\\"October\\", 6, 1880) << endl;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(281, '[email protected]', 'cpp/sstreams/examples/stringstream_in', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nUsing an <tt>istringstream</ii>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <iomanip>\\n#include <string>\\n#include <sstream>\\nusing namespace std;\\n\\nint main() {\\n // CONSTRUCT from a string\\n istringstream storage(\\"Sample text 2parse\\");\\n\\n string word1, word2, word3;\\n int num;\\n\\n // EXTRACT from the stringstream\\n storage >> word1 >> word2 >> num >> word3;\\n\\n cout << \\"Word 1: \\" << word1 << endl;\\n cout << \\"Word 2: \\" << word2 << endl;\\n cout << \\"Number: \\" << num << endl;\\n cout << \\"Word 3: \\" << word3 << endl;\\n\\n // has a fail() member function like other istreams\\n cout << \\"Fail? \\" << boolalpha << storage.fail() << endl;\\n storage >> num; // try to read more\\n cout << \\"Fail now? \\" << storage.fail() << endl;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(282, '[email protected]', 'cpp/practice/triangle', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\n<p>Write a program <code>triangle</code> that takes three command-line \\narguments, representing the side lengths of a triangle.\\n\\n<p>First, you should check that the sides are actually possible. This means\\nthat\\n<ul>\\n<li>All three sides are positive\\n<li>Each side is shorter than the sum of the other two sides \\n(the <a href=\\"http://en.wikipedia.org/wiki/Triangle_inequality\\">triangle \\ninequality</a>)\\n</ul>\\nIf it''s not possible to build a triangle with those sides, \\nprint out <tt>impossible</tt> and nothing else.\\n\\nIf it''s possible to build a triangle with those sides, you\\nwill print out two facts about the triangle. \\n<ol>\\n<li>The first fact should be <tt>right</tt>, <tt>acute</tt>, or\\n<tt>obtuse</tt>. In a right triangle, the longest side squared equals\\nthe sum of the squares of the other two sides (the \\n<a href=\\"http://en.wikipedia.org/wiki/Pythagorean_theorem\\">Pythagorean\\ntheorem</a>).\\nIf the longest side''s square is larger than the sum of the\\nother two sides, the triangle is obtuse. If smaller, it''s called acute.\\n<li>The second fact should be <tt>equilateral</tt>, <tt>isoceles</tt>,\\nor <tt>scalene</tt>. In an equilateral triangle, all three sides are \\nequal. In an isoceles triangle, exactly two sides are equal. In a scalene\\ntriangle, all sides have different lengths.\\n</ol>\\n\\nFor example:\\n<ul>\\n<li><tt>triangle 10 10 10</tt> should print <tt>acute equilateral</tt>\\n<li><tt>triangle 3 4 5</tt> should print <tt>right scalene</tt>\\n<li><tt>triangle 100 60 60</tt> should print <tt>obtuse isoceles</tt>\\n<li><tt>triangle 100 40 40</tt> should print <tt>impossible</tt>\\n</ul>\\n\\nHighlight the following box if you need a hint.\\n<span style=''border:1px solid black; color: white''>\\nIt will simplify things if you start by creating variables\\nrepresenting the longest, shortest, and other side length.\\n</span>\\n", "lang": "C++", "tests": "[\\n {\\"args\\": [\\"10\\", \\"10\\", \\"10\\"]},\\n {\\"args\\": [\\"3\\", \\"4\\", \\"5\\"]},\\n {\\"args\\": [\\"100\\", \\"60\\", \\"60\\"]},\\n {\\"args\\": [\\"100\\", \\"40\\", \\"40\\"]},\\n {\\"args\\": [\\"100\\", \\"50\\", \\"50\\"]},\\n {\\"args\\": [\\"50\\", \\"40\\", \\"30\\"]},\\n {\\"args\\": [\\"5\\", \\"13\\", \\"12\\"]},\\n {\\"args\\": [\\"50\\", \\"30\\", \\"50\\"]},\\n {\\"args\\": [\\"30\\", \\"30\\", \\"50\\"]},\\n {\\"args\\": [\\"29\\", \\"30\\", \\"31\\"]},\\n {\\"args\\": [\\"2\\", \\"3\\", \\"4\\"]},\\n {\\"args\\": [\\"-2\\", \\"-3\\", \\"-4\\"]},\\n {\\"args\\": [\\"0\\", \\"0\\", \\"0\\"]},\\n {\\"args\\": [\\"25\\", \\"25\\", \\"35.3553390593273762\\"]}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\n#include <algorithm>\\nusing namespace std; \\n\\\\[\\nint main(int argc, char* argv[]) {\\n double A = atof(argv[1]);\\n double B = atof(argv[2]);\\n double C = atof(argv[3]);\\n\\n double smallest = min(A, min(B, C));\\n double largest = max(A, max(B, C));\\n double middle = A+B+C - smallest - largest;\\n\\n if (largest >= smallest + middle) {\\n cout << \\"impossible\\" << endl;\\n return 0;\\n }\\n\\n if (largest*largest == smallest*smallest + middle*middle) {\\n cout << \\"right\\";\\n }\\n else if (largest*largest > smallest*smallest + middle*middle) {\\n cout << \\"obtuse\\";\\n }\\n else {\\n cout << \\"acute\\";\\n }\\n\\n cout << \\" \\";\\n\\n if (largest == middle && middle == smallest) {\\n cout << \\"equilateral\\";\\n }\\n else if (largest == middle || middle == smallest) {\\n cout << \\"isoceles\\";\\n }\\n else {\\n cout << \\"scalene\\";\\n }\\n\\n cout << endl;\\n}\\n]\\\\\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(283, '[email protected]', 'cpp/practice/openclose', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nYou''re working with an intern that keeps coming to you with \\nC++ code that won''t run because the <tt>{</tt>braces<tt>}</tt>, \\n<tt>(</tt>brackets<tt>)</tt>, and <tt>(</tt>parentheses<tt>)</tt> \\nare off. To save you both some time, you decide \\nto write a braces/brackets/parentheses validator.\\n\\n<p>\\nWrite a function <tt>bracket_check</tt> that takes a <tt>string</tt>\\nand returns <tt>true</tt> if the braces/brackets/parentheses are matched,\\nand <tt>false</tt> otherwise. You can assume all other characters have\\nbeen deleted: the string can only contain some mix of <tt>()[]{}</tt>\\ncharacters (possibly multiple times).\\n\\n<p>E.g.: <tt>\\"{[]()}\\"</tt> and <tt>\\"[(())]\\"</tt> should return <tt>true</tt>,\\nand <tt>\\")(\\"</tt> and <tt>\\"(]\\"</tt> should return <tt>false</tt>.\\n\\n<p>You may assume that the string has length at most 100.\\n", "lang": "C++func", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std; \\n\\nbool bracket_check(string expr) {\\n\\\\[\\n // we''ll scan through the string in a single pass\\n // the strategy will be to remember how \\"deep\\" we''re nested\\n int depth = 0;\\n // and what kinds of brackets contain us, memory[0] being the outermost\\n char memory[100];\\n\\n for (int i=0; i<expr.length(); i++) {\\n if (expr[i] == ''('' || expr[i] == ''{'' || expr[i] == ''['') {\\n // remember entering this\\n depth++;\\n memory[depth-1] = expr[i];\\n }\\n else if (expr[i] == '')'' || expr[i] == ''}'' || expr[i] == '']'') {\\n // closer not matching any previous opener\\n if (depth == 0)\\n return false;\\n \\n // see if closer and opener have same style\\n char should_match = memory[depth-1];\\n depth--;\\n if (expr[i] == '')'' && should_match != ''('')\\n return false;\\n if (expr[i] == '']'' && should_match != ''['')\\n return false;\\n if (expr[i] == ''}'' && should_match != ''{'')\\n return false;\\n }\\n }\\n \\n // done scanning the string. we''d better be at level 0...\\n return (depth == 0);\\n]\\\\\\n}\\n", "tests": "[\\n [\\"check-function\\", \\"bracket_check\\", \\"bool\\", [\\"string\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"()()\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"(())\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"())(\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"((())\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([])\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"{}[]\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"{[}]\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([]{})\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([()][([[]][]){()}])\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([()][([[]][]}{()}])\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([(]][([[]][]){()}])\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([()][([[]][]){())])\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([()][([[]][]){()]])\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([()][([[)][]){()}])\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([()][([[]}[]){()}])\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([()][([[]][]){()}]))\\\\\\"\\"]],\\n [\\"call-function\\", \\"bracket_check\\", [\\"\\\\\\"([()][([[]][]){()}]\\\\\\"\\"]]\\n]\\n", "remarks": "\\nbased on this Creative Commons Att-SA 3.0 exercise:\\nhttps://cloudcoder.org/repo/exercise/6cdc568f0b5fac4c019de701dd849f4396d7670b\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(284, '[email protected]', 'cpp/practice/fizzbuzz', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\n<p>Write a program <code>fizzbuzz</code> that takes an integer command-line \\nargument <code>n</code> and prints an output. \\nDepending on the value of <code>n</code>, print a different output\\nbased on the following conditions:</p>\\n<ul>\\n<li>If the value is a multiple of 3: print the string <code>Fizz</code> instead</li>\\n<li>If the value is a multiple of 5: print the string <code>Buzz</code> instead</li>\\n<li>If the value is a multiple of 3 & 5: print the string <code>FizzBuzz</code> instead</li>\\n</ul>\\nFor instance,\\n<ul>\\n<li><code>fizzbuzz 3</code> should print <code>Fizz</code></li>\\n<li><code>fizzbuzz 5</code> should print <code>Buzz</code></li>\\n<li><code>fizzbuzz 17</code> should print <code>17</code></li>\\n<li><code>fuzzbuzz 30</code> should print <code>FizzBuzz</code></li>\\n", "lang": "C++", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std; \\n\\\\[\\nint main(int argc, char* argv[]) {\\n int N = atoi(argv[1]);\\n\\n if (N % 15 == 0) { \\n cout << \\"FizzBuzz\\" << endl;\\n }\\n else if (N % 5 == 0) {\\n cout << \\"Buzz\\" << endl;\\n }\\n else if (N % 3 == 0) {\\n cout << \\"Fizz\\" << endl;\\n }\\n else {\\n cout << N << endl;\\n }\\n\\n return 0; \\n}\\n]\\\\\\n", "tests": "[\\n {\\"args\\": [\\"1\\"]},\\n {\\"args\\": [\\"3\\"]},\\n {\\"args\\": [\\"5\\"]},\\n {\\"args\\": [\\"6\\"]},\\n {\\"args\\": [\\"7\\"]},\\n {\\"args\\": [\\"12\\"]},\\n {\\"args\\": [\\"15\\"]},\\n {\\"args\\": [\\"20\\"]},\\n {\\"args\\": [\\"60\\"]},\\n {\\"args\\": [\\"61\\"]},\\n {\\"args\\": [\\"119\\"]},\\n {\\"args\\": [\\"120\\"]}\\n]\\n", "remarks": "\\nbased on this Creative Commons Att-SA 3.0 exercise:\\nhttps://cloudcoder.org/repo/exercise/b9c7c88bd10dc887d8221a3e3554d053f6d3a30b\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(285, '[email protected]', 'cpp/practice/diamond', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that takes a command-line argument <tt>N</tt>\\nand draws a diamond of\\n<tt>''X''</tt> characters on a size-<tt>N</tt> grid of <tt>''-''</tt>\\ncharacters. For example <tt>diamond 5</tt> should print\\n<pre>\\n--X--\\n-XXX-\\nXXXXX\\n-XXX-\\n--X--\\n</pre>\\nand <tt>diamond 6</tt> should print\\n<pre>\\n--XX--\\n-XXXX-\\nXXXXXX\\nXXXXXX\\n-XXXX-\\n--XX--\\n</pre>\\n", "lang": "C++", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std; \\n\\\\[\\n\\n// print ch a total of n times\\nvoid reprint(char ch, int n) {\\n for (int i=0; i<n; i++) {\\n cout << ch;\\n }\\n}\\n\\nint main(int argc, char* argv[]) {\\n int n;\\n n = atoi(argv[1]);\\n\\n // draw the top half\\n for (int i=0; i<n/2; i++) {\\n // this counts the hyphens\\n int hyphens = n/2-i;\\n // but is off by one in the even case\\n if (n%2 == 0) hyphens--;\\n\\n reprint(''-'', hyphens);\\n reprint(''X'', n - 2*hyphens);\\n reprint(''-'', hyphens);\\n cout << endl;\\n }\\n\\n for (int i=n/2; i<n; i++) {\\n // this counts the hyphens\\n int hyphens = i-n/2;\\n\\n reprint(''-'', hyphens);\\n reprint(''X'', n - 2*hyphens);\\n reprint(''-'', hyphens);\\n cout << endl;\\n }\\n}\\n]\\\\\\n", "tests": "[\\n {\\"args\\": [\\"5\\"]},\\n {\\"args\\": [\\"6\\"]},\\n {\\"args\\": [\\"7\\"]},\\n {\\"args\\": [\\"8\\"]},\\n {\\"args\\": [\\"3\\"]},\\n {\\"args\\": [\\"2\\"]},\\n {\\"args\\": [\\"1\\"]},\\n {\\"args\\": [\\"0\\"]},\\n {\\"args\\": [\\"20\\"]},\\n {\\"args\\": [\\"25\\"]}\\n]\\n", "remarks": "\\nbased on this Creative Commons Att-SA 3.0 exercise:\\nhttps://cloudcoder.org/repo/exercise/535b0347ba7d641fd5860ddace95f258c17e2386\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(286, '[email protected]', 'cpp/practice/ascii_table', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\n<p>Write a program that prints out the following table of ASCII values:\\n<pre>\\nchr: ! \\" # $ % & '' ( ) * + , - . /\\nasc: 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47\\nchr: 0 1 2 3 4 5 6 7 8 9 : ; > = < ?\\nasc: 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63\\nchr: @ A B C D E F G H I J K L M N O\\nasc: 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79\\nchr: P Q R S T U V W X Y Z [ \\\\ ] ^ _\\nasc: 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95\\nchr: ` a b c d e f g h i j k l m n o\\nasc: 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111\\nchr: p q r s t u v w x y z { | } ~ \\nasc: 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127\\n</pre>\\nYou should use nested loops (it will fail if you just literally print\\nout the 12 lines above).\\n", "lang": "C++", "source_code": "\\n#include <iostream>\\nusing namespace std; \\n\\\\[\\nint main() {\\n // 6 pairs of lines\\n for (int i=0; i<6; i++) {\\n // first line in the pair\\n cout << \\"chr:\\";\\n for (int j=16*i+32; j<16*i+48; j++)\\n cout << \\" \\" << (char)j << \\" \\";\\n cout << endl;\\n\\n // second line in the pair\\n cout << \\"asc:\\";\\n for (int j=16*i+32; j<16*i+48; j++) {\\n if (j<100)\\n cout << \\" \\" << j << \\" \\";\\n else\\n cout << \\" \\" << j;\\n }\\n cout << endl;\\n }\\n return 0;\\n}\\n]\\\\\\n", "tests": "[\\n {}\\n]\\n", "remarks": "based on a Creative Commons Att-NC-SA 3.0 exercise from:\\nhttp://cscircles.cemc.uwaterloo.ca/8-remix/\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(287, '[email protected]', 'cpp/cstrings/examples/nullchar', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThe null character is <tt>''\\\\0''</tt>.\\n", "example": "True", "source_code": "\\n#include <iostream>\\nusing namespace std; // access cout and endl\\n\\nint main() {\\n cout << boolalpha;\\n char word[3] = \\"Hi\\";\\n // check the characters\\n cout << (word[0] == ''H'') << endl;\\n cout << (word[1] == ''i'') << endl;\\n cout << (word[2] == ''\\\\0'') << endl;\\n return 0;\\n}\\n", "tests": "[\\n {}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:05', 'save', 'open'),
(288, '[email protected]', 'cpp/cstrings/strlen', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>strlen</tt> that takes a single character array as input, \\n<tt>src</tt>. <tt>src</tt> is a null-terminated character array. Return\\nthe number of non-null characters in the string. Example: \\"hi\\" should return\\n2 while \\"\\" should return 0.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"strlen\\", \\"int\\", [\\"char[]\\"]],\\n [\\"call-function\\", \\"strlen\\", [\\"\\\\\\"hi\\\\\\"\\"]],\\n [\\"call-function\\", \\"strlen\\", [\\"\\\\\\"\\\\\\"\\"]],\\n [\\"call-function\\", \\"strlen\\", [\\"\\\\\\"hello world\\\\\\"\\"]],\\n [\\"call-function\\", \\"strlen\\", [\\"\\\\\\"Walk your bike!\\\\\\"\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// return the length (# non-null characters) of the C-string\\n// (null-terminated character array) passed as an argument\\n\\\\[int]\\\\ strlen(\\\\[char src[]]\\\\)\\n{\\n\\\\[\\n int x = 0;\\n while (src[x] != ''\\\\0'') {\\n x++;\\n }\\n return x;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(289, '[email protected]', 'cpp/cstrings/examples/cstr', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of a null-terminated character array.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n \\n\\\\show:\\n // create array. which ones are valid?\\n char greeting[6] = {''H'', ''e'', ''l'', ''l'', ''o'', ''\\\\0''};\\n //char greeting[] = {''H'', ''e'', ''l'', ''l'', ''o'', ''\\\\0''};\\n //char greeting[5] = {''H'', ''e'', ''l'', ''l'', ''o'', ''\\\\0''};\\n //char greeting[7] = {''H'', ''e'', ''l'', ''l'', ''o'', ''\\\\0''};\\n //char greeting[6] = {''H'', ''i'', ''\\\\0'', ''o'', ''k'', ''\\\\0''};\\n\\n// ? what about this one?\\n// char greeting[] = {''H'', ''e'', ''l'', ''l'', ''o'', '' '', ''m'', ''y'',\\n// '' '', ''f'', ''r'', ''i'', ''e'', ''n'', ''d'', ''s''};\\n\\n // pass its address to cout\\n cout << greeting; \\n\\n return 0;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(290, '[email protected]', 'cpp/cstrings/streq', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>streq</tt> that takes \\ntwo character arrays as input,\\nand checks whether they are equal (contain the same text). \\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"streq\\", \\"bool\\", [\\"char[]\\", \\"char[]\\"]],\\n [\\"call-function\\", \\"streq\\", [\\"\\\\\\"programming\\\\\\"\\", \\"\\\\\\"programming\\\\\\"\\"]],\\n [\\"call-function\\", \\"streq\\", [\\"\\\\\\"programming\\\\\\"\\", \\"\\\\\\"programs\\\\\\"\\"]],\\n [\\"call-function\\", \\"streq\\", [\\"\\\\\\"hi\\\\\\"\\", \\"\\\\\\"bye\\\\\\"\\"]],\\n [\\"call-function\\", \\"streq\\", [\\"\\\\\\"hi\\\\\\"\\", \\"\\\\\\"hippie\\\\\\"\\"]],\\n [\\"call-function\\", \\"streq\\", [\\"\\\\\\"thistle\\\\\\"\\", \\"\\\\\\"this\\\\\\"\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n\\\\[ bool ]\\\\ streq(\\\\[ char a[], char b[] ]\\\\) {\\n\\\\[\\n int i=0;\\n while (true) {\\n if (a[i] == ''\\\\0'' && b[i] == ''\\\\0'')\\n return true; // got to end\\n if (a[i] != b[i])\\n return false; // different OR one ended earlier\\n i++;\\n } \\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(291, '[email protected]', 'cpp/cstrings/examples/nullchar2', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nThe effects of the null character.\\n", "example": "True", "source_code": "\\n#include <iostream>\\nusing namespace std; // access cout and endl\\n\\nint main() {\\n\\\\[\\n\\n\\\\show:\\n char test[] = {''1'', ''0'', ''3'', ''\\\\0'', ''C'', ''S'', ''\\\\0''};\\n cout << test << endl;\\n]\\\\\\n return 0;\\n}\\n", "tests": "[\\n {}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:05', 'save', 'open'),
(292, '[email protected]', 'cpp/cstrings/capitalize', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>capitalize</tt>\\nthat takes a C string and capitalizes every letter in it.\\nNon-letters should be left alone. \\n<p>You may need to refer to an ASCII table:<br> <img src=\\"http://macao.communications.museum/images/exhibits/2_18_8_1_eng.png\\">.\\n<p>You should <b>not</b> use cin or cout, that part is done for you\\nin order to facilitate testing.\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"thisISaTEsT\\"},\\n {\\"stdin\\": \\"don''t_4get_ONLY_letters_CHANGE\\"},\\n {\\"stdin\\": \\"abcsdmZklAdz][`''@{}\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid capitalize(char text[]) {\\n\\\\[\\n int i=0;\\n while (text[i] != ''\\\\0'') {\\n if (text[i] >= ''a'' && text[i] <= ''z'') {\\n text[i] += ''A''-''a'';\\n }\\n i++;\\n }\\n]\\\\\\n}\\n\\nint main() {\\n char word[81]; // allow a word up to 80 characters\\n cin >> word;\\n cout << \\"Before calling your function, word is: \\" << word << endl;\\n\\n // call YOUR function\\n capitalize(word);\\n\\n cout << \\"After calling your function, word is: \\" << word << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(293, '[email protected]', 'cpp/dynamic_mem/oom', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nRunning out of memory. <i>What needs to change to avoid this?</i>\\n", "lang": "C++", "cppflags_add": "[\\"-Wno-unused-variable\\"]", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n for (int i=0; i<1000000; i++) {\\n int* p = new int;\\n\\\\[\\n delete p;\\n\\n\\\\show:\\n ;\\n]\\\\\\n }\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(294, '[email protected]', 'cpp/dynamic_mem/examples/newarray', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of new and delete.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int* arr = new int[3]; // get 12 bytes of memory\\n arr[0] = 13;\\n arr[1] = 7;\\n arr[2] = 42;\\n cout << arr[0] << \\" \\" << arr[1] << \\" \\" << arr[2];\\n delete[] arr; // remember to recycle!\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(295, '[email protected]', 'cpp/dynamic_mem/examples/gone', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAccessing deleted memory.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int* p = new int; \\n *p = 103; \\n delete p; // too soon!\\n cout << *p; // too late!\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(296, '[email protected]', 'cpp/dynamic_mem/deepnames', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program that reads 10 names from input, stores them in an\\narray of dynamically-allocated char pointers, and prints them out.\\n<ul>\\n<li>Don''t allocate more dynamic memory than absolutely necessary.\\nThis means that you need to read strings to a temporary buffer,\\nthen create dynamic memory of exactly the right size.\\n<li>Remember to recycle \\n<i>all</i> dynamically-allocated memory!\\n\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "cppflags_add": "[\\"-Wno-unused-variable\\"]", "source_code": "\\n#include <iostream>\\n#include <cstring>\\nusing namespace std;\\n\\nint main() {\\n // store 10 user names \\n // names type is a char**\\n char* names[10];\\n char temp[50];\\n \\n for (int i=0; i < 10; i++) {\\n \\\\[\\n cin >> temp;\\n char* new_region = new char[strlen(temp)+1];\\n names[i] = new_region; // shallow copy (address)\\n strcpy(names[i], temp); // deep copy (each character)\\n \\\\show:\\n cin >> names[i]; // does this work?\\n // PS: don''t allocate more than needed.\\n ]\\\\\\n }\\n\\n // now print the names\\n for (int i=0; i < 10; i++) {\\n cout << names[i] << \\" \\";\\n } \\n cout << endl;\\n // now free/delete the memory you allocated\\n\\\\[\\n for (int i=0; i < 10; i++) {\\n delete[] names[i];\\n }\\n\\\\show:\\n ; // TODO\\n]\\\\\\n return 0;\\n}\\n", "tests": "[\\n {\\"stdin\\": \\"Timothy Christopher Jennifer Tommy John Bill Rafastafafarimalingoberry Melissa JackTwentyFourLetterName Peter\\"}\\n]\\n", "lang": "C++"}', '2015-07-02 22:07:05', 'save', 'open'),
(297, '[email protected]', 'cpp/dynamic_mem/redelete', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nRe-deleting memory.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int* p = new int; \\n *p = 103; \\n\\\\[\\n delete p;\\n\\\\show:\\n delete p;\\n delete p;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(298, '[email protected]', 'cpp/dynamic_mem/ordered_array', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>ordered_array</tt> that takes a single integer argument,\\n<tt>n</tt> and dynamically allocates an integer array of that size and fills\\nit with values 1 through n. It should return the dynamically allocated\\narray back to main which will print out its contents and perform any cleanup.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"5\\", \\"args\\": [\\"\\"]},\\n {\\"stdin\\": \\"1\\", \\"args\\": [\\"\\"]}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// return a new, dynamically allocated integer array of\\n// size n with values 1 to n stored in it\\n\\\\[int*]\\\\ ordered_array(int n) {\\n int* data = \\\\[new int[n]]\\\\;\\n \\\\[\\n for (int i=0; i < n; i++) {\\n data[i] = i+1;\\n }\\n ]\\\\\\n return \\\\[data]\\\\;\\n}\\n\\nint main() {\\n int n;\\n cout << \\"Enter the size of the array: \\" << endl;\\n cin >> n;\\n\\n // Select the right type for the nums value which stores\\n // what is returned by ordered_array()\\n \\\\[int*]\\\\ nums = ordered_array(n);\\n\\n for (int i=0; i < n; i++) {\\n cout << nums[i] << \\" \\";\\n }\\n cout << endl;\\n\\n // Do any other final work before exiting\\n \\\\[\\n delete[] nums; \\n ]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(299, '[email protected]', 'cpp/dynamic_mem/storemany', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a program that will read a sequence of integers of any length\\nfrom input, with <tt>-1</tt> indicating the end of input. Then it\\nshould print out that sequence twice. For example if the input is\\n<pre>\\n2014 10 7 -1\\n</pre>\\nthen the output should be\\n<pre>\\n2014 10 7 2014 10 7\\n</pre>\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"2014 10 7 -1\\"},\\n {\\"stdin\\": \\"34 7 75 20 94 77 76 26 66 12 -1\\"},\\n {\\"stdin\\": \\"0 66 77 51 62 96 95 86 91 52 83 7 49 96 17 97 8 17 45 26 14 27 6 5 44 38 53 43 33 19 58 19 46 63 0 47 89 10 92 51 96 95 81 30 22 73 30 87 33 31 33 13 44 61 39 18 99 77 90 44 30 30 86 84 25 93 92 89 65 0 44 54 88 1 70 80 27 45 43 45 86 4 89 67 12 25 72 56 85 13 23 63 15 23 83 24 38 51 12 97 18 4 28 84 72 94 17 87 23 55 5 68 27 47 0 3 38 33 73 23 98 5 26 50 63 84 48 1 74 48 11 11 25 36 86 65 76 7 99 80 26 31 94 83 61 53 24 55 11 82 79 12 26 2 73 21 34 48 11 27 86 52 38 52 19 30 23 97 90 8 4 12 28 43 45 36 37 96 54 18 97 77 86 71 14 98 95 20 60 95 40 48 72 27 12 98 16 2 63 82 42 63 11 60 10 18 37 99 59 24 94 59 98 89 59 25 81 99 48 6 71 89 78 62 38 98 19 45 99 37 4 46 43 99 5 71 59 49 92 84 5 90 42 34 89 93 39 39 88 15 17 25 24 61 60 90 82 51 92 43 15 6 13 98 70 91 55 92 52 38 50 28 68 60 51 86 87 39 16 72 98 24 7 83 76 58 43 36 88 95 57 62 99 15 4 54 1 85 29 3 6 96 20 90 58 68 66 94 30 92 87 77 59 84 17 42 46 34 91 58 9 5 68 39 61 10 31 56 85 7 24 58 23 93 27 21 10 59 33 50 42 14 7 4 88 67 30 88 28 91 57 65 12 6 10 2 25 53 68 42 13 94 91 54 2 28 21 91 77 18 7 42 98 41 84 93 49 26 86 8 80 79 46 65 24 51 3 25 5 86 95 81 24 42 92 33 31 74 85 8 18 27 51 92 66 92 51 27 35 71 19 18 35 90 3 26 15 59 0 81 63 76 41 34 3 30 34 14 76 35 55 45 0 85 99 33 13 20 40 16 75 75 68 41 34 61 95 25 93 53 13 47 35 51 14 37 80 91 31 93 12 13 2 56 93 80 72 81 65 95 85 19 96 91 17 14 91 82 31 72 85 50 47 10 22 30 41 36 94 75 20 49 13 34 46 61 34 0 97 98 97 19 14 51 15 7 8 37 27 34 4 51 38 86 68 91 71 39 87 82 27 80 87 77 38 18 69 29 36 41 48 22 6 2 10 25 16 19 85 0 42 66 75 68 17 79 23 50 91 53 65 59 24 22 66 70 21 50 97 35 22 12 35 27 49 85 53 83 41 11 71 99 62 34 61 43 78 96 49 95 21 17 12 2 80 24 61 74 49 39 90 11 56 60 88 85 35 26 28 30 83 15 10 47 37 93 68 13 55 90 0 55 14 93 89 89 86 84 26 77 57 27 87 5 1 32 70 70 33 14 14 75 31 33 15 64 38 46 24 92 92 17 96 62 53 90 89 71 80 78 2 47 55 99 65 62 45 30 1 73 27 22 46 24 33 20 66 80 31 53 52 5 86 16 49 84 22 10 40 93 35 39 28 35 40 19 73 38 10 56 38 91 30 26 25 74 11 66 14 73 84 18 76 65 31 58 42 29 79 56 36 12 17 60 67 89 82 56 82 45 72 35 58 33 51 96 5 24 26 69 68 42 60 1 73 74 22 49 14 37 95 16 52 77 51 92 37 88 19 28 88 62 76 88 78 17 87 79 2 98 6 16 62 62 72 9 95 12 29 31 92 27 82 2 94 99 74 93 70 65 82 60 51 57 56 34 3 83 77 74 38 29 73 55 15 14 35 34 5 64 25 1 4 69 22 48 52 72 93 80 75 25 51 14 88 9 57 38 77 27 24 21 82 60 21 98 65 85 4 49 96 54 94 78 81 84 75 72 39 8 32 14 55 54 35 3 22 40 13 12 18 19 86 47 64 93 65 5 42 48 19 71 4 80 16 17 80 96 23 48 68 82 89 63 66 36 95 63 66 5 50 24 59 54 48 50 92 4 79 64 82 14 9 30 52 41 18 54 37 11 71 72 75 71 68 32 47 97 60 14 19 2 20 76 17 54 31 52 85 55 48 61 17 2 94 47 99 31 6 49 0 12 64 50 98 59 27 91 76 17 70 82 56 25 96 26 92 14 52 81 84 37 14 54 56 53 86 17 17 78 33 16 26 44 59 79 72 98 91 19 3 89 34 14 20 71 83 13 72 20 50 34 25 79 37 29 56 6 29 23 65 83 21 7 87 85 53 96 79 46 18 19 23 18 65 30 36 47 80 94 49 68 19 78 10 87 99 39 94 39 97 95 71 96 25 33 54 20 25 99 95 41 29 66 22 68 6 80 94 39 59 4 94 86 50 60 28 2 48 19 71 72 42 26 51 93 81 52 54 0 73 55 42 39 79 17 26 41 69 48 38 94 38 59 77 85 85 62 5 32 53 95 1 48 19 0 20 61 13 15 52 52 62 85 86 32 38 98 74 7 33 67 35 40 58 95 3 95 76 44 35 56 97 10 4 71 41 15 82 30 71 20 8 96 70 68 21 57 22 38 48 3 26 91 2 39 94 74 44 87 3 97 59 59 9 46 81 43 42 11 18 11 63 53 6 28 68 85 18 35 73 66 65 91 76 21 8 18 4 75 53 95 72 13 45 49 67 41 14 28 27 68 90 3 12 46 69 97 71 30 68 11 76 36 47 55 15 78 73 81 56 35 23 16 50 27 84 22 23 33 39 1 91 69 44 38 10 61 8 77 14 50 47 70 74 71 65 93 69 18 45 80 98 41 95 53 59 47 87 5 8 26 87 36 13 94 44 84 20 27 92 31 94 80 15 40 14 65 18 91 25 18 41 39 38 56 0 56 19 44 51 3 50 72 15 89 58 73 51 12 11 30 84 9 67 56 76 74 10 89 28 42 79 65 56 86 96 25 27 7 79 48 83 31 96 95 50 21 22 14 54 5 20 32 88 96 66 12 65 47 86 13 42 72 72 73 97 62 29 60 62 40 97 91 47 54 8 91 40 45 46 96 31 3 39 91 66 8 56 42 31 70 45 9 77 61 93 18 97 14 55 21 98 52 85 97 11 21 39 71 43 61 98 73 27 2 82 76 25 99 51 49 68 60 12 46 60 10 69 24 64 87 66 88 95 49 6 75 62 66 46 52 72 1 10 98 36 35 67 95 89 68 95 42 87 97 23 21 8 78 17 35 15 40 79 43 60 1 50 0 72 76 59 57 45 72 65 6 4 54 16 92 51 18 1 22 88 74 29 87 92 64 16 83 35 8 52 13 72 78 1 46 16 53 35 45 74 19 71 23 2 11 55 3 56 74 77 73 10 37 68 97 73 29 54 20 22 34 26 31 96 32 99 4 88 59 93 57 87 52 42 49 93 86 70 90 10 27 58 98 56 49 34 82 43 31 28 95 70 27 23 64 7 66 6 79 26 34 90 19 67 27 22 45 98 29 37 27 41 68 9 76 39 9 61 4 22 70 95 12 56 4 94 7 9 71 75 23 86 11 56 1 20 47 41 65 84 39 46 45 95 91 48 5 96 94 72 3 75 63 71 17 72 95 76 99 37 38 52 29 69 34 64 6 13 7 98 64 72 93 52 79 68 21 6 10 70 98 18 33 96 62 37 77 91 21 92 24 31 87 49 55 12 31 60 31 68 42 46 0 29 68 47 30 56 27 3 71 57 45 23 0 92 47 44 58 51 79 59 78 87 45 34 30 13 54 75 24 39 76 6 90 42 17 66 47 15 43 29 30 69 68 40 35 67 55 41 74 43 93 39 60 19 82 85 74 23 20 33 81 93 76 54 92 51 40 93 20 48 23 7 49 36 55 14 26 95 36 77 17 38 5 43 44 75 50 69 63 92 99 32 43 91 68 60 65 22 89 44 78 5 22 88 33 59 81 66 43 97 69 67 5 95 47 68 44 78 29 49 31 83 23 3 88 76 30 59 46 47 81 6 41 89 85 73 50 42 69 25 63 76 25 34 3 81 4 30 64 0 47 60 71 18 66 18 23 14 30 20 96 97 55 79 75 64 49 57 89 12 22 54 93 50 20 22 49 26 2 49 40 90 0 86 78 39 34 74 6 32 12 26 83 7 48 22 96 15 8 91 44 0 67 55 3 72 73 67 6 47 93 79 77 77 84 81 25 69 38 69 59 89 4 80 83 41 0 86 90 0 62 90 89 26 39 23 76 28 99 3 67 5 6 97 64 68 92 53 66 65 49 57 38 24 59 57 75 3 9 86 44 3 72 17 64 25 59 32 39 54 18 26 89 45 76 69 47 8 96 65 18 64 1 39 30 43 32 73 74 69 12 4 28 26 6 72 81 22 53 14 96 5 99 41 32 51 40 44 87 54 4 46 8 31 71 89 1 31 83 35 82 94 33 11 52 79 54 56 15 71 43 31 74 74 81 23 97 1 54 84 68 4 77 58 22 50 76 12 98 4 66 64 3 77 8 25 53 87 65 62 94 40 30 99 93 91 80 95 47 52 38 53 78 73 86 79 9 28 21 68 9 38 91 54 26 66 93 38 35 98 12 69 73 69 48 4 25 92 94 58 10 93 85 93 57 74 96 52 27 36 53 35 24 79 42 50 84 81 67 77 98 29 11 65 2 43 46 65 66 31 2 72 47 77 87 78 32 58 27 19 81 90 29 38 7 66 83 96 35 31 19 85 2 54 83 75 39 62 61 94 46 88 69 21 19 11 78 34 86 55 47 71 61 33 55 44 96 47 12 32 22 16 32 93 12 78 28 53 33 92 69 61 45 72 50 44 89 52 41 46 53 85 64 63 77 66 27 71 68 65 25 19 57 26 7 53 11 64 92 67 86 21 94 43 72 48 4 14 39 41 59 27 19 3 80 45 51 5 40 5 36 77 75 53 81 93 40 39 44 17 77 22 5 6 27 8 8 66 8 66 2 71 84 55 42 62 95 30 36 2 20 37 68 64 31 27 61 54 73 84 39 28 45 84 89 1 32 46 35 38 72 67 28 54 74 50 64 82 27 28 32 4 62 6 5 4 74 30 72 91 81 94 90 89 63 5 62 22 86 2 42 6 70 60 45 96 76 23 57 78 15 65 91 78 33 30 70 21 74 1 1 76 40 92 88 92 34 84 20 66 95 85 21 14 81 0 83 85 40 60 57 12 97 18 79 83 88 5 9 83 19 22 30 46 4 67 1 7 11 93 75 93 67 3 58 47 77 60 33 75 82 90 10 81 1 1 41 66 44 45 66 29 30 1 97 88 16 22 26 75 54 24 6 64 72 78 68 37 32 48 86 40 14 78 96 16 60 90 24 83 48 70 95 87 69 80 85 71 34 31 57 36 36 60 15 49 9 5 23 37 8 69 54 82 16 72 59 72 35 6 40 89 87 94 0 35 12 57 86 82 0 52 70 63 21 51 88 17 33 2 18 88 1 79 90 49 92 63 1 71 31 91 36 74 67 76 52 31 58 35 65 25 77 34 53 29 92 34 85 51 96 93 65 75 3 51 92 59 71 16 4 92 8 58 12 29 22 56 38 34 37 18 17 0 5 42 92 95 41 23 67 77 31 29 31 48 36 42 26 21 63 45 90 67 43 80 58 4 33 39 29 35 81 42 37 62 90 34 15 31 58 87 9 4 68 22 52 8 39 34 14 51 44 81 81 13 97 27 96 83 41 67 0 77 25 67 82 89 12 21 66 44 3 53 57 12 15 90 72 22 42 84 69 92 28 84 63 29 86 1 28 1 89 46 77 39 91 3 10 52 54 89 49 75 52 20 56 18 59 56 96 84 97 55 5 67 50 1 57 77 66 48 82 29 18 17 11 39 73 30 13 19 48 21 29 1 73 88 47 32 58 33 89 61 15 40 74 19 90 16 5 50 15 0 52 23 2 53 19 31 45 63 80 85 22 76 61 44 1 1 21 30 3 22 68 87 96 35 51 49 1 86 77 27 91 5 69 44 31 23 61 73 2 72 24 49 69 16 46 16 62 12 92 98 35 57 22 80 44 33 32 26 2 80 49 43 94 0 41 3 6 70 63 88 92 92 2 81 42 72 4 82 82 7 14 57 69 35 2 39 1 19 9 92 20 18 94 27 27 40 51 92 23 87 77 57 34 49 67 12 48 0 33 61 73 62 61 89 24 44 16 24 13 63 8 30 32 99 22 30 18 52 43 0 24 70 87 67 39 75 53 65 12 82 27 10 97 77 56 48 26 10 75 78 48 12 16 74 5 45 86 45 75 86 69 22 91 98 66 6 97 54 22 54 45 94 7 77 95 79 82 4 79 62 91 47 67 71 31 38 92 61 27 32 69 63 39 4 69 83 32 49 23 49 40 42 43 43 69 71 71 76 78 30 74 33 33 29 84 92 71 98 59 20 80 57 31 76 0 39 55 15 29 95 38 50 41 49 56 4 95 63 98 85 70 65 73 73 17 19 79 53 55 94 26 24 92 10 10 61 7 16 95 60 46 88 71 62 40 13 77 67 89 59 17 51 88 31 38 90 45 98 50 51 18 6 83 13 63 24 83 17 43 29 66 18 56 5 10 28 48 69 81 46 89 84 79 74 63 57 83 27 60 59 1 26 37 1 62 30 33 36 67 7 82 65 29 20 83 47 74 97 28 1 54 13 11 96 80 86 6 53 85 60 68 74 18 89 33 21 58 54 13 33 80 1 3 70 77 40 8 35 97 46 6 82 15 45 99 75 16 59 92 19 16 39 38 92 81 23 3 61 58 89 92 49 15 48 88 23 32 11 33 29 33 92 56 33 15 89 34 88 89 5 54 16 57 89 45 36 58 76 83 13 5 70 58 79 42 9 17 44 33 60 46 36 93 71 93 21 13 46 77 9 28 75 93 30 68 1 89 14 29 90 75 64 93 37 22 23 26 83 63 55 10 48 55 89 9 39 61 96 76 44 54 39 48 49 68 42 45 79 45 36 57 49 91 41 33 28 68 15 43 34 57 89 81 53 75 62 97 14 62 73 86 43 39 38 64 41 44 87 96 24 29 33 61 83 40 73 63 24 82 42 74 26 93 58 95 57 89 87 47 51 43 24 13 45 71 55 82 73 50 19 6 45 65 93 45 45 63 37 87 86 23 85 23 54 30 90 4 32 11 50 67 39 12 21 25 41 31 72 27 74 94 87 9 20 57 45 87 98 80 4 82 91 1 90 3 75 84 58 14 60 89 48 26 97 65 99 10 23 13 23 4 44 64 95 89 86 30 36 94 76 57 71 18 39 53 12 50 62 77 24 12 62 55 9 64 13 62 91 91 0 49 89 5 50 85 34 79 16 66 59 18 85 34 1 1 99 24 70 44 61 60 36 51 94 35 97 77 8 74 36 54 17 87 6 62 79 31 41 53 37 99 82 59 59 81 80 24 38 78 3 90 85 80 99 59 49 60 27 82 87 56 22 46 37 48 58 33 54 62 45 74 59 31 3 79 14 57 32 8 16 67 75 12 83 50 41 35 67 59 32 23 85 12 59 80 42 51 13 70 79 43 34 47 78 97 91 83 66 76 75 65 17 46 34 85 21 68 3 55 0 32 6 16 24 34 27 6 77 31 73 31 53 50 18 90 2 2 77 61 81 37 25 86 58 21 23 56 78 26 9 52 83 2 82 84 5 66 32 83 92 60 63 6 78 44 96 61 18 76 50 15 7 63 57 71 32 59 32 58 95 67 47 19 44 43 55 26 13 14 50 10 75 34 97 80 69 31 11 52 90 19 88 25 7 41 24 72 82 26 24 23 88 6 85 42 87 14 4 36 9 85 46 46 19 44 38 62 99 66 62 76 43 22 54 45 64 26 31 40 35 16 29 10 50 48 42 95 20 8 97 4 99 92 48 28 76 26 82 52 57 53 93 89 46 89 24 47 5 40 73 16 85 91 91 89 27 52 2 44 0 17 18 13 63 48 9 62 32 36 33 82 23 46 26 0 28 83 45 65 83 34 40 51 16 35 41 61 17 42 40 22 42 27 3 82 55 71 4 59 70 78 46 62 67 68 87 38 3 72 49 70 92 94 91 70 26 39 77 54 26 86 53 38 14 27 56 0 72 6 58 17 7 26 8 67 24 95 61 84 66 37 83 14 47 54 77 1 88 84 69 46 24 84 80 80 5 56 62 92 53 12 82 35 96 66 53 31 52 68 98 89 65 99 44 9 48 60 76 19 94 31 56 53 35 20 72 96 41 6 55 96 10 55 20 20 30 76 66 58 28 38 20 9 19 21 5 93 24 58 57 2 44 76 66 11 2 30 17 6 26 94 22 14 89 18 93 49 77 81 28 72 19 48 5 83 40 66 62 75 48 12 58 0 43 44 33 45 23 49 67 55 11 19 76 10 79 41 55 67 24 48 90 53 36 62 96 37 11 94 21 94 46 79 74 44 11 99 18 89 23 56 80 38 15 23 89 10 76 12 41 75 80 98 26 2 50 19 73 52 54 41 94 88 20 35 84 29 77 97 67 96 35 19 70 1 14 47 6 67 86 75 56 92 91 39 91 12 98 68 71 93 85 99 50 96 6 82 20 97 29 30 99 80 56 3 92 92 30 7 23 96 46 93 88 74 64 58 62 46 32 11 63 7 68 33 27 25 89 86 6 19 71 54 74 3 83 23 12 69 18 47 96 15 82 70 95 24 33 52 77 37 74 49 16 33 25 39 59 32 20 10 62 29 22 80 83 83 81 72 3 86 61 34 59 56 41 24 8 73 85 34 45 71 44 31 7 68 67 90 8 6 22 89 79 54 67 41 77 66 91 95 97 98 49 38 93 82 44 67 53 24 18 70 26 89 39 18 52 23 95 17 65 33 80 69 83 14 0 80 42 1 96 63 36 22 80 78 6 29 39 51 37 30 38 56 55 9 82 65 56 90 80 45 87 72 4 28 98 39 20 9 99 65 94 79 23 13 44 96 80 33 0 53 5 28 16 45 47 87 18 50 43 40 11 7 55 64 33 37 49 1 70 58 30 3 87 24 28 82 37 31 8 95 88 54 59 30 91 74 39 16 45 4 52 47 72 2 27 43 26 97 61 46 36 65 86 5 78 9 10 17 72 35 47 8 64 19 7 78 1 67 35 21 88 33 99 85 86 85 71 14 47 9 24 19 21 47 64 22 89 72 44 71 13 50 37 81 5 90 13 55 37 0 46 78 69 33 51 64 46 77 41 98 71 49 12 85 17 54 18 14 94 18 37 61 85 14 21 38 26 56 83 13 7 90 51 62 58 72 93 28 9 25 51 26 35 24 86 6 75 97 37 15 51 92 52 61 2 18 15 47 44 29 35 71 55 80 26 83 7 1 53 14 4 39 5 37 65 80 43 68 32 46 48 19 1 32 0 73 68 81 46 63 97 48 60 79 52 88 37 94 79 98 25 58 8 86 41 29 46 10 90 4 54 57 33 28 80 49 81 66 12 9 30 91 99 63 50 0 7 24 12 85 55 8 75 46 19 91 25 7 44 62 0 87 35 50 12 9 44 88 54 54 47 24 88 92 25 73 25 7 12 65 81 15 19 30 50 75 81 13 69 32 45 95 46 93 63 59 35 48 25 65 26 8 86 30 15 88 0 0 68 91 23 42 44 35 56 23 23 33 78 60 26 2 13 90 8 20 4 44 79 99 82 87 20 29 34 21 95 89 2 76 62 13 10 28 15 72 27 42 61 99 68 95 5 74 70 84 75 3 85 44 86 34 13 81 13 97 36 74 14 87 70 74 20 8 56 68 36 64 81 26 80 23 44 50 55 84 53 53 71 92 64 55 40 14 85 64 33 35 28 7 65 25 86 49 16 32 68 51 9 45 75 21 16 19 36 41 50 77 78 20 96 37 93 43 10 88 41 73 62 5 27 73 45 54 6 52 56 29 55 1 33 99 10 28 78 11 88 2 74 32 36 92 8 64 20 77 15 99 47 99 76 0 51 86 52 78 35 33 58 96 84 85 77 43 34 53 91 29 43 11 75 53 94 26 26 87 60 35 32 10 56 15 14 32 2 93 36 31 31 14 16 41 6 22 41 72 28 74 42 89 86 32 46 55 76 88 82 30 31 13 45 30 29 99 48 36 1 99 95 53 69 85 57 33 8 75 44 65 40 88 31 47 37 58 5 70 9 11 72 77 42 47 19 83 77 75 33 18 58 39 84 72 45 63 10 35 74 59 77 53 62 12 68 66 8 79 96 37 43 34 97 3 93 97 75 83 3 14 64 77 33 35 23 23 30 53 82 89 43 23 47 6 94 60 88 41 11 14 25 55 36 19 18 33 46 19 43 33 8 3 85 39 21 47 72 27 7 71 56 76 81 99 6 81 12 61 76 72 67 91 65 52 91 31 93 6 75 24 76 92 41 86 62 98 39 17 94 28 78 40 92 11 64 16 52 84 97 38 62 99 2 20 89 87 63 83 56 34 38 8 19 96 74 62 18 19 73 50 87 76 9 11 93 81 32 22 52 72 18 76 26 59 15 64 1 55 25 59 29 70 52 84 90 25 64 69 82 2 78 47 9 81 56 28 20 69 52 77 9 96 75 68 72 61 96 65 75 70 46 38 37 35 6 92 38 99 41 33 3 34 92 53 88 18 42 74 78 55 98 46 37 50 81 28 23 50 54 44 65 64 14 72 56 91 50 12 75 5 85 98 81 19 19 11 56 39 0 5 92 43 80 20 69 13 97 16 13 77 47 19 84 35 37 80 83 83 51 92 9 34 56 28 94 84 87 49 70 16 23 43 63 30 82 41 28 38 34 27 8 6 51 45 30 3 78 91 49 72 57 31 41 61 54 45 59 58 56 46 13 69 79 27 25 33 91 70 92 44 14 4 54 22 34 20 64 87 83 78 28 86 82 78 83 91 21 69 81 85 38 34 26 48 73 21 38 65 71 22 17 90 78 95 80 16 81 49 75 55 17 21 34 88 89 44 34 59 11 73 44 13 24 1 40 82 19 70 86 15 57 46 37 0 77 5 42 14 25 8 18 50 40 5 71 97 33 12 49 45 74 48 48 33 38 98 81 11 63 50 86 23 24 63 28 98 20 1 49 61 60 21 33 81 89 42 77 0 12 61 25 48 6 61 31 45 46 22 57 60 70 5 60 94 70 17 22 39 86 19 61 60 76 6 65 36 80 71 22 67 55 2 41 69 93 90 72 34 37 67 30 96 99 78 16 69 43 96 6 13 17 99 84 10 92 21 96 58 27 44 77 59 12 48 77 58 13 13 86 50 64 47 62 66 73 7 40 65 37 41 28 10 47 26 26 68 51 39 14 74 18 63 7 42 33 60 75 89 1 85 20 38 58 89 58 59 82 44 86 84 25 94 46 21 55 40 39 44 22 74 35 10 31 49 94 84 46 87 14 78 76 10 6 55 18 21 9 10 6 19 95 45 24 44 79 48 44 7 20 66 29 67 36 67 11 5 88 54 30 37 97 49 69 31 12 48 61 4 23 56 1 64 15 45 59 14 47 48 15 31 12 65 85 58 78 46 55 24 50 69 36 13 88 0 86 47 49 40 70 33 70 35 91 64 76 27 7 14 63 53 56 54 49 1 34 70 72 49 49 23 1 75 53 31 59 99 15 25 97 91 23 32 3 34 37 14 7 77 20 40 67 78 59 53 13 70 43 89 17 86 51 82 54 86 9 82 32 53 87 74 70 3 63 67 52 26 9 94 56 54 90 50 89 45 50 63 60 37 80 98 63 28 92 34 67 72 36 17 96 25 18 40 81 54 52 96 54 24 97 29 12 84 27 41 14 66 48 26 74 88 68 63 91 96 99 33 58 98 82 21 13 15 13 91 94 23 87 18 84 85 74 84 17 3 23 30 36 33 52 99 90 53 79 23 38 9 40 34 44 28 22 87 67 53 72 59 93 89 38 58 68 46 69 93 3 86 72 79 75 52 59 39 59 20 21 15 4 55 26 10 10 36 7 47 10 60 56 15 70 26 57 83 58 6 51 68 31 70 13 59 67 91 90 76 43 73 43 58 19 59 11 92 76 82 55 11 16 15 51 91 2 23 37 1 11 16 36 65 82 47 20 77 44 73 55 70 2 11 68 88 94 38 68 13 1 37 98 94 32 89 65 96 47 17 89 43 79 7 96 76 80 51 87 65 86 28 74 87 48 6 26 10 56 47 67 4 15 65 56 65 38 88 85 63 37 47 66 71 59 5 59 72 21 3 69 19 13 86 84 0 81 40 89 34 55 64 24 43 29 53 19 33 46 19 3 9 24 9 95 78 29 90 50 21 97 36 65 62 54 35 83 35 49 95 49 40 70 85 86 12 28 55 65 7 81 23 24 90 22 34 3 3 67 96 74 87 40 61 67 41 93 40 52 46 86 58 97 32 97 66 12 41 51 21 43 20 18 16 53 74 75 0 93 73 96 38 5 70 56 36 37 71 73 65 81 74 41 56 54 74 62 84 23 83 11 49 48 27 67 52 64 1 89 55 83 18 22 44 46 6 69 70 30 20 64 1 95 83 67 4 20 75 7 9 65 87 76 12 79 34 92 52 8 53 76 80 31 94 61 75 51 23 76 48 78 42 88 78 63 96 25 75 15 22 11 35 84 5 25 57 65 0 14 98 44 30 91 20 6 70 36 74 8 80 84 56 65 99 99 24 58 62 49 87 59 45 78 32 91 32 74 43 74 69 29 92 50 76 51 61 90 48 28 83 58 52 7 84 76 97 13 21 2 91 29 63 10 52 41 34 32 23 23 37 6 65 10 78 93 94 87 77 36 22 43 62 96 19 42 5 98 37 93 18 75 34 49 57 19 9 0 44 33 71 81 39 84 79 12 2 1 69 73 82 12 87 63 34 52 93 27 16 48 38 34 28 46 79 20 93 5 12 24 26 87 8 40 34 24 33 87 24 67 71 18 29 27 40 17 16 89 93 67 28 33 91 26 43 1 54 36 60 19 34 79 11 55 33 11 90 20 58 14 7 20 41 81 29 89 36 88 8 39 25 64 49 95 35 33 24 82 26 58 72 56 76 72 82 39 56 21 97 22 38 32 95 58 62 11 37 77 21 93 53 86 29 9 59 96 22 70 79 66 79 48 20 0 23 37 45 15 64 47 15 1 26 79 70 31 50 79 90 68 26 22 70 80 19 66 14 51 85 98 49 50 58 11 51 69 74 30 31 57 83 96 91 81 1 79 46 98 71 71 99 0 98 96 84 93 39 37 64 55 36 90 44 31 5 50 50 55 66 31 1 73 94 70 90 98 46 77 45 56 75 79 51 88 50 20 77 89 62 88 46 13 49 62 61 45 5 47 29 94 36 0 57 23 75 96 90 74 67 49 77 52 75 27 69 37 57 96 89 65 46 78 27 86 40 23 63 21 56 76 60 51 48 83 37 57 94 90 41 98 33 36 81 61 67 99 29 51 56 52 34 88 2 53 3 9 18 96 58 52 53 0 94 84 60 45 28 5 29 86 85 8 63 8 65 63 60 7 69 62 51 22 2 37 59 7 32 93 88 30 53 83 25 5 14 75 90 46 34 57 69 45 86 99 8 28 97 90 94 23 82 61 68 62 92 50 50 35 13 40 2 93 46 18 63 67 15 28 21 33 2 12 13 26 19 81 34 29 97 58 73 29 32 75 85 56 38 80 1 14 88 42 75 79 49 35 71 59 98 62 94 0 27 99 3 83 4 75 59 54 49 16 87 12 77 6 89 67 87 36 19 34 18 82 4 23 74 60 19 29 16 74 63 0 70 59 42 58 13 73 65 64 85 43 36 38 53 23 64 15 98 36 94 36 47 31 13 59 51 90 7 30 43 86 42 24 64 75 14 22 20 88 20 91 95 6 95 21 62 3 88 99 20 38 75 93 86 7 84 52 89 46 62 41 74 9 14 94 42 33 55 54 22 53 87 36 6 92 92 16 29 63 7 72 76 37 41 72 14 8 34 78 4 6 69 11 26 0 64 46 93 8 27 86 29 97 12 25 83 88 32 38 91 13 70 7 19 26 5 93 84 13 68 35 51 1 19 99 77 4 2 14 1 64 85 16 83 59 11 53 9 48 86 76 91 39 19 5 71 27 54 62 95 87 58 90 30 31 22 70 63 91 32 73 17 83 36 28 72 53 81 8 45 8 15 94 23 33 90 31 33 31 18 90 52 14 7 79 60 14 49 82 94 7 87 62 79 58 15 85 58 58 10 82 66 9 78 62 41 59 72 76 17 56 70 56 0 33 72 72 64 14 64 4 25 13 62 56 78 68 23 78 90 63 95 35 29 22 13 2 24 65 75 67 69 27 30 54 11 77 24 9 40 17 25 99 22 9 23 74 31 16 71 3 50 57 11 77 0 25 26 57 37 45 9 52 37 90 72 21 55 60 8 38 78 95 32 75 39 11 25 80 62 16 82 85 91 23 99 68 25 9 46 34 3 50 74 53 56 6 22 6 47 85 23 33 78 64 73 8 31 9 97 60 53 13 3 15 16 86 93 64 81 95 20 57 60 55 88 87 9 85 29 4 5 46 30 75 5 69 53 36 3 57 46 54 34 97 22 78 57 50 19 67 34 85 59 26 39 41 85 58 3 89 2 55 39 19 18 0 91 69 73 30 75 22 66 46 17 89 69 35 58 89 8 44 65 43 33 12 75 33 94 18 71 89 27 29 91 56 62 59 82 43 85 98 85 73 31 26 49 60 59 53 21 13 11 59 0 56 91 90 66 40 78 8 45 20 39 13 49 54 87 7 82 40 40 72 99 60 71 44 52 76 81 92 82 5 44 31 70 59 47 95 46 6 79 92 0 21 60 19 99 73 2 8 1 43 61 33 81 29 70 6 96 94 84 41 46 69 30 74 93 57 34 88 85 3 15 28 33 49 97 92 1 3 75 82 21 0 11 74 81 15 18 96 71 6 59 75 36 48 96 49 83 52 41 87 78 86 25 95 39 19 34 36 21 13 5 17 87 98 62 1 23 21 61 7 69 7 22 6 99 93 94 90 32 15 26 97 29 4 66 34 47 45 79 14 48 40 59 61 39 9 32 78 90 95 9 5 75 98 36 86 65 49 12 36 80 4 73 78 54 78 14 4 77 88 91 43 22 92 93 42 89 46 40 98 75 16 21 44 12 38 71 97 30 61 32 97 1 39 13 3 49 85 4 28 88 69 33 14 26 30 52 42 25 18 89 93 59 75 90 21 60 76 54 57 17 19 59 60 90 72 75 31 23 76 18 54 2 64 73 91 81 51 19 19 57 24 63 76 58 7 85 69 13 0 70 20 40 42 76 36 85 23 53 70 64 70 59 74 13 49 70 76 36 14 54 73 60 49 73 1 94 12 70 78 28 47 46 89 76 82 20 21 74 5 75 18 95 49 16 8 73 32 12 29 7 40 6 74 0 27 86 12 23 70 29 45 33 81 0 52 8 29 60 62 83 69 39 94 78 82 77 86 28 18 20 87 21 1 1 3 21 48 58 62 82 27 36 73 17 46 67 60 14 64 71 4 31 97 62 58 97 89 20 20 8 47 95 69 0 81 38 90 3 1 4 98 87 93 82 15 29 57 28 85 75 23 52 85 5 57 55 39 2 71 77 47 54 96 72 64 89 84 48 14 0 52 76 39 51 57 37 32 11 4 20 36 75 94 48 14 84 30 74 72 12 70 18 39 2 57 33 49 88 31 66 29 6 55 23 79 82 5 30 58 91 50 57 2 2 35 62 44 25 68 2 6 68 5 14 90 27 67 77 2 28 22 7 32 84 49 49 51 50 70 3 73 43 96 36 71 2 52 70 32 95 36 0 2 35 87 30 27 17 93 32 21 63 6 69 66 9 28 80 59 61 96 80 43 48 64 77 57 46 19 25 42 24 54 76 89 90 6 60 16 24 36 92 6 64 73 83 59 54 84 65 65 83 60 37 33 1 45 13 26 68 73 13 33 78 78 77 6 35 7 4 97 62 1 49 3 94 66 0 10 26 79 1 46 91 97 24 36 77 80 95 15 98 21 54 23 20 2 43 2 23 43 44 38 77 1 25 3 30 24 20 46 35 77 16 20 60 14 48 60 64 94 84 87 2 26 52 52 40 53 60 58 51 98 89 15 22 52 74 46 41 82 60 61 90 77 9 66 19 87 50 38 96 88 64 53 34 32 35 75 83 69 63 92 53 54 36 29 41 97 21 73 71 64 34 98 70 40 41 77 37 62 29 84 37 95 56 98 60 53 79 55 14 39 5 96 6 52 78 79 65 26 44 23 2 67 23 31 69 51 72 4 17 66 78 12 91 93 4 11 86 14 26 30 46 30 56 5 40 4 27 75 31 41 28 10 81 22 8 3 37 34 74 17 11 93 41 57 50 3 71 69 14 11 41 75 80 12 88 48 33 47 1 86 75 71 0 88 97 8 0 54 59 12 57 82 0 59 52 85 45 0 12 64 62 83 55 23 24 68 20 93 38 84 31 58 46 86 51 50 24 32 75 52 49 70 16 14 13 69 90 61 27 79 13 37 16 92 16 7 45 81 0 37 33 98 52 96 35 36 10 90 68 44 24 54 40 98 96 91 78 89 37 93 80 71 71 92 46 39 47 26 39 32 3 29 44 39 48 16 93 41 17 65 73 99 23 23 35 68 48 85 13 63 74 98 73 32 95 26 68 42 74 45 22 49 4 50 10 8 52 21 5 42 87 43 59 89 8 23 4 74 7 1 22 22 60 42 93 86 95 56 31 6 16 50 48 23 81 89 79 49 60 85 28 87 45 38 97 66 66 91 41 36 18 85 63 4 76 67 87 90 43 15 99 16 21 12 3 2 15 35 73 16 24 53 95 36 33 90 26 16 98 62 36 59 97 80 90 31 44 79 43 60 98 71 78 49 0 61 56 79 33 83 61 79 5 79 14 30 56 91 99 35 56 60 26 2 80 51 20 36 26 33 65 33 67 30 7 40 84 80 36 29 1 92 43 41 95 70 48 49 23 53 62 22 63 20 88 43 18 34 6 75 23 77 20 26 48 19 93 89 11 40 20 23 58 13 10 84 46 77 8 6 25 0 50 44 51 90 31 18 57 37 89 17 18 11 81 42 22 99 31 93 99 80 70 97 80 6 43 50 55 62 19 97 49 41 52 14 76 5 32 76 36 64 15 63 18 46 89 9 81 55 96 68 6 76 96 23 6 85 58 83 69 11 27 65 55 16 98 41 41 25 89 12 2 61 29 64 95 54 54 59 72 70 45 2 86 58 86 80 45 30 75 47 61 76 7 24 85 99 5 37 58 45 11 67 32 80 46 8 25 42 4 79 41 22 20 26 77 90 59 20 9 49 41 28 44 13 1 7 45 41 57 74 31 22 77 62 43 44 84 1 21 67 48 24 48 83 84 98 22 59 46 58 2 64 2 60 37 32 71 62 82 46 11 93 15 82 67 14 90 99 26 52 9 0 69 68 31 46 99 60 55 62 28 18 55 88 68 81 22 3 2 22 86 56 62 64 43 87 22 49 39 92 22 56 27 18 91 46 2 11 89 80 57 49 90 32 46 32 37 78 77 5 10 37 76 18 47 1 93 63 32 4 97 31 12 89 90 37 86 62 23 24 93 99 35 38 53 81 20 90 7 75 64 69 46 92 5 42 77 99 70 13 0 58 3 56 36 95 95 22 66 20 65 28 61 31 10 80 82 51 29 27 40 3 77 68 99 68 11 26 69 87 6 7 38 4 23 23 11 21 91 13 89 52 84 3 6 92 9 7 3 64 75 38 79 56 22 38 79 37 34 0 16 55 39 52 79 72 36 69 85 69 69 57 52 85 76 98 80 61 54 13 77 62 51 64 69 32 94 48 8 85 90 26 97 81 37 91 92 59 25 64 13 23 87 41 36 90 62 8 54 30 37 94 2 16 65 58 34 69 11 23 61 79 66 22 97 80 7 85 57 56 57 12 42 79 51 2 6 82 73 13 56 81 20 79 24 9 54 36 60 10 53 39 29 95 21 84 30 24 87 77 57 67 34 40 4 61 99 42 19 26 61 20 46 88 0 42 50 31 13 27 19 15 26 44 49 15 14 52 44 1 61 50 13 54 87 9 56 16 89 77 38 59 22 63 63 52 46 81 55 34 78 14 56 66 1 94 8 2 83 1 47 26 59 37 11 96 5 85 6 82 48 64 74 79 35 84 7 72 45 9 47 66 6 41 21 67 29 65 75 60 70 3 9 58 74 83 1 28 24 88 33 11 55 76 54 62 52 24 99 75 5 86 54 42 16 60 92 30 42 80 6 98 41 37 11 78 19 12 80 41 61 5 85 99 22 55 66 21 32 86 61 99 17 0 12 7 53 24 41 27 93 35 17 43 28 36 78 17 97 58 31 82 4 92 42 94 50 9 36 37 16 45 13 62 35 21 39 16 10 44 39 2 27 91 77 56 6 2 91 80 87 46 6 69 88 14 78 19 70 0 60 87 77 75 1 65 59 18 54 17 40 8 31 21 27 42 8 17 0 31 29 36 94 87 43 88 78 26 35 85 77 37 58 9 75 70 4 81 62 56 53 99 99 48 46 8 76 60 3 37 7 48 89 0 93 7 18 20 79 19 87 85 79 75 10 88 75 40 19 76 60 65 11 64 13 1 17 58 93 48 33 90 11 27 48 34 99 72 37 80 74 92 98 6 46 97 76 64 95 98 6 58 35 84 29 5 60 76 33 62 86 73 72 53 58 93 46 6 10 87 59 96 26 90 38 10 99 50 90 94 56 14 54 72 59 16 51 86 81 46 52 88 78 66 91 13 3 48 26 26 25 61 14 90 33 65 32 2 2 88 42 71 29 98 26 93 57 76 88 13 36 64 25 12 59 51 39 34 89 94 97 30 98 39 14 76 35 62 22 44 87 85 56 20 28 78 84 87 97 93 34 92 86 2 2 55 58 64 57 93 51 95 51 61 60 18 36 91 7 25 83 4 8 18 54 49 15 58 61 40 84 81 54 32 7 9 32 2 15 46 59 7 65 14 46 44 42 61 35 87 83 59 45 36 54 12 48 77 82 65 54 98 84 88 66 61 19 38 63 78 18 59 62 60 27 59 48 6 6 46 16 48 60 60 81 93 52 44 93 43 60 65 19 18 56 51 12 44 31 92 86 89 50 63 72 1 96 18 66 4 9 86 50 87 71 34 9 60 11 30 34 86 64 27 33 42 25 93 35 4 80 37 78 98 42 99 85 58 76 27 11 54 16 57 14 59 9 19 85 48 13 38 4 69 39 87 4 32 1 63 29 95 78 96 62 37 25 93 6 81 24 91 57 72 15 34 28 59 20 62 49 22 55 20 59 18 12 12 71 37 86 72 76 45 5 34 94 66 40 19 96 64 86 64 98 22 13 18 3 9 28 30 20 98 73 77 87 97 56 30 46 2 99 87 37 41 83 58 32 0 28 70 40 75 62 3 93 55 17 70 51 15 30 81 99 84 13 32 57 65 42 94 44 82 6 98 92 65 18 37 85 36 97 28 6 72 1 30 3 51 72 1 93 8 71 88 12 2 66 46 58 57 1 6 8 66 64 64 62 93 37 23 12 94 24 89 72 0 28 4 78 10 94 20 84 57 61 36 73 65 3 74 59 87 35 96 91 39 14 98 86 4 53 52 48 36 47 11 36 12 74 80 51 93 54 23 91 36 31 8 43 88 36 41 55 43 75 12 24 53 2 75 78 18 70 13 90 58 93 76 61 86 98 78 35 64 7 3 69 80 70 8 77 19 81 28 96 55 63 61 31 4 5 89 42 79 82 46 49 38 54 32 43 96 28 63 81 57 37 35 90 40 14 14 1 0 99 49 28 48 88 50 40 78 5 52 23 67 98 15 44 77 95 67 36 60 21 86 31 63 52 56 76 69 90 61 17 98 91 50 11 10 93 81 48 92 86 8 97 85 83 11 50 99 18 13 5 2 58 11 27 60 0 6 87 84 39 19 58 45 30 62 56 44 81 10 2 35 90 18 11 45 12 1 64 1 76 63 28 91 19 25 18 69 67 27 15 99 66 7 70 71 74 43 60 62 99 59 22 39 34 43 12 40 1 3 91 75 49 40 8 76 5 9 92 49 15 67 62 84 59 63 40 99 86 40 2 23 77 84 88 87 25 19 34 5 14 13 80 34 6 16 7 31 71 90 88 59 27 38 81 67 2 99 2 56 18 60 66 51 73 0 63 41 15 81 50 83 14 3 82 35 2 96 39 31 93 69 73 43 5 65 55 36 70 41 84 86 76 3 40 14 85 17 53 96 20 32 54 84 85 31 13 49 83 54 95 6 10 7 58 65 32 82 27 62 77 18 96 64 2 17 50 77 69 10 85 64 87 61 24 56 33 87 43 5 1 50 16 40 52 89 28 65 61 57 14 32 27 55 20 44 97 10 91 66 87 41 86 39 51 50 60 94 38 82 40 52 87 3 98 16 85 4 69 24 92 84 53 88 86 74 19 90 82 61 33 89 59 78 35 82 72 60 46 15 83 50 5 87 62 71 61 23 66 78 1 58 49 92 29 79 80 48 99 42 86 12 98 43 32 78 8 69 58 73 51 73 97 88 1 30 49 93 24 42 11 3 36 80 50 74 21 22 95 11 21 31 11 97 20 4 47 16 46 63 50 39 12 35 2 88 94 4 46 16 36 84 55 98 10 62 61 86 74 83 12 61 59 18 53 78 0 64 90 59 82 81 84 35 17 16 65 41 15 54 8 58 2 19 30 48 40 49 31 42 99 9 19 2 38 66 38 89 18 64 75 45 28 2 61 32 26 77 35 69 45 98 69 65 50 33 94 9 76 19 82 34 33 9 76 89 24 39 42 10 71 62 37 63 30 5 94 79 54 32 97 23 7 26 5 24 32 36 41 17 94 17 31 22 9 84 49 33 8 3 62 11 90 51 28 97 65 39 37 62 70 31 73 19 83 99 13 39 58 65 58 42 31 36 26 41 54 88 98 2 16 39 92 33 52 33 67 70 73 96 39 88 64 96 40 38 54 42 12 65 46 92 58 33 32 98 34 9 68 52 43 15 76 78 81 46 0 68 21 97 37 69 77 56 63 71 86 72 9 9 55 81 60 59 99 30 64 49 70 37 43 66 16 35 58 64 65 96 77 55 47 82 50 46 77 72 13 19 4 61 87 93 49 99 75 11 3 35 51 30 61 11 80 84 40 78 13 58 55 72 47 92 57 42 8 8 18 72 21 46 33 62 67 99 51 82 79 75 37 41 18 69 42 94 5 56 38 50 2 83 77 22 66 76 26 42 75 95 32 94 11 71 90 37 16 61 15 73 45 7 12 69 99 72 22 64 70 66 69 91 56 41 9 25 2 71 68 73 92 94 90 78 94 75 86 6 31 33 89 67 32 18 36 21 19 62 7 97 22 19 29 88 60 87 20 25 32 50 66 9 82 71 60 19 54 11 51 45 76 44 58 2 27 23 71 63 1 25 92 17 65 28 85 23 34 56 10 85 76 67 66 29 17 96 43 21 80 6 46 83 31 64 39 57 38 25 5 29 4 92 75 38 88 29 98 5 73 95 77 12 59 42 29 3 40 39 98 27 34 82 66 79 4 90 13 23 9 77 87 6 81 70 10 83 36 56 34 1 30 49 98 36 13 48 3 56 8 70 73 84 6 35 84 39 43 8 77 20 95 21 43 0 47 36 63 52 22 52 25 48 2 51 59 0 69 76 50 98 80 77 29 88 37 63 98 38 93 93 2 25 92 49 15 57 99 91 28 51 76 89 18 97 43 22 82 49 82 14 35 48 32 51 72 35 27 98 73 93 32 42 25 46 9 47 65 80 44 20 95 0 19 26 34 37 96 41 15 75 74 48 60 80 36 58 49 25 4 11 93 28 76 83 26 22 29 66 6 38 58 69 7 80 95 35 88 9 93 83 36 66 39 96 44 16 10 3 28 5 68 25 91 20 80 92 1 0 52 73 29 75 2 78 46 5 3 1 58 33 45 87 60 71 17 28 86 80 52 89 41 61 58 93 97 20 99 86 97 35 92 72 72 71 2 67 66 57 5 80 20 42 51 58 52 80 26 65 61 24 71 99 65 22 37 84 38 36 70 18 38 45 29 46 72 7 2 69 55 82 3 3 34 37 37 89 67 77 49 79 76 52 6 20 74 17 29 81 27 21 30 8 97 44 63 54 69 33 60 1 81 51 85 13 14 91 60 29 59 4 75 59 83 46 5 11 81 66 49 37 80 55 72 60 53 63 46 41 46 15 44 62 67 12 19 2 74 6 83 39 1 69 29 18 72 39 37 28 94 56 62 20 91 99 24 52 93 52 26 62 32 90 17 47 76 38 95 5 77 25 94 30 13 30 87 97 52 53 92 82 89 0 7 77 69 29 55 87 20 89 99 56 53 94 36 59 59 74 67 62 4 99 98 2 78 18 74 44 11 58 80 81 91 28 20 30 62 96 98 75 70 86 12 57 25 95 52 24 96 7 92 46 97 78 98 3 82 65 11 4 98 35 46 19 41 17 40 19 74 2 38 42 92 2 22 70 83 98 60 45 16 75 43 98 32 79 31 32 14 61 49 88 15 92 10 -1\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstring>\\nusing namespace std;\\n\\n\\nint main() {\\n int n;\\n int* data;\\n\\\\[\\n n = 0;\\n // note: this is a correct, but inefficient solution!\\n // better: keep extra space and double the size when full\\n while (true) {\\n int val;\\n cin >> val;\\n if (val == -1) break;\\n\\n // this is the nth item\\n n++;\\n int* old_data = data;\\n data = new int[n];\\n for (int i=0; i<n-1; i++) {\\n data[i] = old_data[i];\\n }\\n data[n-1] = val;\\n if (n != 1) delete[] old_data;\\n }\\n]\\\\\\n // print everything out, twice\\n for (int i=0; i<n; i++) {\\n cout << data[i] << \\" \\";\\n }\\n for (int i=0; i<n; i++) {\\n cout << data[i] << \\" \\";\\n }\\n delete[] data;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(300, '[email protected]', 'cpp/dynamic_mem/nxmboard', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program to dynamically allocate an NxM 2-D array as an array of arrays\\n(i.e. array of pointers) and create a checkerboard pattern of 1''s and 0''s.\\nThen free up all your memory.\\n<p> \\nYour program will be run a million times. So make sure not to leak any\\nmemory!\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"3 4\\", \\"args\\": [\\"\\"]},\\n {\\"stdin\\": \\"8 4\\", \\"args\\": [\\"\\"]}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// Given the values N and M, create an N row x M column\\n// 2D array with a checkerboard pattern\\n\\nint main() {\\n int n, m;\\n cout << \\"Enter the size of the array: \\" << endl;\\n cin >> n >> m;\\n\\\\hide[\\nfor (int __z=0; __z<1000000; __z++) {\\n]\\\\\\n\\n // Select the right type for the nums value which stores\\n // what is returned by ordered_array()\\n \\\\[int**]\\\\ board = new int*[n];\\n\\n for (int i=0; i < n; i++) {\\n \\\\[board[i] = new int[m];]\\\\\\n }\\n\\n\\\\hide[\\nif (__z==999999) {\\n]\\\\\\n for (int i=0; i < n; i++) {\\n for (int j=0; j < m; j++) {\\n board[i][j] = (i+j)%2;\\n }\\n }\\n\\n for (int i=0; i < n; i++) {\\n for (int j=0; j < m; j++) {\\n cout << board[i][j] << \\" \\";\\n }\\n cout << endl;\\n }\\n\\\\hide[\\n}\\n]\\\\\\n \\n // Do your cleanup here\\n \\\\[\\n for (int i=0; i < n; i++) {\\n delete[] board[i];\\n }\\n delete[] board; \\n ]\\\\\\n\\\\hide[\\n}\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(301, '[email protected]', 'cpp/dynamic_mem/examples/rem_quo', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nCreating and destroying in different functions.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint* rem_quo(int x, int y) {\\n int* result = new int[2];\\n result[0] = x % y;\\n result[1] = x / y;\\n return result;\\n}\\n\\nint main() {\\n int* rq = rem_quo(103, 5);\\n cout << rq[0] << \\" \\" << rq[1];\\n delete[] rq;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(302, '[email protected]', 'cpp/dynamic_mem/examples/return_stack', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAccessing deleted stack memory.\\n", "lang": "C++", "example": "True", "cppflags_add": "[\\"-Wno-return-stack-address\\", \\"-Wno-unused-variable\\"]", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint* get_pointer_to(int x) {\\n return &x;\\n}\\n\\nint main() {\\n int* p5 = get_pointer_to(5);\\n int* p11 = get_pointer_to(11);\\n cout << *p5 << endl; \\n}\\n", "tests": "[\\n {}\\n]\\n", "remarks": "for this to work, either you need clang, or a recent enough\\nversion of g++ that supports -Wno-return-local-addr"}', '2015-07-02 22:07:05', 'save', 'open'),
(303, '[email protected]', 'cpp/dynamic_mem/names', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite code to receive 10 names of less than 50 characters but only\\nuse the minimum amount of memory to store those 10 names.\\n<p>\\nToday, add the following features:\\n<ul>\\n<li>Don''t allocate more dynamic memory than absolutely necessary.\\n<li>Add code to change the first two names. Remember to recycle \\n<i>all</i> unused memory!\\n</ul>\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"Tim Chris Jen JackTwentyFourLetterName Phil Bill Raffi Melissa Pete Megan\\\\nAl Grace\\"}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstring>\\nusing namespace std;\\n\\n\\nint main() {\\n // store 10 user names \\n char* names[10];\\n \\n char temp_buf[50];\\n for(int i=0; i < 10; i++) {\\n \\\\[\\n cin >> temp_buf;\\n names[i] = new char[strlen(temp_buf)+1];\\n strcpy(names[i], temp_buf);\\n \\\\show:\\n cin >> names[i]; // this is not correct!\\n ]\\\\\\n }\\n\\n // now print the names\\n for(int i=0; i < 10; i++){\\n cout << names[i] << \\" \\";\\n } \\n cout << endl;\\n\\n // I want to change names[0] and names[1]\\n\\\\[ \\n cin >> temp_buf; // user enters \\"Al\\"\\n delete[] names[0];\\n names[0] = new char[strlen(temp_buf)+1];\\n strcpy(names[0], temp_buf);\\n\\n cin >> temp_buf; // user enters \\"Grace\\"\\n delete[] names[1];\\n names[1] = new char[strlen(temp_buf)+1];\\n strcpy(names[1], temp_buf);\\n \\\\show:\\n cin >> temp_buf; // user enters \\"Al\\"\\n names[0] = temp_buf;\\n cin >> temp_buf; // user enters \\"Grace\\"\\n names[1] = temp_buf;\\n]\\\\\\n\\n // print the names again\\n for(int i=0; i < 10; i++){\\n cout << names[i] << \\" \\";\\n } \\n cout << endl;\\n\\n // now free/delete the memory you allocated\\n\\\\[\\n for(int i=0; i < 10; i++){\\n delete[] names[i];\\n }\\n \\\\show:\\n ;\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(304, '[email protected]', 'cpp/dynamic_mem/examples/bad_delete', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nTrying to delete something invalid.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n\\n\\\\show:\\n int n = 103;\\n int* p = &n;\\n delete p;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(305, '[email protected]', 'cpp/dynamic_mem/examples/recycle', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of new and delete.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int* p = new int; // get address of 4 new bytes of memory\\n *p = 103; // store 103 there\\n cout << *p; \\n delete p; // remember to recycle!\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(306, '[email protected]', 'cpp/pointers/toi', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a function <tt>ctoi</tt> that converts a character to an integer,\\ne.g. <tt>ctoi(''7'')</tt> gives the integer 7. Then write <tt>atoi</tt>,\\nthat converts a C string to an integer.\\n<p>\\nYou don''t need to worry about negative numbers, overflow,\\nor input validation for this exercise.\\n", "lang": "C++func", "tests": "[\\n [\\"check-function\\", \\"ctoi\\", \\"int\\", [\\"char\\"]],\\n [\\"call-function\\", \\"ctoi\\", [\\"''7''\\"]],\\n [\\"call-function\\", \\"ctoi\\", [\\"''0''\\"]],\\n [\\"call-function\\", \\"ctoi\\", [\\"''1''\\"]],\\n [\\"check-function\\", \\"atoi\\", \\"int\\", [\\"char*\\"]],\\n [\\"call-function\\", \\"atoi\\", [\\"\\\\\\"48\\\\\\"\\"]],\\n [\\"call-function\\", \\"atoi\\", [\\"\\\\\\"103\\\\\\"\\"]],\\n [\\"call-function\\", \\"atoi\\", [\\"\\\\\\"2014\\\\\\"\\"]],\\n [\\"call-function\\", \\"atoi\\", [\\"\\\\\\"2\\\\\\"\\"]]\\n]\\n", "source_code": "\\n#include <iostream>\\n\\nint ctoi(char ch) {\\n int ch_as_int = (int)ch;\\n\\\\[\\n int zero_as_int = ''0'';\\n return ch_as_int - zero_as_int;\\n]\\\\\\n}\\n\\nint atoi(char* str) {\\n\\\\[\\n int value = 0;\\n int i = 0;\\n]\\\\\\n while (\\\\[str[i] != ''\\\\0'']\\\\) { // iterate through C string\\n // multiply by 10 and add next ctoi each time\\n\\\\[\\n value *= 10;\\n value += ctoi(str[i]);\\n i++;\\n]\\\\ \\n }\\n\\\\[\\n return value;\\n]\\\\\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(307, '[email protected]', 'cpp/pointers/examples/decay', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nArrays and pointers are often interchangeable.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid f(int* y) {\\n cout << *y;\\n}\\n\\nint main() {\\n int x[] = {103, 104};\\n f(x);\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(308, '[email protected]', 'cpp/pointers/product', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a function <tt>product1</tt> that takes a <tt>double</tt> pointer\\nindicating the start of an array, and an <tt>int</tt> indicating the \\nlength of the array. It should return the product of all the numbers\\nin the array. Do the same thing again with another function <tt>product2</tt>,\\nusing a different approach.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\n// compute product by treating a as an array\\ndouble product1(double* a, int n) {\\n double running_product = 1;\\n for (int i=0; i<n; i++) {\\n \\\\[running_product *= a[i];]\\\\\\n }\\n return running_product;\\n}\\n\\n// compute product by increasing a by one position at a time\\ndouble product2(double* a, int n) {\\n double running_product = 1;\\n while (n > 0) {\\n // multiply in the next number\\n running_product *= \\\\[*a]\\\\;\\n a++; // increase the pointer by one position\\n n--; // one less number to go\\n }\\n return running_product;\\n}\\n\\nint main() {\\n double sample_inputs[3] = {2.5, -1.0, 3.0};\\n // product of all the numbers?\\n cout << product1(sample_inputs, 3) << endl;\\n // try another way\\n cout << product2(sample_inputs, 3) << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(309, '[email protected]', 'cpp/pointers/examples/cout_addr', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nPrints the address of the <tt>cout</tt> object.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n cout << cout; // whoops!\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(310, '[email protected]', 'cpp/pointers/hello', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program <tt>hello</tt> which prints a greeting to the person\\nnamed on the command line. E.g.:\\n<pre><b>$</b> <i>./hello Joe</i></pre>\\nshould print out\\n<pre>Hello, Joe!</pre>\\n", "lang": "C++", "tests": "[\\n {\\"args\\": [\\"Joe\\"]},\\n {\\"args\\": [\\"World\\"]},\\n {\\"args\\": [\\"goodbye\\"]}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\n// main should accept command-line arguments\\nint main(\\\\[int argc, char* argv[]]\\\\) {\\n\\n\\\\[\\n cout << \\"Hello, \\" << argv[1] << \\"!\\";\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(311, '[email protected]', 'cpp/pointers/cmdargs_smartsum_str', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nNow we want to write a program whose first command line argument is the word \\n''integer'' or ''double'' to indicate the type of data that follows. If the\\nfirst argument is ''integer'' then the program should exepect any additional\\ncommand line arguments (if any) to be integers and sum them up displaying\\nthe sum. if the first argument is ''double'' then the program should exepct\\nany additional command line arguments (if any) to be doubles and sum\\nthem up. Again, your program should not crash if the user forgets\\nto provide the ''integer'' or ''double'' keyword, but instead just print \\n''No input''. Also, if no numbers follow the ''double'' or ''integer'' then\\nthe program should just output the sum of 0.\\n\\n<p>\\nSo for example, if someone ran the program as:\\n <tt>./cmdargs1 integer 2 5 19 3</tt>\\n<p>\\nThe output should be:\\n <tt>29</tt>\\n<p>\\nIf someone runs the program as:\\n <tt>./cmdargs1 double 2.25 -1.0 </tt>\\n<p>\\nThe output should be:\\n <tt>1.25</tt>\\n\\n<p>\\nIf someone runs the program as:\\n <tt>./cmdargs1</tt>\\n<p>\\nThe output should be:\\n <tt>No input</tt>\\n", "lang": "C++", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\n#include <cstring>\\nusing namespace std;\\n\\n\\n\\nint main( int argc, char* argv[] ) {\\n\\n int i;\\n\\n if( argc < \\\\[ 2 ]\\\\ ){\\n cout << \\"No input\\" << endl;\\n }\\n else {\\n // check whether the first argument is \\"integer\\"\\n if( \\\\[ strncmp(argv[1],\\"integer\\",7) == 0 ]\\\\ ){\\n int sum = 0;\\n for( \\\\[ i=2 ]\\\\ ; \\\\[ i <= argc-1 ]\\\\ ; i++ ){\\n sum += \\\\[ atoi(argv[i]); ]\\\\\\n }\\n cout << \\"Sum = \\" << sum << endl;\\n }\\n // check whether the first argument is \\"double\\"\\n else if( \\\\[ strncmp(argv[1],\\"double\\",6) == 0 ]\\\\ ){\\n double sum = 0;\\n for( \\\\[ i=2 ]\\\\ ; \\\\[ i <= argc-1 ]\\\\ ; i++ ){\\n sum += \\\\[ atof(argv[i]); ]\\\\\\n }\\n cout << \\"Sum = \\" << sum << endl;\\n }\\n else {\\n cout << \\"Invalid data type to sum\\" << endl;\\n }\\n }\\n return 0;\\n}\\n", "tests": "[\\n {\\"args\\": [\\"integer\\", \\"2\\", \\"5\\", \\"19\\", \\"3\\"]},\\n {\\"args\\": [\\"double\\", \\"2.25\\", \\"-1.0\\"]},\\n {},\\n {\\"args\\": [\\"integer\\", \\"-2\\"]}\\n]\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(312, '[email protected]', 'cpp/pointers/cmdargs_smartsum', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nNow we want to write a program whose first command line argument is a \\n''i'' or ''d'' to indicate ''integers'' or ''doubles'', respectively. If the\\nfirst argument is ''i'' then the program should exepect any additional\\ncommand line arguments (if any) to be integers and sum them up displaying\\nthe sum. if the first argument is ''d'' then the program should exepct\\nany additional command line arguments (if any) to be doubles and sum\\nthem up. Again, your program should not crash if the user forgets\\nto provide the ''d'' or ''i'', but instead just print ''No input''.\\nAlso, if no numbers follow the ''d'' or ''i'' then\\nthe program should just output the sum of 0.\\n\\nSo for example, if someone ran the program as:\\n <tt>./cmdargs1 i 2 5 19 3</tt>\\nThe output should be:\\n <tt>29</tt>\\n\\nIf someone runs the program as:\\n <tt>./cmdargs1 d 2.25 -1.0 </tt>\\nThe output should be:\\n <tt>1.25</tt>\\n\\nIf someone runs the program as:\\n <tt>./cmdargs1</tt>\\nThe output should be:\\n <tt>No input</tt>\\n", "lang": "C++", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\n#include <cstring>\\nusing namespace std;\\n\\nint main(int argc, char* argv[]) {\\n\\n int i;\\n\\n if (argc < \\\\[2]\\\\) {\\n cout << \\"No input\\" << endl;\\n }\\n else {\\n // if first argument is character i, add doubles\\n if (\\\\[argv[1][0]]\\\\ == ''i'') {\\n int sum = 0;\\n for (\\\\[i=2]\\\\; \\\\[i < argc]\\\\; i++) {\\n sum += \\\\[atoi(argv[i])]\\\\;\\n }\\n cout << \\"Sum = \\" << sum << endl;\\n }\\n // check whether the first argument is the character d\\n else if( \\\\[ argv[1][0] ]\\\\ == ''d'' ){\\n double sum = 0;\\n for( \\\\[ i=2 ]\\\\ ; \\\\[ i <= argc-1 ]\\\\ ; i++ ){\\n sum += \\\\[ atof(argv[i]); ]\\\\\\n }\\n cout << \\"Sum = \\" << sum << endl;\\n }\\n else {\\n cout << \\"Invalid data type to sum\\" << endl;\\n }\\n\\n }\\n return 0;\\n}\\n", "tests": "[\\n {\\"args\\": [\\"i\\", \\"2\\", \\"5\\", \\"19\\", \\"3\\"]},\\n {\\"args\\": [\\"d\\", \\"2.25\\", \\"-1.0\\"]},\\n {},\\n {\\"args\\": [\\"i\\", \\"-2\\"]}\\n]\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(313, '[email protected]', 'cpp/pointers/swap', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nDefine a function <tt>exchange</tt> that takes two <tt>int</tt> pointers\\nas inputs. It should exchange the values held at the locations\\npointed to by its arguments.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid exchange(int* a, \\\\[int* b]\\\\)\\n{\\n\\\\[\\n int tmp = *a;\\n *a = *b;\\n *b = tmp;\\n]\\\\\\n}\\n\\nint main() {\\n int x = 4, y = 5;\\n cout << \\"Before exchange, x is \\" << x << \\" and y is \\" << y << endl;\\n exchange(&x, &y);\\n cout << \\"After exchange, x is \\" << x << \\" and y is \\" << y << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(314, '[email protected]', 'cpp/pointers/examples/array_adds', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nPrints the address of an array and its elements.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int x[4];\\n \\n cout << &x << endl;\\n cout << &(x[0]) << endl;\\n cout << &(x[1]) << endl;\\n cout << &(x[2]) << endl;\\n cout << &(x[3]) << endl;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(315, '[email protected]', 'cpp/pointers/examples/refops', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nExamples of fundamental pointer operations.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int i = 5;\\n int* addr; // type declaration\\n addr = &i; // addr gets the address of i\\n\\n // two dereferences, one read, one write:\\n cout << *addr << endl; // what is stored at addr?\\n *addr = 10; // store 10 where addr points\\n\\n cout << i << endl; // what is stored in i?\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(316, '[email protected]', 'cpp/pointers/examples/addr', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nPrints the address of several variables.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int a;\\n int b[10];\\n double c;\\n int d;\\n \\n cout << \\"address of a: \\" << &a << endl;\\n cout << \\"address of b: \\" << &b << endl;\\n cout << \\"address of c: \\" << &c << endl;\\n cout << \\"address of d: \\" << &d << endl;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open');
INSERT INTO `ws_sheets` (`id`, `author`, `problem`, `definition`, `time`, `action`, `sharing`) VALUES
(317, '[email protected]', 'cpp/pointers/increase_by', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program <tt>increase_by</tt> \\nthat takes a command-line argument <tt>n</tt> and then adds <tt>n</tt>\\nto every number on input, and prints them out one per line.\\nFor example\\n<pre>\\n./increase_by 5\\n</pre>\\nwith input\\n<pre>\\n1\\n2\\n100\\n</pre>\\nshould print\\n<pre>\\n6\\n7\\n105\\n</pre>\\n", "lang": "C++", "tests": "[\\n {\\"stdin\\": \\"1\\\\n2\\\\n100\\", \\"args\\": [\\"5\\"]},\\n {\\"stdin\\": \\"1\\\\n0\\\\n3\\", \\"args\\": [\\"1\\"]},\\n {\\"stdin\\": \\"11\\\\n22\\", \\"args\\": [\\"-10\\"]}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\nint main(int argc, char* argv[]) {\\n\\n // parse command-line argument, save as variable n\\n\\\\[\\n int n = atoi(argv[1]);\\n]\\\\\\n // put each number from standard input as \\"read\\", one at a time\\n int read;\\n while (cin >> read) {\\n cout << \\\\[read + n]\\\\ << endl;\\n }\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(318, '[email protected]', 'cpp/pointers/roll2', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWe want to write a program that simulates the roll of two individual\\n6-sided dice (fair dice with equal probability of landing on 1-6). We\\nwant to declare the variables d1 and d2 in main() but set their values\\nvia the help of two other functions: <tt>roll_one()</tt> and \\n<tt>roll_two()</tt>.\\n<ul>\\n<li>\\n<tt>roll_one()</tt> should set the value of only one die at a time.\\n<li>\\n<tt>roll_two()</tt> should take both die and call <tt>roll_one()</tt> once for each\\ndie value.\\n</ul>\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\n// Takes pointer to integer and changes the pointed-at value\\n// to be a random number between 1 and 6\\nvoid roll_one(\\\\[int*]\\\\ die) {\\n \\\\[ *die ]\\\\ = 1 + rand()%6; \\n}\\n\\n// Takes two pointers to integers and changes the pointed-at values\\n// to be random numbers between 1 and 6\\nvoid roll_two(\\\\[int*]\\\\ die1, \\\\[int*]\\\\ die2) {\\n // Call the roll_one() function twice to set die1 & die2\\n \\\\[\\n roll_one(die1);\\n roll_one(die2);\\n ]\\\\\\n}\\n\\nint main() {\\n int d1=0, d2=0; // two integers representing dice values\\n cout << \\"Before: d1 is \\" << d1 << \\" and d2 is \\" << d2 << endl;\\n\\n srand(0); // not acutally random, to facilitate testing\\n\\n // We want to change the contents of d1 and d2 in the function\\n // roll_one(). But we will first pass them through roll_two()\\n // which will call roll_one() twice...once for each die\\n\\n // Pass appropriate values for d1 and d2 as the arguments \\n roll_two(\\\\[&d1, &d2]\\\\);\\n\\n // d1 and d2 should be changed by the previous call to roll_two()\\n // so let''s check their value.\\n cout << \\"After: d1 is \\" << d1 << \\" and d2 is \\" << d2 << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(319, '[email protected]', 'cpp/pointers/cmdargs_sum', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program <tt>cmdargs_sum</tt> \\nthat adds up all of its command-line arguments.\\n<!--We want to write a program that adds a series of integers provided\\nby the user as command line arguments. We have declared a <tt>sum</tt>\\nvariable for you. You need to figure out the loop counter initialization\\nand condition as well as how to convert each command line argument\\nto an integer before it is added. Also, if there are no arguments\\nyour program should not crash but just output th sum of 0.-->\\n\\nFor example, if you run\\n <pre>./cmdargs_sum 2 5 19 3</pre>\\nThe output should be:\\n <pre>29</pre>\\nAssume the inputs are all integers.\\n\\n<!--If some one runs the program as:\\n <tt>./cmdargs1</tt>\\nThe output should be:\\n <tt>0</tt>-->\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"args\\": [\\"2\\", \\"5\\", \\"19\\", \\"3\\"]},\\n {},\\n {\\"args\\": [\\"-2\\"]}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\n// main should accept command-line arguments\\nint main(\\\\[int argc, char* argv[]]\\\\) {\\n\\n int sum = 0;\\n int i;\\n\\n // convert and add up each argument\\n for (\\\\[i=1]\\\\; \\\\[i < argc]\\\\; i++) {\\n sum += \\\\[atoi(argv[i])]\\\\;\\n }\\n\\n cout << \\"Sum is \\" << sum << endl;\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(320, '[email protected]', 'cpp/pointers/divide', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nWrite a program <tt>divide</tt> \\nthat is capable of performing integer or floating-point division.\\nFor example\\n<pre>\\n./divide d 12.3 10.0\\n</pre>\\nasks for division of doubles and prints <tt>1.23</tt>, while\\n<pre>\\n./divide i 10 3\\n</pre> \\nasks for integer division and should print <tt>3</tt>.\\n\\n<p>\\nPrint <tt>wrong number of arguments</tt> if the number of arguments is wrong.\\nYou don''t need to do any further error checking for this exercise.\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "lang": "C++", "tests": "[\\n {\\"args\\": [\\"d\\", \\"12.3\\", \\"10.0\\"]},\\n {\\"args\\": [\\"i\\", \\"10\\", \\"3\\"]},\\n {\\"args\\": [\\"d\\", \\"7\\", \\"2\\"]},\\n {\\"args\\": [\\"i\\", \\"7\\", \\"2\\"]},\\n {\\"args\\": [\\"d\\", \\"1.8\\", \\"1.2\\"]},\\n {\\"args\\": [\\"d\\", \\"45\\"]},\\n {\\"args\\": [\\"i\\", \\"-2\\", \\"-3\\", \\"-4\\"]}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <cstdlib>\\nusing namespace std;\\n\\nint main(int argc, char* argv[]) {\\n\\n if (\\\\[argc != 4]\\\\) {\\n cout << \\"wrong number of arguments\\" << endl;\\n }\\n else {\\n // if first argument starts with ''i'', divide integers\\n if (argv[1][0] == \\\\[''i'']\\\\) {\\n // parse arguments as integers\\n \\\\[int]\\\\ x = atoi(argv[2]);\\n\\\\[\\n int y = atoi(argv[3]);\\n]\\\\\\n // divide and print\\n cout << x / \\\\[y]\\\\;\\n }\\n else {\\n // parse as doubles, divide and print\\n double x = \\\\[atof(argv[2])]\\\\;\\n\\\\[\\n double y = atof(argv[3]);\\n cout << x / y;\\n]\\\\\\n }\\n }\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(321, '[email protected]', 'cpp/pointers/examples/args_example', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nAn example of <tt>argc</tt> and <tt>argv</tt>.\\n", "example": "True", "lang": "C++", "tests": "[\\n {\\"args\\": [\\"-al\\"]},\\n {\\"args\\": [\\"funky\\", \\"pineapple\\"]},\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main(int argc, char* argv[]) {\\n cout << \\"argc is \\" << argc << endl;\\n // each argv[i] is a char* (a C string)\\n for (int i = 0; i < argc; i++) {\\n cout << \\"argv[\\" << i << \\"] is \\" << argv[i] << endl;\\n }\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(322, '[email protected]', 'cpp/pointers/reset_ptr', '{"attempts_until_ref": "1", "sharing": "open", "description": "\\nIn a previous exercise we tried to write a function that would\\nreset a variable, but it failed to work because of C++''s pass-by-value \\nsemantics.\\n<p>We can fix it now! Use pointers to do so.\\n", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nvoid reset(\\\\[int* x\\\\show:int x]\\\\)\\n{\\n\\\\[\\n *x = 0;\\n\\\\show:\\n x = 0;\\n]\\\\\\n}\\n\\nint main() {\\n int num = 103;\\n reset(\\\\[&num\\\\show:num]\\\\);\\n cout << num;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(323, '[email protected]', 'cpp/pointers/examples/ptrmath', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nPointer arithmetic.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n int x[] = {20, 14};\\n int* y = &(x[0]); // start at first element\\n y = y + 1;\\n cout << *y; // what''s y pointing to?\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(324, '[email protected]', 'cpp/cs104/examples/memref', '{"remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n", "sharing": "open", "attempts_until_ref": "1", "description": "\\nUse this program to test various methods of returning an object or \\npointer/reference to an object from a function.\\n", "example": "True", "lang": "C++", "tests": "[\\n {}\\n]\\n", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nclass Item {\\npublic:\\n Item(int w, string y) { _w = w; _y = y; }\\n int _w; \\n string _y;\\n};\\n\\n\\\\[\\n// Function to build an item\\n\\\\show:\\nItem buildItem()\\n{\\n Item x(4, \\"hi\\");\\n return x;\\n\\n}\\n]\\\\\\n\\nint main() \\n{\\n\\\\[\\n // Code to call buildItem and receive return value\\n\\\\show:\\n Item i = buildItem();\\n cout << i._w << \\" \\" << i._y << endl;\\n\\n]\\\\\\n return 0;\\n}\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(325, '[email protected]', 'cpp/cs104/hello', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nFix this program so that it outputs <pre>Hello, world!</pre>\\nfollowed by a newline character.\\n", "lang": "C++", "source_code": "\\n#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n\\\\[\\n cout << \\"Hello, world!\\" << endl;\\n\\\\show:\\n cout << Hello, <<\\n cout << world!\\n]\\\\\\n return 0;\\n}\\n", "tests": "[\\n {}\\n]\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(326, '[email protected]', 'cpp/cs104/merge', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a function to merge two sorted ranges of a vector. Assum the values in teh input vector between [s1,e1) and [s2,e2) are non-overlapping, sorted sequences of integers. Create a new vector ''retval'' that has the merged, sorted values from those two ranges. \\n\\nFor example, if input is { 2, 5, 3, 4 } and s1=0,e1=2, s2=2,e2=4 should yield a merged result of { 2, 3, 4, 5}\\n", "lang": "C++", "source_code": "\\n#include <vector>\\n#include <iostream>\\nusing namespace std;\\n\\nvector<int> merge(vector<int>& input, int s1, int e1, int s2, int e2)\\n{\\n vector<int> result;\\n\\\\[\\n while(s1 < e1 && s2 < e2){\\n if(input[s1] < input[s2]){\\n result.push_back(input[s1++]);\\n }\\n else {\\n result.push_back(input[s2++]);\\n }\\n }\\n while(s1 < e1){\\n result.push_back(input[s1++]);\\n }\\n while(s2 < e2){\\n result.push_back(input[s2++]);\\n }\\n]\\\\\\n return result;\\n}\\n\\nvoid print_vec(vector<int> input){\\n for(vector<int>::iterator it = input.begin();\\n it != input.end();\\n ++it){\\n cout << *it << \\" \\";\\n }\\n cout << endl;\\n}\\nint main()\\n{\\n int d1[] = {2,9,10,16,3,4,5,6};\\n vector<int> v1(d1, d1+8);\\n print_vec( merge(v1,0,4,4,8) );\\n\\n int d2[] = {1,2,3,4,7,8,5,6};\\n vector<int> v2(d2, d2+8);\\n print_vec( merge(v2,4,6,6,8) );\\n\\n vector<int> v3;\\n print_vec( merge(v3,0,0,0,0) );\\n\\n return 0;\\n\\n}\\n", "tests": "[\\n {}\\n]\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(327, '[email protected]', 'cpp/cs104/llsum_tail', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a recursive function to sum up the integers in a linked list. In this approach, try to use tail recursion where you sum values on the way down the list (i.e. sum the current value and then pass that down the chain via a recursive call).\\n", "lang": "C++", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nstruct Item {\\n Item(int v, Item* n) { val = v; next = n; }\\n int val; \\n Item* next;\\n};\\n\\n// prototype\\nint llsum(Item* head);\\n\\n// prototype any helper functions here if you wish...\\n// As a challenge try to make the return type void\\n\\\\[\\nvoid llsum_helper(Item* head, int& curr_sum);\\n]\\\\\\n\\n// llsum implementation\\nint llsum(Item* head)\\n{\\n\\\\[\\n int sum = 0;\\n llsum_helper(head, sum);\\n return sum;\\n]\\\\\\n}\\n\\n// implement any helper function here\\n\\\\[\\nvoid llsum_helper(Item* head, int& curr_sum)\\n{\\n if(head == NULL) return;\\n else {\\n curr_sum += head->val;\\n llsum_helper(head->next, curr_sum);\\n }\\n}\\n]\\\\\\n\\nint main() \\n{\\n\\n cout << llsum(NULL) << endl;\\n Item* head = new Item(4, new Item(7, new Item(9, new Item(6, NULL))));\\n cout << llsum(head) << endl;\\n\\n}\\n", "tests": "[\\n {}\\n]\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n"}', '2015-07-02 22:07:05', 'save', 'open'),
(328, '[email protected]', 'cpp/cs104/llsum_head', '{"sharing": "open", "attempts_until_ref": "1", "description": "\\nWrite a recursive function to sum up the integers in a linked list. In this approach, try to use head recursion where you sum values on the way back up the list.\\n", "lang": "C++", "source_code": "\\n#include <iostream>\\n#include <string>\\nusing namespace std;\\n\\nstruct Item {\\n Item(int v, Item* n) { val = v; next = n; }\\n int val; \\n Item* next;\\n};\\n\\n// prototype\\nint llsum(Item* head);\\n\\n// prototype any helper functions here if you wish\\n\\\\[\\n\\n]\\\\\\n\\n// llsum implementation\\nint llsum(Item* head)\\n{\\n\\\\[\\n if(head == NULL)\\n return 0;\\n else\\n return head->val + llsum(head->next);\\n]\\\\\\n}\\n\\n// implement any helper function here\\n\\\\[\\n\\n]\\\\\\n\\nint main() \\n{\\n\\n cout << llsum(NULL) << endl;\\n Item* head = new Item(4, new Item(7, new Item(9, new Item(6, NULL))));\\n cout << llsum(head) << endl;\\n\\n}\\n", "tests": "[\\n {}\\n]\\n", "remarks": "Originally by Mark Redekopp ([email protected]) and Dave Pritchard ([email protected])\\n"}', '2015-07-02 22:07:05', 'save', 'open');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;