예제 #1
0
/* Returns the slot_id or -1 in case of error. */
int window::attach(sg_plot* plot, const char *spec)
{
    ref::node *n = m_tree;
    const char *ptr;
    int k;

    for (ptr = next_int (spec, k); ptr; ptr = next_int (ptr, k))
    {
        list<ref::node*>* list = n->tree();

        if (! list)
            return -1;

        for (int j = 1; j < k; j++)
        {
            list = list->next();
            if (! list)
                return -1;
        }

        n = list->content();
    }

    ref* r = n->content();
    if (! r)
        return -1;

    r->plot = plot;

    return r->slot_id;
}
예제 #2
0
FidoAddress::FidoAddress(const std::string& address) {
  bool has_zone = contains(address, ':');
  bool has_net = contains(address, '/');
  bool has_point = contains(address, '.');
  bool has_domain = contains(address, '@');

  if (!has_net) {
    throw bad_fidonet_address(StrCat("Missing Net or Node. Unable to parse address: ", address));
  }
  auto it = std::begin(address);
  if (has_zone) {
    zone_ = next_int(address, it, {':'});
  } else {
    // per FSL-1002: "If 'ZZ:' is missing then assume 1 as the zone."
    // TODO(rushfan): Not sure if this is really what we expect though...
    zone_ = 1;
  }
  net_ = next_int(address, it, {'/'});
  node_ = next_int(address, it, {'@', '.'});
  if (has_point) {
    point_ = next_int(address, it, {'@'});
  }
  if (has_domain) {
    domain_ = string(it, std::end(address));
  }
}
예제 #3
0
int main() {

	N = next_int();
	L = next_int();
	R = next_int();
	
	REP( i, N ) {
		uint x = next_int();
	      seq[i] = H.insert( x );
	}
예제 #4
0
    bool isHappy(int n){
        int fast = n, slow = n;
        while(true){
            int tmp1 = next_int(fast), tmp2 = next_int(tmp1);
            if(tmp1 == 1 || tmp2 == 1)
                return true;

            fast = tmp2;
            slow = next_int(slow);
            if(fast == slow)
                return false;
        }
    }
예제 #5
0
int next_number(GEOSCommand *command, double *value) {
	int type;
        int size;
        char *buffer = command->param_bytes;
        int *index = &command->index;
        int ivalue;

	if(ei_get_type(buffer, index, &type, &size)) {
                return -1;
        }

	int ret = 0;
	switch(type) {
		case ERL_SMALL_INTEGER_EXT:
		case ERL_INTEGER_EXT:
			if(next_int(command, &ivalue)) {
				ret = -1;
			} else
				*value = ivalue; break;
		case ERL_FLOAT_EXT:
			ret = next_double(command, value); break;
		default:
			ret = -1;
	}
	return ret;
}
예제 #6
0
void meteor_launcher::launch() {

   auto side = next_int(0, 3);
   int x = 0, y = 0;
   int x1 = 0, y1 = 0;

   if (side == 0) {
      x = -500;
      y = next_int(0, height);
      x1 = width;
      y1 = next_int(0, height);
   }
   if (side == 1) {
      x = next_int(0, width);
      y = height + 500;
      x1 = next_int(0, width);
      y1 = 0;
   }

   if (side == 2) {
      x = width + 500;
      y = next_int(0, height);
      x1 = 0;
      y1 = next_int(0, height);
   }

   if (side == 3) {
      x = next_int(0, width);
      y = -500;
      x1 = next_int(0, width);
      y1 = height;
   }

   ent_asteroid *a;
   a = &w->add_entity<ent_asteroid>();
   a->C(com_box).pos = vec2(x, y);
   a->C(com_movement).vel = normalize(vec2(x1, y1) - vec2(x, y)) * next_int(7, 12);
   a->C(com_texture).filename = "asteroid.png";
   a->C(com_spin).rotation = next_float(0.01, 0.1);

   cout << "METEOR!!!!!!" << endl;
   last_launch = t.get_ticks();
   launch_period = launch_period - 50 > SEC / 2 ? launch_period - 50 : SEC / 2;
}
예제 #7
0
    bool isHappy(int n){
        unordered_set<int> hash_t;
        while(true){
            if(n == 1) return true;
            
            if(hash_t.find(n) != hash_t.end())
                return false;

            hash_t.insert(n);
            n = next_int(n);
        }
    }
예제 #8
0
파일: HPYNOS.cpp 프로젝트: dush1729/SPOJ
int main()
{
    int N,a[811]={},cou=0,n1,n2;
    N=next_int();
    while((a[N]!=1)&&(N!=1))
    {
        if(N<811) a[N]=1;
        n1=N;
        n2=0;
        while(n1)
        {
            n2+=(n1%10)*(n1%10);
            n1/=10;
        }
        N=n2;
        cou++;
    }
    if(N==1) printf("%d\n",cou);
    else printf("-1\n");
    return 0;
}
예제 #9
0
static gboolean
read_bitmap_file_data (FILE    *fstream,
		       guint   *width, 
		       guint   *height,
		       guchar **data,
		       int     *x_hot, 
		       int     *y_hot)
{
	guchar *bits = NULL;		/* working variable */
	char line[MAX_SIZE];		/* input line from file */
	int size;			/* number of bytes of data */
	char name_and_type[MAX_SIZE];	/* an input line */
	char *type;			/* for parsing */
	int value;			/* from an input line */
	int version10p;			/* boolean, old format */
	int padding;			/* to handle alignment */
	int bytes_per_line;		/* per scanline of data */
	guint ww = 0;			/* width */
	guint hh = 0;			/* height */
	int hx = -1;			/* x hotspot */
	int hy = -1;			/* y hotspot */

	/* first time initialization */
	if (!initialized) {
		init_hex_table ();
	}

	/* error cleanup and return macro */
#define	RETURN(code) { g_free (bits); return code; }

	while (fgets (line, MAX_SIZE, fstream)) {
		if (strlen (line) == MAX_SIZE-1)
			RETURN (FALSE);
		if (sscanf (line,"#define %s %d",name_and_type,&value) == 2) {
			if (!(type = strrchr (name_and_type, '_')))
				type = name_and_type;
			else {
				type++;
			}

			if (!strcmp ("width", type)) {
                                if (value <= 0)
                                        RETURN (FALSE);
				ww = (unsigned int) value;
                        }
			if (!strcmp ("height", type)) {
                                if (value <= 0)
                                        RETURN (FALSE);
				hh = (unsigned int) value;
                        }
			if (!strcmp ("hot", type)) {
				if (type-- == name_and_type
				    || type-- == name_and_type)
					continue;
				if (!strcmp ("x_hot", type))
					hx = value;
				if (!strcmp ("y_hot", type))
					hy = value;
			}
			continue;
		}
    
		if (sscanf (line, "static short %s = {", name_and_type) == 1)
			version10p = 1;
		else if (sscanf (line,"static const unsigned char %s = {",name_and_type) == 1)
			version10p = 0;
		else if (sscanf (line,"static unsigned char %s = {",name_and_type) == 1)
			version10p = 0;
		else if (sscanf (line, "static const char %s = {", name_and_type) == 1)
			version10p = 0;
		else if (sscanf (line, "static char %s = {", name_and_type) == 1)
			version10p = 0;
		else
			continue;

		if (!(type = strrchr (name_and_type, '_')))
			type = name_and_type;
		else
			type++;

		if (strcmp ("bits[]", type))
			continue;
    
		if (!ww || !hh)
			RETURN (FALSE);

		if ((ww % 16) && ((ww % 16) < 9) && version10p)
			padding = 1;
		else
			padding = 0;

		bytes_per_line = (ww+7)/8 + padding;

		size = bytes_per_line * hh;
                if (size / bytes_per_line != hh) /* overflow */
                        RETURN (FALSE);
		bits = g_malloc (size);

		if (version10p) {
			unsigned char *ptr;
			int bytes;

			for (bytes = 0, ptr = bits; bytes < size; (bytes += 2)) {
				if ((value = next_int (fstream)) < 0)
					RETURN (FALSE);
				*(ptr++) = value;
				if (!padding || ((bytes+2) % bytes_per_line))
					*(ptr++) = value >> 8;
			}
		} else {
			unsigned char *ptr;
			int bytes;

			for (bytes = 0, ptr = bits; bytes < size; bytes++, ptr++) {
				if ((value = next_int (fstream)) < 0) 
					RETURN (FALSE);
				*ptr=value;
			}
		}
		break;
	}
예제 #10
0
파일: com.c 프로젝트: KonstantinosKr/solfec
/* communicate objects using point to point communication */
int COMOBJS (MPI_Comm comm, int tag,
	     OBJ_Pack pack,
	     void *data,
	     OBJ_Unpack unpack,
             COMOBJ *send, int nsend,
	     COMOBJ **recv, int *nrecv) /* recv is contiguous => free (*recv) releases all memory */
{
  COMDATA *send_data,
	  *recv_data,
	  *cd, *cc;
  int recv_count,
      i, n,
      ret;
  COMOBJ *co;
  MAP *map;
  MEM mem;

  ERRMEM (send_data = malloc (nsend * sizeof (COMDATA)));
  MEM_Init (&mem, sizeof (MAP), MAX (nsend, 64));

  /* pack objects */
  for (i = 0, cd = send_data, co = send, map = NULL; i < nsend; i ++, cd ++, co ++)
  {
    int isize = 0,
	dsize = 0;

    cd->rank = co->rank;

    if ((cc = MAP_Find (map, co->o, NULL))) /* same object was already packed */
    {
      cd->ints = cc->ints;
      cd->doubles = cc->doubles;
      cd->i = cc->i;
      cd->d = cc->d;
    }
    else
    {
      cd->ints = 0;
      cd->doubles = 0;
      cd->i = NULL;
      cd->d = NULL;

      pack (co->o, &dsize, &cd->d, &cd->doubles, &isize, &cd->i, &cd->ints);

      MAP_Insert (&mem, &map, co->o, cd, NULL);
    }
  }

  /* send and receive packed data */
  if (tag == INT_MIN) ret = COMALL (comm, send_data, nsend, &recv_data, &recv_count); /* all to all */
  else ret = COM (comm, tag, send_data, nsend, &recv_data, &recv_count); /* point to point */

#if PARDEBUG
  {
    int debug_send_count, *ip, *jp, ii [2], jj [2];
    COMDATA *debug_send_data;
    double *qq, *pp;

    /* send backwards */
    if (tag == INT_MIN) COMALL (comm, recv_data, recv_count, &debug_send_data, &debug_send_count);
    else COM (comm, tag, recv_data, recv_count, &debug_send_data, &debug_send_count);

    ii[0] = 0, ii[1] = 0;
    jj[0] = 0, jj[1] = 0;
    do
    {
      ip = next_int (send_data, nsend, ii);
      jp = next_int (debug_send_data, debug_send_count, jj);
      if (ip && jp)
      {
	ASSERT_DEBUG (*ip == *jp, "Integer values mismatch");
      }
      else
      {
	ASSERT_DEBUG (!ip && !jp, "Integer count mismatch");
      }
    }
    while (ip && jp);

    ii[0] = 0, ii[1] = 0;
    jj[0] = 0, jj[1] = 0;
    do
    {
      qq = next_double (send_data, nsend, ii);
      pp = next_double (debug_send_data, debug_send_count, jj);
      if (qq && pp)
      {
	ASSERT_DEBUG (*qq == *pp, "Double values mismatch");
      }
      else
      {
	ASSERT_DEBUG (!qq && !pp, "Double count mismatch");
      }
    }
    while (qq && pp);

    free (debug_send_data);
  }
#endif

  if (recv_count)
  {
    *nrecv = recv_count;
    ERRMEM (*recv = malloc ((*nrecv) * sizeof (COMOBJ)));

    /* unpack received objects */
    for (n = i = 0, cd = recv_data, co = *recv; i < recv_count; i ++, cd ++)
    {
      int ipos = 0,
	  dpos = 0;

      do
      {
	if (n == *nrecv)
	{
	  *nrecv *= 2; /* resize the receive buffer */
	  ERRMEM (*recv = realloc (*recv, (*nrecv) * sizeof (COMOBJ)));
	  co = *recv + n; /* and reset the current pointer */
	}

	co->rank = cd->rank;
	co->o = unpack (data, &dpos, cd->d, cd->doubles, &ipos, cd->i, cd->ints);

	co ++;
	n ++;

      } while (ipos < cd->ints || dpos < cd->doubles); /* while something is left to unpack */
    }

    /* truncate output */
    if (n) ERRMEM (*recv = realloc (*recv, n * sizeof (COMOBJ)));
    *nrecv = n;
  }
  else
  {
    *recv = NULL;
    *nrecv = 0;
  }

  /* cleanup */
  for (MAP *item = MAP_First (map); item; item = MAP_Next (item))
  { cd = item->data; free (cd->i); free (cd->d); }
  MEM_Release (&mem);
  free (send_data);
  free (recv_data); /* contiguous */

  return ret;
}