vector<int> twoSum(vector<int> &numbers, int target) { int i,j,k,n; n=numbers.size(); vector<pair<int,int> >p3a(n); for(i=0;i<n;i++) { p3a[i].first=numbers[i]; p3a[i].second=i; } sort(p3a.begin(),p3a.end()); i=0;j=n-1; vector<int>ans; while(i<j) { if(p3a[i].first+p3a[j].first==target) { ans.push_back(p3a[i].second+1); ans.push_back(p3a[j].second+1); sort(ans.begin(),ans.end()); return ans; } else if(p3a[i].first+p3a[j].first>target) j--; else i++; } }
void OSGDebugDrawInterface::AddAxes(const dtEntity::Matrix& m, const dtEntity::Vec4f& color, float size, float duration, bool depthTestEnabled) { float arroww = 0.1f; osg::Vec3 p0(0, 0, 0); osg::Vec3 p1(0, 0, 1); osg::Vec3 p2(0, 1, 0); osg::Vec3 p3(1, 0, 0); osg::Vec3 p1a(arroww, 0, 1 - arroww); osg::Vec3 p1b(-arroww, 0, 1 - arroww); osg::Vec3 p2a(arroww, 1 - arroww, 0); osg::Vec3 p2b(-arroww, 1 - arroww, 0); osg::Vec3 p3a(1 - arroww, 0, arroww); osg::Vec3 p3b(1 - arroww, 0, -arroww); std::vector<osg::Vec3> lines(18); lines[0] = m * p0; lines[1] = m * p1; lines[2] = m * p0; lines[3] = m * p2; lines[4] = m * p0; lines[5] = m * p3; lines[6] = m * p1; lines[7] = m * p1a; lines[8] = m * p1; lines[9] = m * p1b; lines[10] = m * p2; lines[11] = m * p2a; lines[12] = m * p2; lines[13] = m * p2b; lines[14] = m * p3; lines[15] = m * p3a; lines[16] = m * p3; lines[17] = m * p3b; AddLines(lines, color, size, duration, depthTestEnabled); }
int main(void) { p3a(); p3b(); p3c(); return 0; }
int main( int argc, char *argv[] ) { if( argc < 2 ) { printf("Expecting at least one argument. Please try again\n"); } else if(argc==2) { if(atoi(argv[1])==3) { printf("Expecting two arguments for this part. Please try again.\n"); } else { if(atoi(argv[1])==1) { p1(); } else if(atoi(argv[1])==2) { p2(); } else { printf("Incorrect argument supplied.\n"); } } } else if(argc==3) { if(atoi(argv[1])!=3) { printf("Expecting two arguments only for Part 3. Please try again.\n"); } else { if(atoi(argv[2])==1) { p3a(); } else if(atoi(argv[2])==2) { p3b(); } } } else { printf("The argument supplied is %s\n", argv[1]); } }