Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main(void)
  6. {
  7. int n, k;
  8. cin >> n;
  9. cin >> k;
  10.  
  11. int sit = 1;
  12. int i = 1;
  13. while(k >0)
  14. {
  15. if(sit == 1){
  16. cout << i;
  17. sit = 2;
  18. k--;
  19. }
  20. else{
  21. cout << n - i +1;
  22. sit = 1;
  23. i++;
  24. k--;
  25. }
  26. cout << " ";
  27. }
  28. if(sit == 1)
  29. {
  30. for(int j=n-i+1;j>i;j--)
  31. cout << j << " ";
  32. cout << i;
  33. }
  34. else{
  35. for(int j=i+1;j<n-i+1;j++)
  36. cout << j << " ";
  37. cout << n-i+1;
  38. }
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement