#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int main()
{
list<int> coll;
list<int>::iterator start_pos,end_pos;
int i;
int N,K;
cin >>N>>K;
for(i=1;i<=N;i++)
{
coll.push_back(i);
}
for(i = 0;i<N;i+=K)
{
start_pos = find(coll.begin(),coll.end(),i+1);
if(i+K>N)
{
break;
}
end_pos = find(coll.begin(),coll.end(),i+K+1);
reverse(start_pos,end_pos);
}
while(!coll.empty())
{
cout<<coll.front()<<' ';
coll.pop_front();
}
cout<<endl;
}
#include<list>
#include<algorithm>
using namespace std;
int main()
{
list<int> coll;
list<int>::iterator start_pos,end_pos;
int i;
int N,K;
cin >>N>>K;
for(i=1;i<=N;i++)
{
coll.push_back(i);
}
for(i = 0;i<N;i+=K)
{
start_pos = find(coll.begin(),coll.end(),i+1);
if(i+K>N)
{
break;
}
end_pos = find(coll.begin(),coll.end(),i+K+1);
reverse(start_pos,end_pos);
}
while(!coll.empty())
{
cout<<coll.front()<<' ';
coll.pop_front();
}
cout<<endl;
}
No comments:
Post a Comment
తెలుగులో వ్రాయడానికి http://www.google.com/ime/transliteration/ ఉపయోగించండి.