解题思路:
注意事项:
参考代码:
#include<iostream>
#include<algorithm>
using namespace std;
int a[100001];
int main()
{
int n,m;
int i;
//输入
cin>>n;
for(i=0;i<n;i++){
cin>>a[i];
}
cin>>m;
//排序
sort(a,a+n);
//二分
int mid,high,low;
high=n-1;
low=0;
while(low<=high){
//如果等于m,输出并停止程序
if(a[low]+a[high]==m){
cout<<a[low]<<" "<<a[high];
return 0;
}
//如果相加小于m,那么最低下标++
else if(a[low]+a[high]<m){
low++;
}
//如果相加大于m,那么最高下标--
else{
high--;
}
}
cout<<"No";
return 0;
}
0.0分
0 人评分
简单编码 (C++代码)(这里推荐用switch)浏览:960 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:521 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:515 |
回文数(一) (C语言代码)浏览:731 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:451 |
1113题解浏览:786 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:792 |
杨辉三角 (C语言代码)浏览:484 |
判定字符位置 (C语言代码)浏览:795 |
简单的a+b (C语言代码)浏览:415 |