Android ANR异常
#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; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。