Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. void main()
  2. {
  3.     int k = 9; // 9 code
  4.     int n = 60; // 60 student
  5.  
  6.     int p = 1;
  7.     int q = 2;
  8.  
  9.     int locA = p * 2 + q - 1; // location of A
  10.     int locB = (locA > k ? locA - k : (locA + k > n ? locA + k : -1)); // location of B, -1 if invalid
  11.     if (locB == -1) { cout << "Location not found (-1)" << endl; return; }
  12.  
  13.     int code = (locA > k ? locA % k : locA); // B need to match this code
  14.    
  15.     cout << "Code needed to be matched: " << code << endl;
  16.  
  17.     int v = locB % 2 + 1;
  18.     int u = (locB - v) / 2;
  19.  
  20.     cout << "B is need to be at row: " << u << "  position: " << v << endl;
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement