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

List of all available Websheets


Viewing cpp/var-expr/4swap by goodney. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
This program reads in 4 strings, representing the top, bottom, left, right 
colors of the sides
of a square. Your program should <i>rotate the square 90 degrees clockwise</i>
and output the top, bottom, left, right colors after the rotation. 
<p>
For example if the input is <tt>red green blue yellow</tt> then the rotation
looks like this:
<div><img src="http://cscircles.cemc.uwaterloo.ca/websheets/images/FourSwap.ipe.png"></div>
and the output should be <tt>blue yellow green red</tt>.
<p>
Hint: use a variant of the <i>swap idiom</i>.
Public permissions remove
Engine
Template / Reference solution
 
#include <iostream>
#include <string>
using namespace std;
int main() {
   string top, bottom, left, right;
   cin >> top >> bottom >> left >> right;
   // now do something clever to update the variables!
\[
   string t = top;
   top = left;
   left = bottom;
   bottom = right;
   right = t;
]\
   cout << top << " " << bottom << " " << left << " " << right;
   return 0;
}
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": "red green blue yellow"},
   {"stdin": "fuschia vermilion salmon ochre"}
]
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'.