cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Displaying combinations of string withou
Displaying combinations of string without repetition with the help of circular queue
Aug 30, 2018 at 11:30am UTC
AtomicRogue1
(1)
Input :
n= 4
PRSW
Output :
RSWP
SWPR
WPRS
PRSW
Aug 30, 2018 at 12:43pm UTC
Ganado
(6806)
Looks hard. What have you tried?
Aug 30, 2018 at 1:31pm UTC
jonnin
(11429)
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 UTC
Topic archived. No new replies allowed.