Not logged in. Log in with GitHub. About Websheets.

List of all available Websheets


Viewing cpp/arrays/echo by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
Write a program that takes an input <tt>n</tt>, 
then <tt>n</tt> more <tt>string</tt> inputs.
You may assume <tt>n</tt> is less than 100.
Print out all of the strings, one per line, and then print them 
all out again. For example if the input is
<pre>
3
repeat
me
plz
</pre>
then the output should be
<pre>
repeat
me
plz
repeat
me
plz
</pre>
Public permissions remove
Engine
Template / Reference solution
 
#include <iostream>
#include <string>
using namespace std;
int main() {
\[
   int n;
   cin >> n;
   string words[100];
   // fill out the array
   for (int i=0; i<n; i++)
      cin >> words[i];
   // output twice
   for (int i=0; i<n; i++)
      cout << words[i] << endl;
   for (int i=0; i<n; i++)
      cout << words[i] << endl;
]\
}
C++ test suite
json list of stdin/args tests
e.g. [{"stdin":"hi", "args":["4", "5"]},
{"stdin":"noargs"}]

to just run once with no input use [{}]
 
[
   {"stdin": "3\nrepeat\nme\nplz"},
   {"stdin": "6\nwe\nwill\nwe\nwill\nrock\nyou"},
   {"stdin": "1\nabracadabra"}
]
Solution visibility remove


Optional properties:

Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.