void days(char c[20], int l, int k) { int s = 0; if ((c[l] == '0')&&(c[l+1]!='0')) { s = (int)c[l + 1] - 49; ones(s); } else if (c[l] == '1') { if (c[l + 1] != '0') { s = (int)c[l + 1] - 49; tens(s); } else { s = (int)c[l + 1] - 48; ten(s); } } else if ((c[l] != '1') && (c[l + 1] != '0')) { s = (int)c[l] - 49; ten(s); s = (int)c[l + 1] - 49; ones(s); } else if (((c[l] != '1')) && (c[l + 1] == '0')) { s = (int)c[l] - 49; ten(s); } }
int main() { char v[2][3], c, i=3, j; while((c=getchar())&'0') v[0][--i] = c-'0'; i=3; while((c=getchar())&'0') v[1][--i] = c-'0'; int ans[4] = {0,}; for(i=0; i<3; i++) { for(j=0; j<3; j++) { ans[i] += (((int)v[0][j] * v[1][i])*ten(j)); } ans[3]+=(ans[i]*ten(i)); } for(i=0; i<4; i++) printf("%d\n", ans[i]); return 0; }
void mpq_manager<SYNCH>::display_decimal(std::ostream & out, mpq const & a, unsigned prec) { mpz n1, d1, v1; get_numerator(a, n1); get_denominator(a, d1); if (is_neg(a)) { out << "-"; neg(n1); } mpz ten(10); div(n1, d1, v1); display(out, v1); rem(n1, d1, n1); if (is_zero(n1)) goto end; // number is an integer out << "."; for (unsigned i = 0; i < prec; i++) { mul(n1, ten, n1); div(n1, d1, v1); SASSERT(lt(v1, ten)); display(out, v1); rem(n1, d1, n1); if (is_zero(n1)) goto end; // number is precise } out << "?"; end: del(ten); del(n1); del(d1); del(v1); }
NumberPtr Number::Read(Input &input) { Integer ten(10); auto_ptr<Integer> intValue(new Integer); while(input.Current() >= '0' && input.Current() <= '9') { Integer digit(input.Current() - '0'); intValue = intValue->Times(&ten)->Plus(&digit); input.Next(); } // Process part after decimal separator if(input.Current() == '.') { // Cast the current value to float (just to prevent compiler warning) auto_ptr<MachineReal> realValue(new MachineReal(intValue)); input.Next(); auto_ptr<MachineReal> factor(new MachineReal(1.0)); MachineReal tenth(0.1); while(input.Current() >= '0' && input.Current() <= '9') { MachineReal digit(input.Current() - '0'); factor = factor->Times(&tenth); realValue = realValue->Plus(factor->Times(&digit).get()); input.Next(); } return NumberPtr(realValue); } else return NumberPtr(intValue); }
int year(int c[10], int l) { int i, j, e = 0, t, o; j = l; for (i = 0; i <= l; i++) { if (c[i + 1] == 0 && c[i + 2] == 0||c[i]==1&&c[i+1]==0&&e==0) { if (j == 3&&e==0) { onces(c[i]); printf("Thousand "); j--; e++; } else if (j == 2 && e != 0) { onces(c[i]); printf("hundred "); e = 0; } } else if (i % 2 == 0) { if (c[i] == 1) { t = (c[i] * 10) + c[i + 1]; ten(t); i++; e++; j--; } else if(c[i] > 1) { tens(c[i]); e++; j--; } else if (c[i]==0 && e!=0 && c[i-1]!=0) { printf("hundred"); e++; j--; } } else { onces(c[i]); } e++; } }
void conversion() { sinterval_t a(stime_t::msec(hires)); sinterval_t b(stime_t::usec(hires)); sinterval_t c(stime_t::nsec(hires)); cout << "hires == " << hires << endl; cout << "====== conversion statics ====" << endl; cout << "msec " << (stime_test_t)a << ' ' << a << endl; cout << "usec " << (stime_test_t)b << ' ' << b << endl; cout << "nsec " << (stime_test_t)c << ' ' << c << endl; cout << "====== output conversion integers ======" << endl; cout << "msec " << a.msecs() << endl; cout << "usec " << b.usecs() << endl; cout << "nsec " << c.nsecs() << endl; a = stime_t::msec(25); b = stime_t::usec(25); c = stime_t::nsec(25); cout << "====== output conversion integers 2 ======" << endl; cout << "msec " << a.msecs() << ' ' << b.msecs() << ' ' << c.msecs() << endl; cout << "usec " << a.usecs() << ' ' << b.usecs() << ' ' << c.usecs() << endl; cout << "nsec " << a.nsecs() << ' ' << b.nsecs() << ' ' << c.nsecs() << endl; cout << "======= output casts =======" << endl; a = stime_test_t(tod, hires); struct timeval tv; tv = a; cout << (stime_test_t)a << ": " << tv << endl; #ifdef USE_POSIX_TIME struct timespec ts; ts = a; cout << (stime_test_t)a << ": " << ts << endl; #endif cout << "test overflow of output casts" << endl; a = stime_test_t(0, HR_SECOND-1); tv = a; cout << (stime_test_t)a << ": " << tv << endl; #ifdef USE_POSIX_TIME ts = a; cout << (stime_test_t)a << ": " << ts << endl; #endif /* XXX what is this supposed to test? */ stime_test_t ten(10,0); stime_test_t tenn(ten); tenn.normalize(); cout << "stime_t(10,0) == " << ten; cout << tenn << endl; }
int foo (int k, int j) { if (k >= ten()) { if (j > k) { /* We should fold this to if (1). */ if (j > zero()) return j; } } return j+1; }
EPtr FunctionNumeric::apply_evaled(EPtr arguments, State &state) { Number *value = Element::as_number(Pair::car(arguments)); if (! value) return state.error("first argument must be numeric"); Fractional v = value->value(); BigInt fractions(5); Element *next = Pair::cdr(arguments); if (next) { Number *digits = Element::as_number(Pair::car(next)); if (! digits) return state.error("second argument must be numeric"); if (Pair::cdr(next)) return state.error("too many arguments"); if (digits->value().denominator() != BigInt(1)) return state.error("digits must be integer"); fractions = digits->value().numerator(); } Fractional rounding(1, 2); Fractional ten(10); Fractional one(1); Fractional zero(0); for (Fractional i = fractions; zero < i; i = i - one) { rounding = rounding / ten; } v = v + rounding; std::ostringstream buffer; Fractional fraction(0); if (v.denominator() > BigInt(1)) { BigInt rest = v.numerator() % v.denominator(); Fractional full = v - Fractional(rest, v.denominator(), v.isNegative()); buffer << full; fraction = v - full; } else { buffer << v; fraction = Fractional(0); } buffer << "."; BigInt bi_one(1); for (BigInt cur(0); cur < fractions; cur = cur + bi_one) { fraction = fraction * ten; BigInt rest = fraction.numerator() % fraction.denominator(); Fractional full = fraction - Fractional(rest, fraction.denominator(), fraction.isNegative()); buffer << full; fraction = fraction - full; } return state.creator()->new_string(buffer.str()); }
void mpq_manager<SYNCH>::set(mpq & a, char const * val) { reset(a.m_num); mpz ten(10); _scoped_numeral<mpz_manager<SYNCH> > tmp(*this); char const * str = val; bool sign = false; while (str[0] == ' ') ++str; if (str[0] == '-') sign = true; while (str[0] && (str[0] != '/') && (str[0] != '.') && (str[0] != 'e') && (str[0] != 'E')) { if ('0' <= str[0] && str[0] <= '9') { SASSERT(str[0] - '0' <= 9); mul(a.m_num, ten, tmp); add(tmp, this->mk_z(str[0] - '0'), a.m_num); } ++str; } TRACE("mpq_set", tout << "[before] a: " << to_string(a) << "\n";);
int MultiDigit::from_string(char * s) { if (!strncmp(s,"0x",2)) { // return from_hexstring(s+2); } else { MultiDigit d, accum2(0), ten(10); from_number(0); while (((*s) >= '0') && ((*s) <= '9')) { d.from_number(*s-'0'); multiply_multi_digit(*(this), ten, &accum2); add_multi_digit(accum2, d, this); } } }
int day(int a[50], int j) { int t = 0, o; int i = 0, c = 0; for (i = 0; i <= j; i++) { t = (t * 10) + a[i]; } for (i = 0; i <= j; i++) { if (t > 32) { printf(" invalid date"); break; } if (c == 2 && a[i]>0||i==j&&c<2) { t = a[i]; onces(t); } if (a[i] == 2 && c <= i && i != j || a[i] == 3 && c <= i && i != j) { t = a[i]; tens(t); c = c + 2; } else if (a[i] == 1 && c <= i && i != j) { ten(t); c = c + 3; } else if (a[i] == 0 && c <= i) { c = c + 2; } } }
int main(){ fstream in("input.txt"); std::string num; in >> num; clock_t start = clock(); Factorization comp = Factorization(num.c_str()); BigNumber test(num.c_str()); //инициализируем вектор степеней десятки Ipp32u deg = ceil((test.BitSize() - 1) / log2f(10)); ++deg; BigNumber ten(10); BigNumber tmp(1); for (unsigned i = 0; i <= deg; ++i){ BigNumber::decPowers.push_back(tmp); tmp *= ten; } //std::map<BigNumber, Ipp32u> factor = comp.getFactor(); //cout << "Factorization completed! " << endl<<"time = "<<clock() - start << endl; //for (auto& i : factor){ // cout << i.first; // if (i.second > 1) // cout << "^" << i.second; // cout << endl; //} QuadraticSieve q(test); q.doFactorization(); //cout << q.modPow(BigNumber(3), BigNumber(1024), BigNumber(7)); cout << "Complete " << clock() - start << endl; ofstream out("TS_log.txt"); out << "Complete " << clock() - start << endl; system("pause"); return 0; }
//right param is litter one Bigint operator *(Bigint num1,Bigint num2) { #if 1 static bool s_first = 1; if(num2.getlength() == 0|| num1.getlength() ==0|| strcmp(num2.getptr(), "0") == 0 || strcmp(num1.getptr(), "0") == 0) return "0"; if (s_first && num1<num2){num1.swap(num2);} s_first = 0; #endif int nlen1 = num1.getlength(); int nlen2 = num2.getlength(); //memory leak ptr_array<char> sum = new char[nlen1+1+1]; memset(sum.getptr() , 0, nlen1+2); int flag = 0; int nindex = 0; for(; nindex < nlen1; nindex++) { int num = (num2.getindex(nlen2-1)-'0')*(num1.getindex(nlen1 - nindex - 1)-'0') +flag; sum[nindex] = num%10 +'0'; flag = num/10; } if(flag) sum[nindex] = flag +'0'; makestr(sum.getptr()); //memory leak ptr_array<char> pleft =new char[nlen2+1]; strcpy(pleft.getptr(), num2.getptr()); pleft[num2.getlength() - 1] = 0; // Bigint temp =ten(num1*pleft); return (Bigint(sum.getptr()) + ten(num1*pleft.getptr())); }
int go(int argc){ seal::PluginManager::get()->initialise(); pool::URIParser p; p.parse(); pool::IFileCatalog lcat; pool::IFileCatalog * cat = &lcat; cat->setWriteCatalog(p.contactstring()); cat->connect(); cat->start(); pool::IDataSvc *svc = pool::DataSvcFactory::instance(cat); // Define the policy for the implicit file handling pool::DatabaseConnectionPolicy policy; policy.setWriteModeForNonExisting(pool::DatabaseConnectionPolicy::CREATE); // policy.setWriteModeForExisting(pool::DatabaseConnectionPolicy::OVERWRITE); policy.setWriteModeForExisting(pool::DatabaseConnectionPolicy::UPDATE); svc->session().setDefaultConnectionPolicy(policy); svc->transaction().start(pool::ITransaction::UPDATE); std::vector<pool::Ref<TT<T1> > > refs; std::string vten[] = { "0","1","2","3","4","5","6","7","8","9","10"}; std::vector<std::string> ten(vten,vten+11); std::vector<std::string>::const_iterator s = ten.begin(); for (;s!=ten.end();s++) { std::string f = std::string("E")+ (*s); std::string c = std::string("C")+ (*s); pool::Ref<TT<T1> > o1(svc, new TT<T1>); pool::Placement place(f, pool::DatabaseSpecification::PFN, c, ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o1.markWrite(place); refs.push_back(o1); } pool::Ref<TMe > o6(svc, new TMe); { pool::Placement place("E0", pool::DatabaseSpecification::PFN, "C0", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o6.markWrite(place); } pool::Ref<TVoid> o7(svc, new TVoid); { pool::Placement place("E0", pool::DatabaseSpecification::PFN, "C0", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o7.markWrite(place); } svc->transaction().commit(); svc->session().disconnectAll(); // cat->commit(); // cat->start(); svc->transaction().start(pool::ITransaction::UPDATE); pool::Ref<TT<T1> > o1(svc, new TT<T1>); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o1.markWrite(place); } pool::Ref<TT<T2> > o2(svc, new TT<T2>); { pool::Placement place("EN", pool::DatabaseSpecification::PFN, "N", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o2.markWrite(place); } // o1->bs.push_back(o2); // o2->c=o1; pool::Collection<TT<T1> > collection(svc, "ImplicitCollection", "PFN:DN", "L", pool::ICollection::READ) ; pool::Collection<TT<T1> >::Iterator iter = collection.select(); while (iter.next()) { std::cout << iter.ref().toString() << std::endl; std::cout << (*iter).i << std::endl; } std::vector<pool::Ref<TT<T1> > >::const_iterator r = refs.begin(); int n=0; for (;r!=refs.end();r++) { n++; std::cout << r->toString() << std::endl; if (n==2||n==8) r->markUpdate(); } svc->transaction().commit(); svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::READ); std::cout << "o6 " << o6.isNull() << " " << (*o6->me.get()).i << std::endl; std::cout << "o7 " << o7.isNull() << " " << (*o7->get()).i << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); cat->commit(); delete svc; return 0; }
Limbs::Limbs(Encoding &g) :genome(g) { //create Traits Trait spindly(1, -3, 3, "spindly"); Trait thin(1, -2, 1, "thin"); Trait thick(-2, 3, 0, "thick"); Trait round(3, -1, -1, "round"); Trait zero(0, 0, 3, "0"); Trait one(1, 1, 3, "1"); Trait two(3, 1, -3, "2"); Trait three(-1, 1, 3, "3"); Trait four(3, 1, -3, "4"); Trait five(-1, 1, 3, "5"); Trait six(2, 1, -3, "6"); Trait seven(-2, 2, 3, "7"); Trait eight(0, 3, 2, "8"); Trait nine(-3, 2, 3, "9"); Trait ten(-2, 3, 2, "10"); Trait eleven(-3, 2, 3, "11"); Trait twelve(-3, 3, 2, "12"); Trait thirteen(-3, 2, 3, "13"); Trait fourteen(-3, 3, 3, "14"); Trait fifteen(-3, 2, 3, "15"); //create all maps if (thicknessK.empty() ) { thicknessK["spindly"] = 0; thicknessK["thin"] = 1; thicknessK["thick"] = 2; thicknessK["round"] = 3; thicknessM[0] = spindly; thicknessM[1] = thin; thicknessM[2] = thick; thicknessM[3] = round; numM[0] = zero; numM[1] = one; numM[2] = two; numM[3] = three; numM[4] = four; numM[5] = five; numM[6] = six; numM[7] = seven; numM[8] = eight; numM[9] = nine; numM[10] = ten; numM[11] = eleven; numM[12] = twelve; numM[13] = thirteen; numM[14] = fourteen; numM[15] = fifteen; } //decode the number of limbs so that there can //only be a non-zero even number of them number = decodeNumber(); int numValue = std::stoi(number); if (numValue % 2 != 0) { encodeNumber(numValue + 1); number = decodeNumber(); } if (numValue == 0) { encodeNumber(2); number = decodeNumber(); } thickness = decodeThickness(); }
void main() { FILE*file; int cases; int i,j,k; char number[110]; file=fopen("input.txt","r"); fscanf(file,"%d",&cases); for(i=0; i<cases; i++) { fscanf(file,"%s",number); k=strlen(number); for(j=0; j<k; j++) { number[j]-='0'; } printf("%d %d %d %d %d %d %d %d %d %d\n",two(number,k),three(number,k),four(number,k),five(number,k),six(number,k),seven(number,k),eight(number,k),nine(number,k),ten(number,k),eleven(number,k)); } }
int main() { /* part1.c */ printf("== one() ==\n"); one(3, 4); one(10, 10); printf("== two() ==\n"); two(50); two(100); printf("== three() ==\n"); three(); printf("== four() ==\n"); four(0.5); four(1.5); printf("== five() ==\n"); five(3, 3); five(3, 4); /* part2.c */ printf("== six() ==\n"); float *p_six; int i4 = 4, i432 = 432; p_six = six(&i4); printf("%d == %f\n", i4, *p_six); free(p_six); p_six = six(&i432); printf("%d == %f\n", i432, *p_six); free(p_six); printf("== seven() ==\n"); seven(2, 12); seven(14, 20); printf("== eight() ==\n"); eight(); printf("== nine() ==\n"); nine(); printf("== ten() ==\n"); int i_ten = 100; ten(&i_ten); printf("%d == 0?\n", i_ten); /* part3.c */ printf("== eleven() ==\n"); eleven(); printf("== twelve() ==\n"); twelve(); printf("== thirteen() ==\n"); thirteen(); printf("== fourteen() ==\n"); fourteen("red"); fourteen("orange"); fourteen("blue"); fourteen("green"); printf("== fifteen() ==\n"); fifteen(1); fifteen(2); fifteen(3); /* part4.c */ printf("== sixteen() ==\n"); char *str = sixteen(); printf("%s\n", str); free(str); printf("== seventeen() ==\n"); seventeen(35); seventeen(20); printf("== eighteen() ==\n"); eighteen(3); eighteen(5); printf("== clear_bits() ==\n"); long int result; result = clear_bits(0xFF, 0x55); printf("%ld\n", result); result = clear_bits(0x00, 0xF0); printf("%ld\n", result); result = clear_bits(0xAB, 0x00); printf("%ld\n", result); result = clear_bits(0xCA, 0xFE); printf("%ld\n", result); result = clear_bits(0x14, 0x00); printf("%ld\n", result); result = clear_bits(0xBB, 0xBB); printf("%ld\n", result); return 0; }
int main() { printf("== one() ==\n"); one(3, 4); one(10, 10); printf("== two() ==\n"); const char* a = "20"; two(a); const char* b = "100"; two(b); printf("== three() ==\n"); three(); printf("== four() ==\n"); four(0.5); four(1.5); printf("== five() ==\n"); const int num1 = 3; const int num2 = 3; five(&num1, &num2); const int num3 = 4; five(&num1, &num3); printf("== six() ==\n"); float *p_six; int i4 = 4, i432 = 432; p_six = six(&i4); printf("%d == %f\n", i4, *p_six); free(p_six); p_six = six(&i432); printf("%d == %f\n", i432, *p_six); free(p_six); printf("== seven() ==\n"); const char s = 'S'; seven(&s); const char t = '_'; seven(&t); printf("== eight() ==\n"); eight(); printf("== nine() ==\n"); nine(); printf("== ten() ==\n"); int i_ten = 100; ten(&i_ten); printf("%d == 0?\n", i_ten); printf("== eleven() ==\n"); eleven(); printf("== twelve() ==\n"); twelve(); printf("== thirteen() ==\n"); thirteen(10); printf("== fourteen() ==\n"); fourteen("red"); fourteen("orange"); fourteen("blue"); fourteen("green"); printf("== fifteen() ==\n"); fifteen(1); fifteen(2); fifteen(3); printf("== sixteen() ==\n"); char *str = sixteen(); printf("%s\n", str); free(str); printf("== seventeen() ==\n"); seventeen(35); seventeen(20); printf("== eighteen() ==\n"); eighteen(3); eighteen(5); printf("== clear_bits() ==\n"); long int result; result = clear_bits(0xFF, 0x55); printf("%ld\n", result); result = clear_bits(0x00, 0xF0); printf("%ld\n", result); result = clear_bits(0xAB, 0x00); printf("%ld\n", result); result = clear_bits(0xCA, 0xFE); printf("%ld\n", result); result = clear_bits(0x14, 0x00); printf("%ld\n", result); result = clear_bits(0xBB, 0xBB); printf("%ld\n", result); return 0; }