"Brian MacBride" <ma******@ix.netcom.com> wrote:
Sure, it is only a few lines of code.
If you do someone's homework assignment, do it in a form utterly useless
for them! At minimum, it should be plain to the person correcting the
homework, that the student hadn't written it. Here is an example:
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
int main()
{
int n = 0, j = 0, k = 0;
if (std::cin >> n >> j >> k && 1 <= n && n <= 100 && 0 <= j && 0 <= k)
{
std::vector<int> v;
struct vp {
vp(std::vector<int> const& v): mv(v) {}
std::vector<int> const& mv;
friend std::ostream& operator<< (std::ostream& o, vp const& v) {
std::copy(v.mv.begin(), v.mv.end(),
std::ostream_iterator<int>(o << "[ ", " "));
return o << "]";
}
};
for (int i = 0; i < n; std::cout << vp(v) << "\n")
v.push_back((std::rotate(v.begin(),
v.begin() + j % (i? i: j),
v.end()), ++i));
std::vector<int> s(v.size());
for (std::vector<int>::iterator i = s.end();
!v.empty() && std::cout << vp(v) << "\n"
<< (*--i = v[k % v.size()]) << "\n";
v.erase(v.begin()))
std::rotate(v.begin(), v.begin() + k % v.size(), v.end());
std::copy(s.begin(), s.end(),
std::ostream_iterator<int>(std::cout << vp(v) << "\n", "\n"));
}
else
std::cerr << "you goofed!\n";
}
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>