예제 #1
0
void fill_num_arr(char *str, size_t *num_arr, int num)
{
    int i;
    for(i = 0; i < num; ++i)
    {
        size_t next_num;
        str = get_next_int(str, &next_num);
        num_arr[i] = next_num;
    }
}
예제 #2
0
int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    fgets(buf, sizeof(buf), stdin);
    size_t num_test_cases;
    get_next_int(buf, &num_test_cases);
    while(num_test_cases > 0)
    {
        handle_test_case();
        --num_test_cases;
    }
    return 0;
}
예제 #3
0
void		cmd_pic(char *cmd)
{
	int		i;
	int		pos[2];
	int		npc;
	int		lvl;

	i = 0;
	i += get_next_int(&pos[1], &cmd[i]);
	i += get_next_int(&pos[0], &cmd[i]);
	i += get_next_int(&lvl, &cmd[i]);
	printf("cmd_pic %d %d\n", pos[0], pos[1]);
	cast_incant(pos[0], pos[1]);
	while (cmd[i])
	{
		while (cmd[i] == ' ' || cmd[i] == '#')
			i++;
		i += get_next_int(&npc, &cmd[i]);
		if (npc >= NPCS_MAX || !g_env->npc[npc].id)
			return ;
	}
}
예제 #4
0
void		cmd_pfk(char *cmd)
{
	int		i;
	int		npc;

	printf("cmd_pfk: %s\n", cmd);
	i = 0;
	while (cmd[i] && (cmd[i] == ' ' || cmd[i] == '#'))
		i++;
	i += get_next_int(&npc, &cmd[i]);
	if (npc >= NPCS_MAX || !g_env->npc[npc].id)
		return ;
	printf("cmd_pfk: %d\n", npc);
}
예제 #5
0
void		cmd_bct(char *cmd)
{
	int		i;
	int		x;
	int		y;
	int		*tab;

	printf("cmd_bct: %s\n", cmd);
	i = 0;
	i += get_next_int(&x, &cmd[i]);
	i += get_next_int(&y, &cmd[i]);
	tab = g_env->sq[x + g_env->mapw * y].itms;
	i += get_next_int(&tab[0], &cmd[i]);
	i += get_next_int(&tab[1], &cmd[i]);
	i += get_next_int(&tab[2], &cmd[i]);
	i += get_next_int(&tab[3], &cmd[i]);
	i += get_next_int(&tab[4], &cmd[i]);
	i += get_next_int(&tab[5], &cmd[i]);
	i += get_next_int(&tab[6], &cmd[i]);
}
예제 #6
0
void		cmd_pcb(char *cmd)
{
	char	buf[BUF_SIZE];
	int		i;
	int		npc;

	bzero(buf, BUF_SIZE);
	i = 0;
	while (cmd[i] && (cmd[i] == ' ' || cmd[i] == '#'))
		i++;
	i += get_next_int(&npc, &cmd[i]);
	while (cmd[i] && cmd[i] == ' ')
		i++;
	strcpy(buf, &cmd[i]);
	broadcast(npc);
	printf("cmd_pcb: %d [%s]\n", npc, buf);
}
예제 #7
0
void handle_test_case()
{
    size_t num;
    size_t *num_arr = NULL, *wt_arr = NULL, *result_wt_arr = NULL;
    // get size of array
    fgets(buf, sizeof(buf), stdin);
    get_next_int(buf, &num);
    num_arr = (size_t*)malloc(num * sizeof(size_t));
    wt_arr = (size_t*)malloc(num * sizeof(size_t));
    result_wt_arr =(size_t*)malloc(num * sizeof(size_t));
    
    fgets(buf, sizeof(buf), stdin);
    fill_num_arr(buf, num_arr, num);
    fgets(buf, sizeof(buf), stdin);
    fill_num_arr(buf, wt_arr, num);
    
    int i, j;
    size_t max = 0;
    for(i = 0; i < num; ++i)
    {
        //printf("(%zu,  %zu)\n", num_arr[i], wt_arr[i]);
        result_wt_arr[i] = wt_arr[i];
        for(j = 0; j < i; ++j)
        {
            if(
                (num_arr[i] > num_arr[j]) && 
                 ((result_wt_arr[j] + wt_arr[i]) > result_wt_arr[i])
              )
            {
                result_wt_arr[i] = result_wt_arr[j] + wt_arr[i];
                if (result_wt_arr[i] > max)
                {
                    max = result_wt_arr[i];
                }
            }
        }
    }
    
    printf("%zu\n", max);
    free(num_arr);
    free(wt_arr);
    free(result_wt_arr);
    return;    
}
예제 #8
0
파일: tinterp.c 프로젝트: fl04t/codec2
void load_amp(MODEL *model, const char * file, int frame)
{
    FILE *f;
    int   i;
    char  s[1024];
    const char *ps;

    f = fopen(file,"rt");
    assert(f);

    for(i=0; i<frame; i++)
	ps = fgets(s, 1023, f);

    /// can frame ever be 0? what if fgets fails?
    ps = s;
    ps = get_next_float(ps, &model->Wo);
    ps = get_next_int(ps, &model->L);
    for(i=1; i<=model->L; i++)
	ps = get_next_float(ps, &model->A[i]);

    fclose(f);
}
예제 #9
0
void rx_task ()
{
	uint8_t pos,len,i,version;
	int8_t rssi;
  uint8_t *local_rx_buf;
  int16_t recipient,sender,dataseq;
	char type;
  if(log_g) printf ("log:rx_task PID=%d\r\n", nrk_get_pid ());
  // init bmac on channel 15 
  bmac_init (15);

  bmac_rx_pkt_set_buffer (rx_buf, RF_MAX_PAYLOAD_SIZE);

  while (1) {
    // Wait until an RX packet is received
    bmac_wait_until_rx_pkt ();
    // Get the RX packet 
    nrk_led_set (ORANGE_LED);
    local_rx_buf = bmac_rx_pkt_get (&len, &rssi);
    //if(log_g) printf ("log:Packet recv\n");
    //if(log_g) printf ("log:");
    //for (i = 0; i < len; i++) {
    //  if(log_g) printf ("%c", rx_buf[i]);
		//}
    //if(log_g) printf ("\n");

		pos = 0; 
		recipient = get_next_int(local_rx_buf,&pos,len); 
		pos+=1;
		sender = get_next_int(local_rx_buf,&pos,len);
		pos+=1; 
		type = local_rx_buf[pos];
		pos+=2;

		if((recipient != 0 && recipient != MAC_ADDR) || sender == MAC_ADDR) {

			if(log_g) printf("log:Ignore\r\n");

		} else if(recipient == 0 && type == 'S') {

			version =get_next_int(local_rx_buf,&pos,len);
			on_discover_pkt(sender, version);
 
		} else if (recipient == 0 && type == 'B') {

			onBasketBallPkt();
		
		}	else if (type == 'C') {

			version =get_next_int(local_rx_buf,&pos,len);
			onConnectionReq(sender,version);

		} else if(type == 'D' ) {

			dataseq = get_next_int(local_rx_buf,&pos,len);	
			onData(sender,dataseq,local_rx_buf,len);

		}	else if(type == 'A') {

			dataseq = get_next_int(local_rx_buf,&pos,len);	
			onAck(sender, dataseq);

		} else if(type == 'M') {
			onContactShare(local_rx_buf,len); 
		}else {

			if(log_g) printf("log:Invalid MSG\r\n");

		}
    
		// Release the RX buffer so future packets can arrive 
    memset(local_rx_buf,0,len+1);
    bmac_rx_pkt_release ();
  	nrk_led_clr(ORANGE_LED);
		nrk_wait_until_next_period();
	}
}
예제 #10
0
void uart_task()
{
	char c;
	nrk_sig_t uart_rx_signal;
	//nrk_sig_mask_t sm;
	uint8_t buf_pos = 0;
	uint8_t vbuf_pos = 0;
	uint8_t pos = 0;
	uint8_t other_active = 1;  
	uint8_t version_buf[VERSION_BUF_SIZE];
	int16_t my_version = 0;
	uint8_t connection_l;  
	uint8_t activate_uart_l;  
	uint8_t ack_received_l;

  if(log_g) printf("log:uart_task PID=%d\r\n",nrk_get_pid());

  // Get the signal for UART RX  
  uart_rx_signal=nrk_uart_rx_signal_get();
  // Register your task to wakeup on RX Data 
  if(uart_rx_signal==NRK_ERROR) nrk_kprintf( PSTR("log:Get Signal ERROR!\r\n") );
  nrk_signal_register(uart_rx_signal);


  while(1) {

	nrk_sem_pend(conn_sem);
	connection_l = connection_g;  
	nrk_sem_post(conn_sem);
	nrk_sem_pend(ack_sem);
	ack_received_l = ack_received_g;
	nrk_sem_post(ack_sem);


	if(activate_uart_g == 1 && other_active == 1)
	{
		memset(uart_rx_buf,0,buf_pos); 
		buf_pos = 0;
		if(log_g) printf("log:Switching off logs\r\n");
		req_for_next_data();
		log_g = 0;
		other_active = 0;
	}
	else if(activate_uart_g == 0 && vertsk_active_g == 0)
	{
		nrk_wait_until_next_period();	
		continue;
	} else if(activate_uart_g == 0 && connection_l == 0 && vertsk_active_g == 1) { // assuming this completes in one period
			
		if(log_g)nrk_kprintf(PSTR("verreq\n"));
		log_g = 0;
		while(nrk_uart_data_ready(NRK_DEFAULT_UART)!=0)
		{
			// Read Character
			c=getchar();
			if(vbuf_pos >= VERSION_BUF_SIZE)
 			{
				vbuf_pos = 0; 
				nrk_kprintf(PSTR("Ver buf ovflw\n"));
			}
			version_buf[vbuf_pos++] = c; 	
			nrk_led_toggle(GREEN_LED);
			if(c =='&')
			{
				log_g = 1;
				version_buf[vbuf_pos++] = '\0';
				pos = 0; 
				my_version = get_next_int(version_buf,&pos,vbuf_pos);
				if(log_g) printf("log:Ver %d\n",my_version);
				version_g[MAC_ADDR] = my_version;
				if(vbuf_pos > 6) 
				{	
					if(log_g)nrk_kprintf(PSTR("Cnct Frnd\n"));
					pos++;
					bmac_tx_pkt(version_buf+pos,vbuf_pos-pos);
 				}
				vertsk_active_g = 0;
				vbuf_pos = 0; 
			} else if (c == '$') {
				vbuf_pos = 0; 
			}
		}		
		log_g = 1;
		nrk_wait_until_next_period();
		continue; 
	}
	
	nrk_sem_pend(conn_sem);
	connection_l = connection_g;  
	nrk_sem_post(conn_sem);
	nrk_sem_pend(ack_sem);
	ack_received_l = ack_received_g;
	nrk_sem_post(ack_sem);



	if(ack_received_l == 1 && connection_l == 1)  
	{
	
		while(nrk_uart_data_ready(NRK_DEFAULT_UART)!=0)
		{
			// Read Character
			c=getchar();
			uart_rx_buf[buf_pos++] = c; 	
			nrk_led_toggle(GREEN_LED);
			if(c =='$')
			{
				log_g = 1;
				uart_rx_buf[buf_pos++] = '\0';
				if(log_g) nrk_kprintf(PSTR("log:From UART\n"));
				if(log_g) printf("log:%s\n",uart_rx_buf);
				activate_uart_g = 0;
				other_active = 1;
				// tx a packet				
				bmac_tx_pkt(uart_rx_buf,buf_pos);
				nrk_sem_pend(ack_sem);
				ack_received_g = 0; 
				nrk_sem_post(ack_sem);
				ack_received_l = 0;
				pending_retransmit_g = 1;
			} else if (c == '&') {
				buf_pos = 0; 		
			}
		}
		log_g = 1;
	}
	//sm=nrk_event_wait(SIG(uart_rx_signal));
	//if(sm != SIG(uart_rx_signal))
	//	nrk_kprintf( PSTR("RX signal error\n") );
	nrk_wait_until_next_period();	
  }

}