Ejemplo n.º 1
0
int main() {
  char m[4][100];
  char r[100];

  for (int i = 0; i < 4; i++)
    scanf("%s", m[i]);

  int f = get_nth(m, 0);
  int l = get_nth(m, strlen(m[0])-1);
  
  for (int i = 1; i < strlen(m[i])-1; i++) {
    r[i-1] = ((f*get_nth(m,i)) + l) % 257;
  }
  r[strlen(m[0])-1] = '\0';
  printf("%s\n", r);
}
Ejemplo n.º 2
0
static char *
discover_traversible(dpl_addrlist_t *addrlist)
{
  int n;
  int i;
  int j;
  char *s;
  dpl_status_t r;
  char *addr;
#define MAXADDRS    32
  int naddrs = 0;
  char *addrs[MAXADDRS];

  n = dpl_addrlist_count(addrlist);
  for (i = 0 ; i < n ; i++)
    {
      addr = get_nth(addrlist, i);

      for (j = 0 ; j < naddrs ; j++)
	{
	  if (!strcmp(addr, addrs[j]))
	    break;
	}
      if (j == naddrs)
	{
	  dpl_assert_int_ne(naddrs, MAXADDRS);
	  addrs[naddrs++] = addr;
	}
      else
	free(addr);
    }

  /* sort the results into a predictable order */
  qsort(addrs, naddrs, sizeof(char*), compare_addrs);

  /* concatenate the strings into one big one */
  n = 0;
  for (i = 0 ; i < naddrs ; i++)
    n += strlen(addrs[i])+1;

  s = malloc(n);
  dpl_assert_ptr_not_null(s);
  s[0] = '\0';

  for (i = 0 ; i < naddrs ; i++)
    {
      if (i)
	strcat(s, ",");
      strcat(s, addrs[i]);
      free(addrs[i]);
    }

  return s;
}
Ejemplo n.º 3
0
int     get_nth(BTREE *bt, long page, int n, KEY *key, ITEM *u)
{
PAGE_ADDRESS *p;
int     i, cont;

   if (page == BTREE_NULL)
   {
        btree_errno = INTERN_MIST;
        return -1;
   }

   p = (PAGE_ADDRESS *) get_page(bt, page);

   if (p->child0 >= n)
        return get_nth(bt, p->next0, n, key, u);

   n -= p->child0;
   i = 0;
   while (i < p->nkeys-1)
   {
        if (1 == n)
        {
           l1:
           memcpy(key, nth_key(bt, p, i), bt->realkeysize);
           *u = p->s[i];
           return 0;
        }
        n--;
        if (n <= p->s[i].child)
           return get_nth(bt, p->s[i].next, n , key, u);
        n-= p->s[i].child;
        i++;
   }
   if (n == 1)
        goto l1;

   return get_nth(bt, p->s[i].next, n-1 , key, u);
}
Ejemplo n.º 4
0
void
task2(intptr_t exinf)
{
	ID		tskid;
	ER_UINT	ercd;
	uint_t	load;

	check_point(7);
	ercd = get_lod(TPRI_SELF, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 3U);

	ercd = get_nth(TPRI_SELF, 0U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TASK2);

	check_point(8);
	ercd = slp_tsk();
	check_ercd(ercd, E_OK);

	check_point(17);
	ercd = get_lod(TPRI_SELF, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 1U);

	check_point(18);
	ercd = chg_pri(TASK5, MID_PRIORITY);
	check_ercd(ercd, E_OK);

	ercd = get_lod(TPRI_SELF, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 2U);

	ercd = rot_rdq(TPRI_SELF);
	check_ercd(ercd, E_OK);

	check_point(0);
}
//-----------------------------------------------
// encode()
// PreConditions:
// - letter_to_encode is a letter of the English
//   alphabet. It can be small or capital
// PostConditions:
// - encodedvalue will be returned. It is an
//   index value in the DOI where the first letter
//   of the encodedvalue word is the letter_to_encode
//-----------------------------------------------
int BCipher::encode (char letter_to_encode)
{
 int numoccurrences, encodedvalue, randval;

 // work with caps only for internal comparisons
 if ((letter_to_encode >= ASCIIa) &&
     (letter_to_encode <= ASCIIz)) letter_to_encode -= TOCAPITAL;
 //spot = letter_to_encode - ASCIIA;
 numoccurrences = lettercount[letter_to_encode - ASCIIA];

 // Prepare to select a random word in the DOI that
 // begins with the letter_to_encode
 if (numoccurrences > 1) randval = (rand() % numoccurrences) + 1;
 else randval = 1;

 // go get the index position of the nth occurrence
 // of the letter_to_encode
 encodedvalue = get_nth(randval, letter_to_encode);

 return(encodedvalue);
} // end encode()
Ejemplo n.º 6
0
void
task4(intptr_t exinf)
{
	ID		tskid;
	ER_UINT	ercd;
	uint_t	load;

	check_point(11);
	ercd = get_lod(TPRI_SELF, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 1U);

	ercd = get_nth(TPRI_SELF, 0U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TASK4);

	check_point(12);
	ercd = slp_tsk();
	check_ercd(ercd, E_OK);

	check_point(0);
}
Ejemplo n.º 7
0
void
task5(intptr_t exinf)
{
	ID		tskid;
	ER_UINT	ercd;
	uint_t	load;

	check_point(13);
	ercd = get_lod(TPRI_SELF, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 1U);

	ercd = get_nth(TPRI_SELF, 0U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TASK5);

	check_point(14);
	ercd = loc_mtx(MTX1);
	check_ercd(ercd, E_OK);

	ercd = get_lod(TPRI_SELF, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 0U);

	ercd = get_nth(TPRI_SELF, 0U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TSK_NONE);

	ercd = get_lod(MID_PRIORITY, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 1U);

	ercd = get_nth(MID_PRIORITY, 0U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TASK5);

	check_point(15);
	ercd = wup_tsk(TASK2);
	check_ercd(ercd, E_OK);

	ercd = get_lod(TPRI_SELF, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 0U);

	ercd = get_lod(MID_PRIORITY, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 2U);

	check_point(16);
	ercd = unl_mtx(MTX1);
	check_ercd(ercd, E_OK);

	check_point(19);
	ercd = get_lod(TPRI_SELF, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 2U);

	ercd = get_nth(TPRI_SELF, 0U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TASK5);

	check_finish(20);
	check_point(0);
}
Ejemplo n.º 8
0
void
task1(intptr_t exinf)
{
	ID		tskid;
	ER_UINT	ercd;
	uint_t	load;

	test_start(__FILE__);

	check_point(1);
	ercd = get_lod(TMIN_TPRI-2, &load);
	check_ercd(ercd, E_PAR);

	ercd = get_lod(TMAX_TPRI+1, &load);
	check_ercd(ercd, E_PAR);

	ercd = get_nth(TMIN_TPRI-2, 0U, &tskid);
	check_ercd(ercd, E_PAR);

	ercd = get_nth(TMAX_TPRI+1, 0U, &tskid);
	check_ercd(ercd, E_PAR);

	check_point(2);
	ercd = get_lod(MID_PRIORITY, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 0U);

	ercd = get_nth(MID_PRIORITY, 0U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TSK_NONE);

	check_point(3);
	ercd = act_tsk(TASK2);
	check_ercd(ercd, E_OK);

	ercd = get_lod(MID_PRIORITY, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 1U);

	ercd = get_nth(MID_PRIORITY, 0U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TASK2);

	ercd = get_nth(MID_PRIORITY, 1U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TSK_NONE);

	check_point(4);
	ercd = act_tsk(TASK3);
	check_ercd(ercd, E_OK);

	ercd = act_tsk(TASK4);
	check_ercd(ercd, E_OK);

	ercd = get_lod(MID_PRIORITY, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 3U);

	ercd = get_nth(MID_PRIORITY, 0U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TASK2);

	ercd = get_nth(MID_PRIORITY, 1U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TASK3);

	ercd = get_nth(MID_PRIORITY, 2U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TASK4);

	ercd = get_nth(MID_PRIORITY, 3U, &tskid);
	check_ercd(ercd, E_OK);

	check_assert(tskid == TSK_NONE);

	check_point(5);
	ercd = act_tsk(TASK5);
	check_ercd(ercd, E_OK);

	ercd = get_lod(MID_PRIORITY, &load);
	check_ercd(ercd, E_OK);

	check_assert(load == 3U);

	check_point(6);
	ercd = slp_tsk();
	check_ercd(ercd, E_OK);

	check_point(0);
}