two nums

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <vector> using namespace std; void twonum(const vector<int> & rvec, const int & tar) { int temptar = tar; int prevInd = 0; int turn = 1; for(int ind =0; ind < rvec.size(); ind++) { if(temptar-rvec[ind] == 0 && turn == 0) { cout<<"the two indices are "<<prevInd <<", "<<ind<<endl; return; } else { turn = 1; temptar = tar; } if(temptar-rvec[ind] > 0 && turn == 1) { temptar = temptar - rvec[ind]; prevInd = ind; turn--; } } cout<<"Target doesn't exist"<<endl; } int main() { int target = 0; cin>> target; vector<int> vec{1,6,7,3,6,8,2,9}; twonum(vec, target); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines