iis怎么建设网站内容,杭州做搜索引擎网站的公司,东莞南城网站建设公司,东莞关键词seo答题
用两个优先队列#xff0c;一个记录正数升序排序#xff0c;一个记录负数降序排序#xff0c;然后在两个队列都不为空的情况下取二者top相加与0比较大小#xff0c;如果等于0#xff0c;那么相反数的数目增加一对并同时弹出队列#xff0c;如果小于0#xff0c;那…
答题
用两个优先队列一个记录正数升序排序一个记录负数降序排序然后在两个队列都不为空的情况下取二者top相加与0比较大小如果等于0那么相反数的数目增加一对并同时弹出队列如果小于0那么弹出正数队列如果大于0那么弹出负数队列
#includeiostream
#includequeue
#includevector
using namespace std;int main() {priority_queueint,vectorint,greater positive;priority_queueint negative;int n, temp, sum 0;cin n;while (n--) {cin temp;if (temp 0)positive.push(temp);else negative.push(temp);}while (!positive.empty() !negative.empty()) {temp positive.top() negative.top();if (temp 0) {positive.pop();negative.pop();sum;} else if (temp 0) {positive.pop();} else {negative.pop();}}cout sum;
}