예제 #1
0
int main()
{
#ifdef DEBUG
#else
	freopen("sigma.in", "r", stdin);
#endif
	scanf("%d%d%d%d", &k, &x, &m, &n);

	res = itob(0);
	ptmp = itob(1);
	for(i=0; i<40; i++)  ptmp = bmultiply(ptmp, itob(10));
	bx = itob(x);

	btmp = ptmp;
	for(i=0; i<=n; i++){
		res = badd(res, btmp);
		btmp = bmultiply(btmp, bx);
	}

	btmp = itob(1);
	for(i=0; i<m; i++){
		btmp = bmultiply(btmp, bx);
		res = badd(res, bdivide(ptmp, btmp));
	}
	res = bmultiply(res, itob(k));

	write(res);

	/*
	ires = 0;  itmp = 1;
	for(i=0; i<=n; i++){
		ires += itmp;
		itmp *= x;
	}

	itmp = 1;  dtmp2 = 0;
	for(i=0; i<m; i++){
		//dtmp2 += dtmp;
		if( itmp > 2147483647 / x )  break;
		itmp *= x;
		dres += (double)k / itmp;
	}

//	dres = (double)(dtmp2) / dtmp;

	ires *= k;
	ires += (int)dres;
	dres -= (int)dres;
	printf("%d%.14lf", ires / 10, dres + ires % 10);
	*/
#ifdef DEBUG
	system("pause");
#endif
	return 0;
}
예제 #2
0
파일: MOUSE.C 프로젝트: flrl/spred
void mouse_update(Mouse *mouse) {
	int i;

	badd(&mouse->x, mouse->dx, 0, 319);
	badd(&mouse->y, mouse->dy, 0, 199);

	for (i = 0; i < mouse->n_buttons; i++) {
		if (mouse->pressed[i]) mouse->button[i] = 1;
		if (mouse->released[i]) mouse->button[i] = 0;
		mouse->pressed[i] = 0;
		mouse->released[i] = 0;
	}

	mouse->events = 0;
}
예제 #3
0
int main(void) {
    char *a = "9726", *b = "45",
         *c = badd(a,b);
    printf("%s+%s=",a,b);
    printf("%s\n",c);
    return 0;
}
예제 #4
0
파일: dwebsvr.c 프로젝트: Cloudhomebr/rCPU
STRING* new_string(int increments)
{
	STRING *s = mallocx(sizeof(STRING));
	bcreate(s, 1, increments);
	badd(s, "\0", 1);
	return s;
}
예제 #5
0
int main(int argc, char* argv[]){
	if(argc > 2) {
		int a = atoi(argv[1]);
		int b = atoi(argv[2]); 
		printf("%i + %i = %i\n", a, b, badd(a,b) );
	
	}
}
예제 #6
0
void free(void* ptr) {
	if (ptr == 0) return;
	mybucket* b = (mybucket*)(ptr - sizeof(mybucket));
	if (b->size >= N) {
		mythread* th = getById(pthread_self());
		pthread_mutex_lock(&th->thread_mutex);
		badd(&th->big_list, &th->big_list_end,b);
		th->bigsize++;
		pthread_mutex_unlock(&th->thread_mutex);
		if (th->bigsize > MAX_BIG_SIZE) {
			mybucket* moving = th->big_list;
			pthread_mutex_lock(&th->thread_mutex);
			bdelete(&th->big_list, &th->big_list_end, moving);
			th->bigsize--;
			pthread_mutex_unlock(&th->thread_mutex);
			pthread_mutex_lock(&glob_mutex);
			badd(&glob_list, &glob_list_end, moving);
			glob_size++;
			pthread_mutex_unlock(&glob_mutex);
			if (glob_size > MAX_GLOB_SIZE) {
				mybucket* d = glob_list;
				pthread_mutex_lock(&glob_mutex);
				bdelete(&glob_list, &glob_list_end, d);
				glob_size--;
				pthread_mutex_unlock(&glob_mutex);
				bdestroy(d);
			}
		}
	} else {
		mythread* th = getById(b->id);
		pthread_mutex_lock(&th->thread_mutex);
		badd(&th->small_list, &th->small_list_end, b);
		th->smallsize++;
		pthread_mutex_unlock(&th->thread_mutex);
		if (th->smallsize > MAX_SMALL_SIZE) {
			mybucket* d = th->small_list;
			pthread_mutex_lock(&th->thread_mutex);
			bdelete(&th->small_list, &th->small_list_end,d);
			th->smallsize--;
			pthread_mutex_unlock(&th->thread_mutex);
			bdestroy(d);
		}
	}
}
예제 #7
0
int main ()
{
	int b=eingabezahl("Bitte geben Sie die Basis ein: ");
	int zahl=eingabezahl("Bitte geben Sie die Dezimalzahl ein: ");
	//int n;
	//for (n=0;n<zahl;n++)
	//	printf("%lli\n",powi(b,n));
	badd(b,zahl);
	//printf("%i\n",badd(b,zahl));
	printf("\n");
	return 0;
}
예제 #8
0
bint bdivide (const bint a, const bint b)
{ // ! b != 0
	bint tmp, mod, res;
	int i, lf, rg, mid;
	mod.v[0] = mod.ln = 0;
	for (i = a.ln - 1; i >= 0; i--) {
		mod = badd( bmultiply(mod, itob(base)), itob(a.v[i]));
		for (lf = 0, rg = base -1; lf < rg; ) {
			mid = (lf + rg + 1) / 2;
			if ( bnolarger(bmultiply(b, itob(mid)), mod) ) lf = mid;
			else rg = mid - 1;
		}
		res.v[i] = lf;
		mod = bminus(mod, bmultiply(b, itob(lf)));
	}
	res.ln = a.ln;
	while (res.ln > 0 && res.v[res.ln - 1] == 0) res.ln--;
	return res; // return mod 就是%运算
}
예제 #9
0
파일: 77.c 프로젝트: shixv/test
int main(int argc,char *argv[])
{
	printf("%s\n",badd(argv[1],argv[2]));
	return 0;
}
예제 #10
0
char*
Brdstr(Biobuf *bp, int delim, int nulldelim)
{
	char *ip, *ep, *p;
	int i, j;

	i = -bp->icount;
	bp->rdline = 0;
	if(i == 0) {
		/*
		 * eof or other error
		 */
		if(bp->state != Bractive) {
			if(bp->state == Bracteof)
				bp->state = Bractive;
			bp->gbuf = bp->ebuf;
			return nil;
		}
	}

	/*
	 * first try in remainder of buffer (gbuf doesn't change)
	 */
	ip = (char*)bp->ebuf - i;
	ep = memchr(ip, delim, i);
	if(ep) {
		j = (ep - ip) + 1;
		bp->icount += j;
		return badd(nil, &bp->rdline, ip, j, delim, nulldelim);
	}

	/*
	 * copy data to beginning of buffer
	 */
	if(i < bp->bsize)
		memmove(bp->bbuf, ip, i);
	bp->gbuf = bp->bbuf;

	/*
	 * append to buffer looking for the delim
	 */
	p = nil;
	for(;;){
		ip = (char*)bp->bbuf + i;
		while(i < bp->bsize) {
			j = read(bp->fid, ip, bp->bsize-i);
			if(j <= 0 && i == 0)
				return p;
			if(j <= 0 && i > 0){
				/*
				 * end of file but no delim. pretend we got a delim
				 * by making the delim \0 and smashing it with nulldelim.
				 */
				j = 1;
				ep = ip;
				delim = '\0';
				nulldelim = 1;
				*ep = delim;	/* there will be room for this */
			}else{
				bp->offset += j;
				ep = memchr(ip, delim, j);
			}
			i += j;
			if(ep) {
				/*
				 * found in new piece
				 * copy back up and reset everything
				 */
				ip = (char*)bp->ebuf - i;
				if(i < bp->bsize){
					memmove(ip, bp->bbuf, i);
					bp->gbuf = (uchar*)ip;
				}
				j = (ep - (char*)bp->bbuf) + 1;
				bp->icount = j - i;
				return badd(p, &bp->rdline, ip, j, delim, nulldelim);
			}
			ip += j;
		}
	
		/*
		 * full buffer without finding; add to user string and continue
		 */
		p = badd(p, &bp->rdline, (char*)bp->bbuf, bp->bsize, 0, 0);
		i = 0;
		bp->icount = 0;
		bp->gbuf = bp->ebuf;
	}
}
예제 #11
0
파일: dwebsvr.c 프로젝트: Cloudhomebr/rCPU
void string_add(STRING *s, char *char_array)
{
    s->used_bytes--;
    badd(s, char_array, (int)strlen(char_array)+1);
}