Aug 30, 2018 at 11:30am Aug 30, 2018 at 11:30am UTC
Input :
n= 4
PRSW
Output :
RSWP
SWPR
WPRS
PRSW
Aug 30, 2018 at 12:43pm Aug 30, 2018 at 12:43pm UTC
Looks hard. What have you tried?
Aug 30, 2018 at 1:31pm Aug 30, 2018 at 1:31pm UTC
so the order is fixed and the starting point varies.
easy enough. there are probably cleaner ways, but just iteration gets it done
vector<char> buff(4) = {'P','R','S','W'}; //You will want to read all this in
for(out = 0; out < buff.size(); out++)
{
for(in = 0; in < buff.size(); out++)
{
cout << buff[ (out+in)%buff.size()];
}
cout << endl;
}
so, basically, we used sensible iteration to make a standard vector look like a circular queue. you can cook up a full blown data structure for this instead, but its a lot of trouble for not much real gain.
Last edited on Aug 30, 2018 at 1:35pm Aug 30, 2018 at 1:35pm UTC