#include<iostream>
using namespace std;
bool find_num(int data[] , int length , int sum , int &first_num , int &second_num)
{
if(length < 1)
return true;
int begin = 0;
int end = length - 1;
while(begin < end)
{
int current_sum = data[begin] + data[end];
if(current_sum == sum)
{
first_num = data[begin];
second_num = data[end];
return true;
}
else if(current_sum > sum)
end--;
else
begin++;
}
return false;
}
int main()
{
int data[] = {1 ,3 , 4 , 7 , 12 , 15};
int length = sizeof(data)/sizeof(int);
int first_num = 0 ;
int second_num = 0;
int sum = 11;
if(find_num(data , length , sum , first_num , second_num))
{
cout<<first_num<<" "<<second_num<<endl;
}
else
cout<<"不存在"<<endl;
return 0;
}
Android ANR异常,布布扣,bubuko.com
Android ANR异常