C++ HackerRank|AND xor OR
来源:互联网 发布:浮雕设计用什么软件 编辑:程序博客网 时间:2024/06/05 10:47
- Dashboard
- Data Structures
- Stacks
- AND xor OR
#include <iostream>#include <stack>#include <vector>using namespace std;int main(int argc, char const *argv[]){ int n, max = 0, temp; cin >> n; vector<int> arr(n); stack<int> index; for (int i = 0; i < n; ++ i) { cin >> arr[i]; while (! index.empty()) { temp = arr[i] ^ arr[index.top()]; // (((a & b) ^ (a | b)) & (a ^ b)) == a ^ b max = max > temp ? max : temp; if (arr[index.top()] > arr[i]) { index.pop(); } else { break; } } index.push(i); } cout << max << endl; return 0;}
0 0