Esempio n. 1
0
int bs1(int a[], int low, int high, int t){
  if (low <= high) {
    //printf("%d-%d\n", low, high);
    int mid = low + (high-low)/2;
    if(a[mid] < t) return bs1(a, mid + 1, high, t);
    else if(a[mid] > t) return bs1(a, low, mid - 1, t);
    else {
      return mid;
    }
  } else 
    return -1;
}
Esempio n. 2
0
/*
 * Byteswap an mmap'ed file if needed
 */
static void byteswap(struct r_magic *magic, ut32 nmagic) {
	ut32 i;
	for (i = 0; i < nmagic; i++)
		bs1 (&magic[i]);
}
Esempio n. 3
0
void ModelTest()
{
	int array[4][4]={1};
	int i,j;
	try
	{
		BaseShape bs1(1);
		if (bs1.get_color()==0)
			throw int(2);
		BaseShape bs2(2);
		if (bs2.get_color()!=2)
			throw int(2);

		BaseShape bs3(bs1);
		if (ShapeEqual(bs1,bs3))
			throw int(2);
		if (!ShapeEqual(bs2,bs3))
			throw int(2);
		if (ShapeEqual(bs3,BaseShape(bs1)))
			throw int(2);
		if (!ShapeEqual(bs3,BaseShape(bs2)))
			throw int(2);
		
		BaseShape bs4=bs1;
		if (ShapeEqual(bs1,bs4))
			throw int(2);
		if (!ShapeEqual(bs2,bs4))
			throw int(2);
		BaseShape bs5=BaseShape(bs2);
		if (ShapeEqual(bs2,bs5))
			throw int(2);
		if (!ShapeEqual(bs1,bs5))
			throw int(2);

		BaseShape s(0);

		s.set_x(1);
		if (s.get_x()!=1)
			throw int(2);
		s.set_x(2);
		if (s.get_x()==1)
			throw int(2);
		
		s.set_y(1);
		if (s.get_y()!=1)
			throw int(2);
		s.set_y(2);
		if (s.get_y()==1)
			throw int(2);

		s.set_color(1);
		if (s.get_color()!=1)
			throw int(2);
		s.set_color(2);
		if (s.get_color()==1)
			throw int(2);

		s.move_left();
		if (s.get_x()!=1)
			throw int(2);

		s.move_right();
		s.move_right();
		if (s.get_x()!=3)
			throw int(2);

		s.move_down();
		if (s.get_color()!=1)
			throw int(2);

		for(i=0 ;i<4 ;i++)
		for(j=0 ;j<4 ;j++)
			if (s.get_matrix(i,j))
				throw int(2);

		s.Rotate();
		if (s.get_dir()!=1)
			throw int(2);

	}
	catch(...)
	{
		printf("shape exception!");
	}

	try
	{
		Map m1;
		for(i=0 ;i<4 ;i++)
		for(j=0 ;j<4 ;j++)
			if(m1.get_exist(i,j)||m1.get_color(i,j))
				throw int(3);
		Map m2(m1);
		for(i=0 ;i<4 ;i++)
		for(j=0 ;j<4 ;j++)
			if(m2.get_exist(i,j)||m2.get_color(i,j))
				throw int(3);

		if(Map(m1).get_exist(0,0))
				throw int(3);

		Map m3=m1;
		for(i=0 ;i<4 ;i++)
		for(j=0 ;j<4 ;j++)
			if(m3.get_exist(i,j)||m3.get_color(i,j))
				throw int(3);
		Map m4=Map(m1);
		for(i=0 ;i<4 ;i++)
		for(j=0 ;j<4 ;j++)
			if(m4.get_exist(i,j)||m4.get_color(i,j))
				throw int(3);


	}
	catch(...)
	{
		printf("map exception!");
	}

	try
	{
		Board b1;
		if (b1.get_points()!=0)
			throw int(4);
		Board b2(b1);
		if (b2.get_points()!=0)
			throw int(4);
		if (b1.add_points(10) != 10)
			throw int(4);

		if (Board(b2).get_points()!=0)
			throw int(4);	
		Board b4=b2;
		if (b4.get_points()!=0)
			throw int(4);
		Board b5=Board(b2);
		if (b5.get_points()!=0)
			throw int(4);
	}
	catch(...)
	{
		printf("board exception!");
	}
}
Esempio n. 4
0
int main() {
  int a1[] = {1,1,2,3,3,5,8,8,8,10,27,27,29,31,31};
  printf("%d\n", bs1(a1, 0, sizeof(a1)/sizeof(int) - 1, 8));
}
Esempio n. 5
0
File: main.cpp Progetto: CCJY/coliru
int main() {
    Inkr inkr;
    bs1(inkr);
    bs2(inkr);
}