Advertisement
Noblessed

Code bài 1 bằng C++ cực chill

Mar 20th, 2023 (edited)
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | Source Code | 0 0
  1. #include<bits/stdc++.h>
  2. #define endl '\n'
  3. using namespace std;
  4.  
  5. int n;
  6.  
  7. int diff(int x, int y) {
  8.     int diff = x ^ y;
  9.     int base = 1;
  10.     for (int i = 1; i <= n; i++, base <<= 1)
  11.         if (base == diff)
  12.             return i;
  13.     return 0;
  14. }
  15.  
  16. void solve(){
  17.     cin >> n;
  18.     for (int i = 0; i < n*n; i++) {
  19.         for (int j = 0; j < n*n; j++) {
  20.             cout << diff(i, j) << " ";
  21.         }
  22.         cout << endl;
  23.     }
  24. }
  25.  
  26. void fastIO(){
  27.     ios_base::sync_with_stdio(false); //cin.tie(0); cout.tie(0);
  28. }
  29.  
  30. int main(){
  31.     fastIO();
  32.     int t = 1; //cin >> t;
  33.     while(t--) solve();
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement