void Qmax(int n){ rm.r = 0; for (int i = -1000; i < 1000;i=i+1) for (int j = -1000; j < 1000; j=j+1){ ca.mux = i; ca.muy = j; for (int h = 0; h < 1; h++){ if (cmp1(qdx(ca), qdy(ca)) && cmp1(qdx(ca), (qzl(ca, Circle[h]) - (Circle[h].r))) && cmp1(qdy(ca), (qzl(ca, Circle[h]) - (Circle[h].r)))){ int pd=1; for (int t = 0;t<n;t++) if (cmp2(ca.mux, Circle[t].mux) && cmp2(ca.muy, Circle[t].muy)) pd = 0; if (pd) if ((qdx(ca)>rm.r) && !cmp2(qdx(ca),rm.r)) { rm.mux = i, rm.muy = j; rm.r = qdx(ca); } } } if (n>1) Qmax2(n); if (n>2) Qmax3(n); } Circle[n].mux = rm.mux; Circle[n].muy = rm.muy; Circle[n].r = rm.r; }
/* takes a comma separated list of log masks. Return 0 if error. */ int qemu_str_to_log_mask(const char *str) { const QEMULogItem *item; int mask; const char *p, *p1; p = str; mask = 0; for (;;) { p1 = strchr(p, ','); if (!p1) { p1 = p + strlen(p); } if (cmp1(p,p1-p,"all")) { for (item = qemu_log_items; item->mask != 0; item++) { mask |= item->mask; } } else { for (item = qemu_log_items; item->mask != 0; item++) { if (cmp1(p, p1 - p, item->name)) { goto found; } } return 0; } found: mask |= item->mask; if (*p1 != ',') { break; } p = p1 + 1; } return mask; }
int cmp(t_linez *lz, t_sh *term, t_linez *hist) { if (!ft_strncmp("fg", lz->ep_l, 2) || lz->ep_l[0] == '%') { if ((lz->ep_l[0] == '%' && lz->ep_l[1] == ' ') || (lz->ep_l[0] == 'f' && lz->ep_l[2] == ' ')) second_static(NULL, lz->ep_l, NULL); else if ((lz->ep_l[0] == '%' && lz->ep_l[1] && lz->ep_l[1] != ' ') || (lz->ep_l[0] == 'f' && lz->ep_l[2] && lz->ep_l[2] != ' ')) return (0); job_cont(SIGCONT); return (term->status = 1); } else if (!ft_strncmp("history", lz->ep_l, 7)) { if (lz->ep_l[7] && lz->ep_l[7] != ' ') return (0); return (ft_history(&hist, term, '\0')); } else if (!ft_strncmp("export", lz->ep_l, 6)) { if (lz->ep_l[6] == ' ') return (term->status = export_var(term, lz)); ft_putendl_fd("export: usage: 'export var'", 2); term->status = 0; return (1); } return (cmp1(lz, term, hist)); }
object Factor(bigint* num) { num=copybigint(num,NULL); if (num->size<0) { Printf("- "); num->size=-num->size; } { bigint* temp=mkbigint(num->size); _digit p; int i=0; if (num->size==0) { Printf("0"); goto quit; } for (p=2; p<=trial_limit; p+= inc[i++]) { if (i==array_size(inc)) i=3; /* after |37-31| wrap to difference |11-7| */ if (copybigint(num,temp),div1(temp,p)==0) { _index n; _digit pn=p; int e=1; copybigint(temp,num); for (n=1; pn<=MaxDigit/p; ++n) pn*=p; /* highest $p^n$ fitting in |_digit| */ for (; div1(temp,pn)==0; e+=n) copybigint(temp,num); /* find factors $p^n$ */ if (n>1) /* then there might be some factors |p| left */ for (copybigint(num,temp); div1(temp,p)==0; ++e) copybigint(temp,num); /* factors |p| */ Printf("%ld",(long)p); if (e>1) Printf("^%ld",(long)e); if (cmp1(num,1)==0) goto quit; /* last factor was found */ Printf(" * "); } } printbigint(num,0); if (num->size>2) Printf(" (Last factor need not be a prime)"); quit: Printf("\n"); freemem(num); freemem(temp); } return (object) NULL; }
int main(void) { cmp1(NAN, 4); cmp2(NAN, NAN); assert(a == 0); assert(b == 1); return 0; }
/* takes a comma separated list of log masks. Return 0 if error. */ int qemu_str_to_log_mask(const char *str) { const QEMULogItem *item; int mask; const char *p, *p1; p = str; mask = 0; for (;;) { p1 = strchr(p, ','); if (!p1) { p1 = p + strlen(p); } if (cmp1(p,p1-p,"all")) { for (item = qemu_log_items; item->mask != 0; item++) { mask |= item->mask; } #ifdef CONFIG_TRACE_LOG } else if (strncmp(p, "trace:", 6) == 0 && p + 6 != p1) { trace_enable_events(p + 6); mask |= LOG_TRACE; #endif } else { for (item = qemu_log_items; item->mask != 0; item++) { if (cmp1(p, p1 - p, item->name)) { goto found; } } return 0; found: mask |= item->mask; } if (*p1 != ',') { break; } p = p1 + 1; } return mask; }
int main() { ///////////////////////////////////////////////////////////////////// /// Exmaple for use: ///////////////////////////////////////////////////////////////////// std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> dis (-100, 100); std::vector <int> arr (25); std::vector <int> arr1 (25); std::vector <int> arr2 (25); for(int i = 0 ; i < 25; i++) { arr [i] = dis (gen); arr1 [i] = arr [i]; arr2 [i] = arr [i]; } for (int i = 0 ; i < 25 ; i ++) { std::cout << arr [i] << " "; } std::cout << std::endl; //////////////////////////////////////////////////////////////////// /// Use Standart Sort //////////////////////////////////////////////////////////////////// std::sort (begin (arr1), end (arr1), cmp2 ()); for (int i = 0 ; i < 25 ; i ++) { std::cout << arr1 [i] << " "; } std::cout << std::endl; ///////////////////////////////////////////////////////////////////// /// Use atdc sort ///////////////////////////////////////////////////////////////////// atdc_sort (std::begin (arr2), std::end (arr2), cmp1 ()); for(int i = 0 ; i < (int)arr2.size () ; i ++) { std::cout << arr2 [i] << " "; } std::cout << std::endl; return 0; }
void divide(char s[]) { int len=strlen(s); for(int i=0;i<n;i++) { if(len==dic[i].len) { cmp0(s,dic[i]); } else if(len==dic[i].len-1) { cmp1(s,dic[i]); } else if(len==dic[i].len+1) { cmp2(s,dic[i]); } } }
int main() { int a = A, b = B; unsigned ua = uA; unsigned ub = uB; unsigned uc = uC; printf("cmp1(%d, %d) = %d\n", a, b, cmp1(a, b)); printf("cmp2(%d, %d) = %d\n", a, b, cmp2(a, b)); printf("cmp3(%d) = %d\n", a, cmp3(a)); printf("cmp4(%d) = %d\n", a, cmp4(a)); printf("cmp5(%d) = %d\n", a, cmp5(a)); printf("cmp6(%d) = %d\n", a, cmp6(a)); printf("cmp7(%d) = %d\n", a, cmp7(a)); printf("cmp8(%d) = %d\n", a, cmp8(a)); printf("cmp9(%d, %d) = %d\n", a, b, cmp9(a, b)); printf("cmp10(%d, %d) = %d\n", a, b, cmp10(a, b)); printf("cmp11(%d) = %d\n", a, cmp11(a)); printf("cmp12(%d) = %d\n", a, cmp12(a)); printf("cmp13(%d) = %d\n", a, cmp13(a)); printf("cmp14(%d) = %d\n", a, cmp14(a)); printf("cmp15(%d) = %d\n", a, cmp15(a)); printf("cmp16(%d) = %d\n", a, cmp16(a)); printf("cmp17(%d, %d) = %d\n", a, b, cmp17(a, b)); printf("cmp18(%d, %d) = %d\n", a, b, cmp18(a, b)); printf("cmp19(%u, %u) = %d\n", ua, ub, cmp19(ua, ub)); printf("cmp20(%u, %u) = %d\n", ua, ub, cmp20(ua, ub)); printf("cmp21(%u, %u) = %d\n", ua, ub, cmp21(ua, ub)); printf("cmp22(%u, %u) = %d\n", ua, ub, cmp22(ua, ub)); printf("cmp23(%u, %u) = %d\n", ua, ub, cmp23(ua, ub)); printf("cmp19(%u, %u) = %d\n", ua, uc, cmp19(ua, uc)); printf("cmp20(%u, %u) = %d\n", ua, uc, cmp20(ua, uc)); printf("cmp21(%u, %u) = %d\n", ua, uc, cmp21(ua, uc)); printf("cmp22(%u, %u) = %d\n", ua, uc, cmp22(ua, uc)); printf("cmp23(%u, %u) = %d\n", ua, uc, cmp23(ua, uc)); return 0; }
bool Vector4Test::test() { // ctor tests Vector4d vvector4_test( 8., 1., 6., 3. ); for ( size_t i = 0; i < 4; ++i ) { if ( vvector4_test.xyzw[i] != _vector4.xyzw[i] ) { cout << "test: Vector4::Vector4( scalars ) failed!" << endl; failed(); assert( 0 ); } } Vector4d uvector4_test( Vector3d( 8., 1., 6. ), 3. ); for ( size_t i = 0; i < 4; ++i ) { if ( uvector4_test.xyzw[i] != _vector4.xyzw[i] ) { cout << "test: Vector4::Vector4( vector3, scalar ) failed!" << endl; failed(); assert( 0 ); } } // setter test Vector4d tvector4_test( 0., 0., 0., 0. ); tvector4_test.set( 8., 1., 6., 3. ); for ( size_t i = 0; i < 4; ++i ) { if ( tvector4_test.xyzw[i] != _vector4.xyzw[i] ) { cout << "test: Vector4::set( ... ) failed!" << endl; failed(); assert( 0 ); } } // operator= test tvector4_test.set( 0., 0., 0., 0. ); tvector4_test = uvector4_test; for ( size_t i = 0; i < 4; ++i ) { if ( tvector4_test.xyzw[i] != _vector4.xyzw[i] ) { cout << "test: Vector4::operator=( ... ) failed!" << endl; failed(); assert( 0 ); } } // length() tests if ( _vector4.lengthSquared() != 110. ) { cout << "test: Vector4::length( ... ) failed!" << endl; failed(); assert( 0 ); } if ( _vector4.length() != sqrt( 110. ) ) { cout << "test: Vector4::length( ... ) failed!" << endl; failed(); assert( 0 ); } // normalise() test tvector4_test.set( 8. / sqrt( 110. ), 1. / sqrt( 110. ), 6. / sqrt( 110. ), 3. / sqrt( 110. ) ); vvector4_test.normalise(); for ( size_t i = 0; i < 4; ++i ) { if( tvector4_test.xyzw[i] - vvector4_test.xyzw[i] < -1e-13 || tvector4_test.xyzw[i] - vvector4_test.xyzw[i] > 1e-13 ) { cout << "test: Vector4::normalise( ... ) failed!" << endl; failed(); assert( 0 ); } } // vector/scalar operations vvector4_test.set( 7., 0., 5., 2. ); if ( vvector4_test + 1. != _vector4 ) { cout << "test: Vector4::operator+( scalar ) failed!" << endl; failed(); assert( 0 ); } if ( vvector4_test != _vector4 - 1. ) { cout << "test: Vector4::operator-( scalar ) failed!" << endl; failed(); assert( 0 ); } uvector4_test.set( 4., 0.5, 3., 1.5 ); if ( uvector4_test * 2 != _vector4 ) { cout << "test: Vector4::operator*( scalar ) failed!" << endl; failed(); assert( 0 ); } if ( _vector4 / 2. != uvector4_test ) { cout << "test: Vector4::operator/( scalar ) failed!" << endl; failed(); assert( 0 ); } vvector4_test += 1.; if ( vvector4_test != _vector4 ) { cout << "test: Vector4::operator+=( scalar ) failed!" << endl; failed(); assert( 0 ); } uvector4_test *= 2.; if ( uvector4_test != _vector4 ) { cout << "test: Vector4::operator*=( scalar ) failed!" << endl; failed(); assert( 0 ); } uvector4_test.set( -8., -1., -6., -3. ); if ( -uvector4_test != _vector4 ) { cout << "test: Vector4::operator-() failed!" << endl; failed(); assert( 0 ); } // vector/vector operations tvector4_test.set( 2., -1., 3., 1. ); uvector4_test.set( 6., 2., 3., 2. ); vvector4_test.set( 4., -1., 2., 3. ); if ( tvector4_test + uvector4_test != _vector4 ) { cout << "test: Vector4::operator+( vector ) failed!" << endl; failed(); assert( 0 ); } if ( _vector4 - uvector4_test != tvector4_test ) { cout << "test: Vector4::operator-( vector ) failed!" << endl; failed(); assert( 0 ); } if( tvector4_test * vvector4_test != _vector4 ) { cout << "test: Vector4::operator*( vector ) failed!" << endl; failed(); assert( 0 ); } if ( _vector4 / tvector4_test != vvector4_test ) { cout << "test: Vector4::operator/( vector ) failed!" << endl; failed(); assert( 0 ); } uvector4_test += tvector4_test; if ( uvector4_test != _vector4 ) { cout << "test: Vector4::operator+=( vector ) failed!" << endl; failed(); assert( 0 ); } vvector4_test *= tvector4_test; if ( vvector4_test != _vector4 ) { cout << "test: Vector4::operator*=( vector ) failed!" << endl; failed(); assert( 0 ); } // dot() test if ( _vector4.dot( tvector4_test ) != 36. ) { cout << "test: Vector4::dot( vector4 ) failed! " << _vector4 << " . " << tvector4_test << " = " << _vector4.dot( tvector4_test ) << endl; failed(); assert( 0 ); } // operator == / != tests if( vvector4_test != _vector4 ) { cout << "test: Vector4::operator !=( vector ) failed!" << endl; failed(); assert( 0 ); } if ( tvector4_test == _vector4 ) { cout << "test: Vector4::operator==( vector ) failed!" << endl; failed(); assert( 0 ); } // min/max component tests if ( _vector4.getMinComponent() != 1. ) { cout << "test: Vector4::getMinComponent() failed!" << endl; failed(); assert( 0 ); } if ( _vector4.getMaxComponent() != 8. ) { cout << "test: Vector4::getMaxComponent() failed!" << endl; failed(); assert( 0 ); } vec4f cmp0( 1.0, 2.5, 4.0, 1.0 ); vec4f cmp1( 3.0, 2.0, 5.0, 2.0 ); size_t smaller = cmp0.smaller( cmp1 ); size_t greater = cmp0.greater( cmp1 ); if ( smaller != 13 || greater != 2 ) { failed(); assert( 0 ); } smaller = cmp0.smaller( cmp1, 3 ); greater = cmp0.greater( cmp1, 3 ); if ( smaller != 8 || greater != 0 ) { failed(); assert( 0 ); } if ( ok ) cout << "Vector4: all tests passed!" << std::endl; return ok; }
int main() { int ball[12],cmp2_result,cmp3_result,diff=12,err,i; char w=' '; FILE *fin=fopen("input.txt","r"); FILE *fout=fopen("output.txt","w"); for(i=0; i<12; i++) ball[i]=fgetc(fin); fclose(fin); switch(cmp1(ball)) { case 0: cmp2_result=cmp2(ball,0,0,0,&err); break; case 1: cmp2_result=cmp2(ball,0,4,1,&err); break; case 2: cmp2_result=cmp2(ball,4,0,1,&err); break; default: break; } switch(cmp2_result) { case 0: w='l'; cmp3_result=cmp3(ball,err,1,w); break; case 1: w='h'; cmp3_result=cmp3(ball,err,1,w); break; case 2: cmp3_result=cmp3(ball,err,0,w); break; case 3: w='h'; cmp3_result=cmp3(ball,err,1,w); break; case 4: cmp3_result=cmp3(ball,err,0,w); break; case 5: w='l'; cmp3_result=cmp3(ball,err,1,w); break; default: break; } switch(cmp3_result) { case 0: diff=11; w='h'; break; case 1: if(err) diff=3; else diff=7; w='h'; break; case 2: diff=err+2; break; case 3: diff=err+1; break; case 4: diff=err; break; case 5: diff=err; w='l'; break; default: break; } fputs("the error ball is:",fout); fprintf(fout,"%d\n",(diff+1)); fputs("It is ",fout); if(w=='h') fputs("heavy\n",fout); else fputs("light\n",fout); fclose(fout); return 0; }
bool cmp2(int x,int y) { return cmp1(a[x],a[y]); }