Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    long long int n = glong(), i, maxbit, j, k, tmp;
    long long int a[100005], t, ans = 0;
    for (i = 0; i < n; ++i)
    {
        a[i] = glong();
    }
    qsort((void*)a, n, sizeof(long long int), longlongintcmp);
    i = 0;
    while ((i < n) && (msb(a[i])))
    {
        j = i + 1;
        t = msb(a[i]);
        while((j < n) && (t == msb(a[j])))
        {
            a[j] ^= a[i];
            j++;
        }
        qsort((void*)a, n, sizeof(long long int), longlongintcmp);
        i++;
    }
    for(i = 0; i < n; ++i)
        if((ans ^ a[i]) > ans)
            ans = ans ^ a[i];
    printf("%lld\n", ans);
    return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    long long int t = 1, n, trigraph[100010][3], i;
    while(1)
    {
        n = glong();
        if(n == 0)
            break;
        for (i = 0; i < n; ++i)
        {
            trigraph[i][0] = glong();
            trigraph[i][1] = glong();
            trigraph[i][2] = glong();
        }
        plong(t);
        putchar_unlocked('.');
        putchar_unlocked(' ');
        if(n == 2)
            plong(minpath1(trigraph, n));
        else
            plong(minpath2(trigraph, n));
        putchar_unlocked('\n');
        t++;
    }
    return 0;
}
Exemplo n.º 3
0
gulong offset_rindex::load_page(glong page_idx)
{
	g_assert(gulong(page_idx+1)<npages);
	gulong nentr=ENTR_PER_PAGE;
	if (page_idx==glong(npages-2))
		if ((nentr=filecount%ENTR_PER_PAGE)==0)
			nentr=ENTR_PER_PAGE;


	if (page_idx!=page.page_idx) {
		page_data.resize(oft_file.get_wordoffset(page_idx+1)-oft_file.get_wordoffset(page_idx));
		fseek(idxfile, oft_file.get_wordoffset(page_idx), SEEK_SET);
		size_t fread_size;
		size_t page_data_size = page_data.size();
		fread_size = fread(&page_data[0], 1, page_data_size, idxfile);
		if (fread_size != page_data_size) {
			g_print("fread error!\n");
		}
		page.fill(&page_data[0], nentr, page_idx);
	}

	return nentr;
}
Exemplo n.º 4
0
inttoktype yylex()
{
	register	ptrall	bufptr;	
	register	inttoktype		val;	
	register	struct	exp	*locxp;
	/*
	 *	No local variables to be allocated; this saves
	 *	one piddling instruction..
	 */
	static	int	Lastjxxx;

	bufptr = tokptr;		/*copy in the global value*/
   top:
	if (bufptr < tokub){
		gtoken(val, bufptr);
		switch(yylval = val){
		case	PARSEEOF:
				yylval = val = PARSEEOF;
				break;
		case	BFINT:
		case	INT:
				if (xp >= &explist[NEXP])
				     yyerror("Too many expressions; try simplyfing");
				else
				    locxp = xp++;
				locxp->e_number = Znumber;
				locxp->e_number.num_tag = TYPL;
				glong(locxp->e_xvalue, bufptr);
			  makevalue:
				locxp->e_xtype = XABS;
				locxp->e_xloc = 0;
				locxp->e_xname = NULL;
				yylval = (int)locxp;
				break;
		case	BIGNUM:	
				if (xp >= &explist[NEXP])
				     yyerror("Too many expressions; try simplyfing");
				else
				    locxp = xp++;
				gnumber(locxp->e_number, bufptr);
				goto makevalue;
		case	NAME:
				gptr(yylval, bufptr);
				lastnam = (struct symtab *)yylval;
				break;
		case	SIZESPEC:
		case 	REG:
				gchar(yylval, bufptr);
				break;
		case	INSTn:
		case	INST0:
				gopcode(yyopcode, bufptr);
				break;
		case	IJXXX:
				gopcode(yyopcode, bufptr);
				/* We can't cast Lastjxxx into (int *) here.. */
				gptr(Lastjxxx, bufptr);
				lastjxxx = (struct symtab *)Lastjxxx;
				break;
		case	ILINESKIP:
				gint(yylval, bufptr);
				lineno += yylval;
				goto top;
		case	SKIP:	
				eatskiplg(bufptr);
				goto top;
		case	VOID:	
				goto top;
		case 	STRING:
		case 	ISTAB:
		case	ISTABSTR:
		case	ISTABNONE:
		case	ISTABDOT:
		case	IALIGN:
				gptr(yylval, bufptr);
				break;
		} 
#ifdef DEBUG
		if (toktrace){
		char	*tok_to_name();
		printf("P: %d T#: %4d, %s ",
			passno, bufptr -  firsttoken, tok_to_name(val));
		switch(val){
		case 	INT:	printf("val %d",
					((struct exp *)yylval)->e_xvalue);
				break;
		case	BFINT:	printf("val %d",
					((struct exp *)yylval)->e_xvalue);
				break;
		case 	BIGNUM: bignumprint(((struct exp*)yylval)->e_number);
				break;
		case	NAME:	printf("\"%.8s\"",
					FETCHNAME((struct symtab *)yylval));
				break;
		case	REG:	printf(" r%d",
					yylval);
				break;
		case	IJXXX:
		case	INST0:	
		case	INSTn:	printf("%.8s",
						FETCHNAME(ITABFETCH(yyopcode)));
				break;
		case	STRING:
			printf("length %d, seekoffset %d, place 0%o ",
				((struct strdesc *)yylval)->sd_strlen,
				((struct strdesc *)yylval)->sd_stroff,
				((struct strdesc *)yylval)->sd_place
				);
			if (((struct strdesc *)yylval)->sd_place & STR_CORE)
				printf("value\"%*s\"",
					((struct strdesc *)yylval)->sd_strlen,
					((struct strdesc *)yylval)->sd_string);
			break;
		}  		/*end of the debug switch*/
		printf("\n");
		}
#endif DEBUG

	} else {	/* start a new buffer */
	    if (useVM){
		if (passno == 2){
			tok_temp = emptybuf->tok_next;
			emptybuf->tok_next = tok_free;
			tok_free = emptybuf;
			emptybuf = tok_temp;
		} else {
			emptybuf = emptybuf->tok_next;
		}
		bufno += 1;
		if (emptybuf == 0){
			struct	tokbufdesc *newdallop;
			int	i;
			if (passno == 2)
				goto badread;
			emptybuf = newdallop = (struct tokbufdesc *)
			  Calloc(TOKDALLOP, sizeof (struct tokbufdesc));
			for (i=0; i < TOKDALLOP; i++){
				buftail->tok_next = newdallop;
				buftail = newdallop;
				newdallop += 1;
			}
			buftail->tok_next = 0;
		}	/*end of need to get more buffers*/
		(bytetoktype *)bufptr = &(emptybuf->toks[0]);
		if (passno == 1)
			scan_dot_s(emptybuf);
	    } else {	/*don't use VM*/
		bufno ^= 1;
		emptybuf = &tokbuf[bufno];
		((bytetoktype *)bufptr) = &(emptybuf->toks[0]);
		if (passno == 1){
			/*
			 *	First check if there are things to write
			 *	out at all
			 */
			if (emptybuf->tok_count >= 0){
			    if (writeTEST((char *)emptybuf, sizeof *emptybuf, 1, tokfile)){
				yyerror("Unexpected end of file writing the interpass tmp file");
				exit(2);
			    }
			}
			scan_dot_s(emptybuf);
		} else {	/*pass 2*/
		    if (readTEST((char *)emptybuf, sizeof *emptybuf, 1, tokfile)){
			 badread:
			     yyerror("Unexpected end of file while reading the interpass tmp file");
			     exit(1);
		    }
		}
	    }	/*end of using a real live file*/
	    (char *)tokub = (char *)bufptr + emptybuf->tok_count;
#ifdef DEBUG
	    firsttoken = bufptr;
	    if (debug)
		printf("created buffernumber %d with %d tokens\n",
			bufno, emptybuf->tok_count);
#endif DEBUG
	    goto top;
	}	/*end of reading/creating a new buffer*/
	tokptr = bufptr;		/*copy back the global value*/
	return(val);
}	/*end of yylex*/
Exemplo n.º 5
0
toktype yylex()
{
	register	ptrall	bufptr;	
	register	toktype		val;	
	register	struct	exp	*locxp;

	bufptr = tokptr;		/*copy in the global value*/
   top:
	if (bufptr < tokub){
		gtoken(val, bufptr);
		switch(yylval = val){
			case	PARSEEOF :
					yylval = val = PARSEEOF;
					break;
			case	INT:
					locxp = xp++;
					glong(locxp->xvalue, bufptr);
				  makevalue:
					locxp->xtype = XABS;
					locxp->xloc = 0;
					locxp->xname = NULL;
					yylval = (int)locxp;
					break;
			case	FLTNUM:	/*case patched on 3-Jan-80*/
					locxp = xp++;
					gdouble(locxp->doubval.dvalue, bufptr);
					/*
					 *	We make sure that locxp->xvalue
					 *	is not in the range suitable for
					 *	a short literal.  The field
					 *	xvalue is only used for
					 *	integers, not doubles, but when
					 *	we test for short literals
					 *	in ascode.c, we look
					 *	at the field xvalue when
					 *	it encounters an in line
					 *	floating number. Ergo,
					 *	give it a bad value.
					 */
					locxp->xvalue = -1;
					goto makevalue;
			case	NAME:
					gptr(yylval, bufptr);
					lastnam = (struct symtab *)yylval;
					break;
			case	SIZESPEC:
			case 	REG:
			case	INSTn:
			case	INST0:
					gchar(yylval, bufptr);
					break;
			case	IJXXX:
					gchar(yylval, bufptr);
					gptr(lastjxxx, bufptr);
					break;
			case	ILINESKIP:
					gint(yylval, bufptr);
					lineno += yylval;
					goto top;
			case	SKIP:	
					eatskiplg(bufptr);
					goto top;
			case	VOID:	
					goto top;
			case 	STRING:
					strptr = &strbuf[strno ^= 1];
					strptr->str_lg = *((lgtype *)bufptr);
					movestr(&strptr->str[0],
						(char *)bufptr + sizeof(lgtype),
						strptr->str_lg);
					eatstrlg(bufptr);
					yylval = (int)strptr;
					break;
			case 	ISTAB:
			case	ISTABSTR:
			case	ISTABNONE:
			case	ISTABDOT:
			case	IALIGN:
					gptr(yylval, bufptr);
					break;
		} /*end of the switch*/

#ifdef DEBUG

		if (toktrace)
		switch(val){
			case 	INT:	printf("Class integer val %d\n",
						((struct exp *)yylval)->xvalue);
					break;
			case 	FLTNUM: printf("Class floating point num value %4.3f\n",
					((struct exp *)yylval) -> doubval.dvalue);
					break;
			case	NAME:	printf("Class name, \"%.8s\"\n",
						((struct symtab *)yylval)->name);
					break;
			case	REG:	printf("Class register, number %d\n",
						yylval);
					break;
			case	INSTn:	printf("Class INSTn, %.8s\n",
						itab[0xFF &yylval]->name);
					break;
			case	IJXXX:	printf("Class IJXXX, %.8s\n",
						itab[0xFF &yylval]->name);
					break;
			case	INST0:	printf("Class INST0, %.8s\n",
						itab[0xFF &yylval]->name);
					break;
			case	STRING:	printf("Class string, length %d\n",
						((struct strdesc *)yylval)->str_lg);
					break;
			default:	printf("Pass: %d Tok: %d Other class: %d, 0%o, '%c'\n",
						passno,
						bufptr -  firsttoken,
						val,val, val);
					break;
		}		/*end of the debug switch*/
#endif

	}	/*end of this buffer*/
	else {
		if (useVM){
			bufno += 1;
			emptybuf = emptybuf->tok_next;
			if (emptybuf == 0){
				struct	tokbufdesc *newdallop;
				int	i;
				if (passno == 2)
					goto badread;
				emptybuf = newdallop = 
				  (struct tokbufdesc *)sbrk(
					TOKDALLOP*sizeof (struct tokbufdesc));
				if (emptybuf == (struct tokbufdesc *)-1)
					goto badwrite;
				for (i=0; i < TOKDALLOP; i++){
					buftail->tok_next = newdallop;
					buftail = newdallop;
					newdallop += 1;
				}
				buftail->tok_next = 0;
			}	/*end of need to get more buffers*/
			(toktype *)bufptr = &(emptybuf->toks[0]);
			if (passno == 1)
				scan_dot_s(emptybuf);
		} else {	/*don't use VM*/
			bufno ^= 1;
			emptybuf = &tokbuf[bufno];
			((toktype *)bufptr) = &(emptybuf->toks[0]);
			if (passno == 1){
				/*
				 *	First check if there are things to write
				 *	out at all
				 */
				if (emptybuf->tok_count >= 0){
					if (fwrite(emptybuf, sizeof *emptybuf, 1, tmpfil) != 1){
					  badwrite:
						yyerror("Unexpected end of file writing the interpass tmp file");
						exit(2);
					}
				}
				scan_dot_s(emptybuf);
			} else {	/*pass 2*/
				if (fread(emptybuf, sizeof *emptybuf, 1, tmpfil) != 1){
				  badread:
					yyerror("Unexpected end of file while reading the interpass tmp file");
					exit(1);
				}
			}	/*end of pass2*/
		}	/*end of using a real live file*/
		(char *)tokub = (char *)bufptr + emptybuf->tok_count;
#ifdef DEBUG
		firsttoken = bufptr;
		if (debug)
			printf("created buffernumber %d with %d tokens\n",
				bufno, emptybuf->tok_count);
#endif
			goto top;
	}	/*end of reading/creating a new buffer*/
	tokptr = bufptr;		/*copy back the global value*/
	return(val);
}	/*end of yylex*/
Exemplo n.º 6
0
int sf_aiffwav( FILE *f, int foffs, void ** wav, int *length){

  unsigned char chk[18], fid[4];
  int len, bps=0, offs, bksize, size;
  int samples, frequency, channels, found = 0;
  int bytespersample, reqsize;
  int noutsam=0, noutreqsam, bytesneeded, outbytespersample=2, mhack;
  double ratio, cratio;
  CONV conv; int needCONV;

  unsigned char *bout = NULL;

  if (!f) return -20;
  if (!wav) return -21;

  fseek(f,foffs,0);

  samples = 0; frequency = 0;
  channels = 0;

  if (fread(chk,1,4,f) < 4) return -1;	// FORM
  if (memcmp(chk,"FORM",4)) return -3;
  if (fread(chk,1,4,f) < 4) return -1;	// size
  size = glong(chk);
  if (size & 1) size++;
  if (size < 20) return -99;
  if (fread(chk,1,4,f) < 4) return -1;	// AIFF
  if (memcmp(chk,"AIFF",4)) return -3;
  size -= 4;
  while (size > 8){
	if (fread(fid,1,4,f) < 4) return -1;	// chunck id
	if (fread(chk,1,4,f) < 4) return -1;	// and len
	size -= 8;
	len = glong(chk);
	if (len < 0) return -98;
	if (len & 1) len++;
	size -= len;
	if (size < 0) return -97;
	if (memcmp(fid,"COMM",4)==0){
		if (len != 18) return -5;
		if (fread(chk,1,18,f) < 18) return -1;
		channels = gshort(chk);
		if (channels < 1) return -9;
		if (channels > MAXCHAN) return -9;
		samples = glong(chk+2);
		if (samples < 1) return -9;
		frequency = IeeeExtendedToLong(chk+8);
		if (frequency <= 0) return -54;
		bps = gshort(chk+6);
		if (bps < 1 || bps > 16) return -51;
//		data = malloc(samples*sizeof(short));
//		if (!data) return -55;
		}
	else if (memcmp(fid,"SSND",4)==0){
		if (!channels) return -11;
		if (fread(chk,1,4,f) < 4) return -1;
		offs = glong(chk);
		if (fread(chk,1,4,f) < 4) return -1;
		bksize = glong(chk);
		if (bksize) return -77;
		if (offs) fseek(f,offs,SEEK_CUR);
		found = 1;
		break;
		}
	else fseek(f,len,SEEK_CUR);
	}
  if (!found) return -69;
  if (!channels) return -66;

		// her should check freq
  ratio = (double)m_frequency / (double)frequency;
  mhack = hack(ratio);
  cratio = ratio;
  if (mhack)
	{
	cratio = 1.0;
	if (mhack > 0) frequency = m_frequency/mhack;
	else frequency = m_frequency * (-mhack);
	}

  noutreqsam = cratio*samples + 0.49;
  bytesneeded = HEADERSIZE + noutreqsam*channels*outbytespersample;
  bout = malloc(bytesneeded);
  if (!bout) return -55;

  *wav = (void *)bout;
  bout += HEADERSIZE;

  noutsam = 0;

  if ((needCONV = initCONV(&conv,cratio,channels,(bps+7)/8,BLOCKSIZE)) < 0)
	{
	free(bout);
	*wav = NULL;
	return -997;
	}

  while (samples)
	{
	int nrd = BLOCKSIZE, nwr;
	if (nrd > samples) nrd = samples;
	nwr = conv.doCONV( &conv, f, bout, nrd, nrd == samples);
	samples -= nrd;
	noutsam += nwr;
	bout += nwr*channels*outbytespersample;
	}

  conv.finishCONV(&conv);

//printf("AIFF %d, req %d\n",frequency,m_frequency);
	// write RIFF header
  if (needCONV) frequency = m_frequency;
  writeRIFFheader( *wav, frequency, noutsam, channels, outbytespersample);

  *length = HEADERSIZE + noutsam*channels*outbytespersample;

/*{
FILE *f;
f = fopen("_TMP","w"); fwrite(*wav,1,*length,f); fclose(f);
}*/
  return 0;
  }