SHARE
TWEET

Untitled

a guest Feb 27th, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. /*
  6.  */
  7. int pageCount(int n, int p) {
  8.  //n -> pages in book
  9.  //p -> page u wan to get
  10. int howMany =0;
  11. map <int,int> book;
  12.     book.insert(pair<int,int>(0,1));
  13.  for(int i = 1; i <= n - 2; i ++){
  14.    book.insert(pair<int,int>(i+1,i+2));
  15.    i = i + 1;
  16.  }
  17.  if(n%2==0){
  18.  book.insert(pair<int,int>(n,0));
  19. }
  20. int score =0;
  21. int h1;
  22.  for(auto it = book.cbegin(); it != book.cend(); ++it)
  23.  {
  24.      if(p == it->first || p == it->second){
  25.         h1 = score;
  26.      }
  27.      score ++;
  28.  }
  29.  int score2 =0;
  30.  int h2;
  31.  for(auto it = book.cend(); it != book.cbegin(); --it)
  32.  {
  33.      if(p == it->first || p == it->second){
  34.         h2 = score2;
  35.      }
  36.      score2 ++;
  37.  }
  38. h2 = h2-1;
  39. if( p == n){
  40.     howMany =0;
  41. }else{
  42. if(h1>h2){
  43.   howMany = h2;
  44. }
  45. else{
  46.   howMany = h1;
  47. }
  48. }
  49.  return howMany;
  50.  
  51. return 0;
  52. }
  53.  
  54. int main()
  55. {
  56.     ofstream fout(getenv("OUTPUT_PATH"));
  57.  
  58.     int n;
  59.     cin >> n;
  60.     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  61.  
  62.     int p;
  63.     cin >> p;
  64.     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  65.  
  66.     int result = pageCount(n, p);
  67.  
  68.     fout << result << "\n";
  69.  
  70.     fout.close();
  71.  
  72.     return 0;
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top