List of all available Websheets
Viewing cpp/cppstrings/circ_shift by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | A <i>circular shift</i> of a string <tt>S</tt> by <tt>n</tt> spots is defined to be taking the first <tt>n</tt> characters and moving them to the end of the string. For example, <tt>STOP</tt> shifted by <tt>1</tt> would yield <tt>TOPS</tt>. <tt>STRING</tt> circular shifted by <tt>2</tt> spots would yield <TT>RINGST</tt>. <p> Write a function that takes an input string and <tt>n</tt> the number of spots to shift by and returns the circular shifted result (i.e. a string). <tt>string circular_shift(string S, int n)</tt> <p> Hint: <tt>substr</tt> and <tt>+=</tt> or <tt>append</tt> could be helpful functions. |
Public permissions | |
Engine | |
Template / Reference solution |
using namespace std; string circular_shift(string s, int n) { \[ return (s+s).substr(n, s.size()); ]\ } |
C++ test suite See manual | [ ["check-function", "circular_shift", "string", ["string", "int"]], ["call-function", "circular_shift", ["\"STOP\"", "1"]], ["call-function", "circular_shift", ["\"STOP\"", "3"]], ["call-function", "circular_shift", ["\"STRING\"", "3"]], ["call-function", "circular_shift", ["\"BYE\"", "1"]], ["call-function", "circular_shift", ["\"find()\"", "5"]] ] |
Solution visibility |
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'.