1 Star 1 Fork 0

AlbertDarren / CCFCSPPastProblems

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
CPP1-201403-1.cpp 574 Bytes
一键复制 编辑 原始数据 按行查看 历史
AlbertDarren 提交于 2022-04-03 00:51 . first commit
#include <iostream>
#include <algorithm>
using namespace std;
#define N 500
int a[N]={0};
int main_2()
{
int n,cnt=0;
cin>>n;
for (int i=0;i<n ;i++ )
{
cin>>a[i];
}
sort(a,a+n);
int left=0,right=n-1;
while (left<right&&a[left]<0&&a[right]>0)
{
if (-a[left]==a[right])
{
cnt++;
left++;
right--;
}
else if (-a[left]>a[right])
{
left++;
}
else
{
right--;
}
}
cout << cnt << endl;
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/AlbertDarren_admin/ccfcsppast-problems.git
git@gitee.com:AlbertDarren_admin/ccfcsppast-problems.git
AlbertDarren_admin
ccfcsppast-problems
CCFCSPPastProblems
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891