示例#1
0
文件: sudoku.c 项目: gnimnet/sudoku
int getnext(int nowrow,int nowcol){
	char canput[10];
	int i;
	if(sudoku[nowrow][nowcol]!=0){//已经有数据
		if(nowrow==8 && nowcol==8)
			return 1;
		else
			return getnext(nowrow+(nowcol+1)/9,(nowcol+1)%9);
	}
	getput(nowrow,nowcol,canput);
	for(i=1;i<=9;i++){
		if(canput[i]){
			if(nowrow==8 && nowcol==8){
				sudoku[nowrow][nowcol]=i;
				return 1;
			}
			sudoku[nowrow][nowcol]=i;
			if(getnext(nowrow+(nowcol+1)/9,(nowcol+1)%9)){
				return 1;
			}
			sudoku[nowrow][nowcol]=0;
		}
	}
	return 0;
}
void check(void)
{
	if(gethash()==myhash)
	{
		int flag=1;
		for(int i=qstart;getnext(i)!=qstart;i=getnext(i))
		{
			if(mystr[i-qstart]!=strq[i])
			{
				flag=0;
				return;
			}
		}
		if(flag==1)
		{
			k++;
			printf("No.%d: %d~%d\n",k,loc-mylen+1,loc);
			if(k>=32)
			{
				printf("Too many. \n");
                                exit(0);
			}
		}
	}
}
示例#3
0
/*********************************************************************
  return: next character from current input stream
**********************************************************************/
static int getnext(void)
{
  int ch;

  if(inputputbackcount > 0)
  {
    ch = inputputback[--inputputbackcount];
    (current->columnnr)++;
    return ch;
  }
  if(inputstate == CLOSED)
    systemerror(9);
  if(current->columnnr > 0 && inputbuffer[current->columnnr-1] == '\0')
  {
    if(inputstate == EXPRESSIONINPUT)
      return EOF;
    else if(current->fp == NULL || !fgets(inputbuffer, stringsize, current->fp))
    {
      closeinput();
      return inputstate==FILEINPUT ? getnext() : EOF;
    }
    (current->linenr)++;
    current->columnnr = 0;
    if(preprocess()) return getnext();
  }
  ch = inputbuffer[(current->columnnr)++];
  if(ch == '\0') ch = '\n';
  return ch;
}
示例#4
0
int
_readx(Rune *p, int n, int nmode, int line)
{
	int c, omode;
	Rune *e;

	while((c = getrune()) == ' ' || c == '\t')
		;
	ungetrune(c);
	omode = inputmode;
	inputmode = nmode;
	e = p+n-1;
	for(c=getnext(); p<e; c=getnext()){
		if(c < 0)
			break;
		if(!line && (c == ' ' || c == '\t'))
			break;
		if(c == '\n'){
			if(!line)
				ungetnext(c);
			break;
		}
		*p++ = c;
	}
	inputmode = omode;
	*p = 0;
	if(c < 0)
		return -1;
	return 0;
}
示例#5
0
uint32_t MidPlayer::getval()
{
    auto b = getnext(1);
    auto v = b & 0x7f;
    while((b & 0x80) != 0)
    {
        b = getnext(1);
        v = (v << 7) | (b & 0x7F);
    }
    return v;
}
示例#6
0
文件: view.c 项目: csimons/cswm
void
focusnext(Arg *arg) {
    Client *c;
   
    if(!sel)
        return;
    if(!(c = getnext(sel->next)))
        c = getnext(clients);
    if(c) {
        focus(c);
        restack();
    }
}
示例#7
0
文件: sdbm.c 项目: JoeFord/rig-build
datum
sdbm_nextkey(register DBM *db)
{
	if (db == NULL)
		return errno = EINVAL, nullitem;
	return getnext(db);
}
示例#8
0
文件: kz.c 项目: surajpkn/flux-core
int kz_get (kz_t *kz, char **datap)
{
    char *json_str = NULL;
    char *data;
    int len = -1;

    if (!datap || (kz->flags & KZ_FLAGS_RAW)) {
        errno = EINVAL;
        goto done;
    }
    if (kz->eof)
        return 0;
    if ((kz->flags & KZ_FLAGS_NONBLOCK))
        json_str = getnext (kz);
    else
        json_str = getnext_blocking (kz);
    if (!json_str)
        goto done;
    if ((len = zio_json_decode (json_str, (void **) &data, &kz->eof)) < 0) {
        errno = EPROTO;
        goto done;
    }
    *datap = data;
done:
    if (json_str)
        free (json_str);
    return len;
}
示例#9
0
int kmp( const char* src, const char* pattern )
{
	if( NULL == src || NULL == pattern )
		return -1;
	
	const char* head = src;
	int count = 0;
		
	while( '\0' != *src )
	{
		int next = (count > 0)?getnext( pattern, count ):0;
		count = next;
		const char* subfix = src-count;
		while( '\0' != *src && '\0' != *(pattern+next) && (*src == *(pattern+next)) )
		{
			++next;
			++count;
			++src;
		}
		if( '\0' == *(pattern+next) )
			return (subfix-head);
		if( 0 == next )
			++src;
	}
	return -1;	
}
示例#10
0
void	read_data ( void )
{
	while (getnext())
	{
		printf("%s", buffer);
	}
}
示例#11
0
文件: process.c 项目: dank101/386BSD
/*
 * process --
 *	copy report to permanent file,
 *	update summary file.
 */
process()
{
	register int	rval;			/* read return value */
	struct timeval	tp;			/* time of day */
	int	lfd;				/* lock file descriptor */
	static int getnext();

	if (access(LOCK_FILE, R_OK) || (lfd = open(LOCK_FILE, O_RDONLY, 0)) < 0)
		error("can't find lock file %s.", LOCK_FILE);
	if (flock(lfd, LOCK_EX))
		error("can't get lock.", CHN);
	sprintf(pfile, "%s/%s/%d", dir, folder, getnext());
	fprintf(stderr, "\t%s\n", pfile);
	if (!(freopen(pfile, "w", stdout)))
		error("can't create %s.", pfile);
	rewind(stdin);
	while ((rval = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && rval)
		if (write(fileno(stdout), bfr, rval) != rval)
			error("write to %s failed.", pfile);

	/* append information to the summary file */
	sprintf(bfr, "%s/%s", dir, SUMMARY_FILE);
	if (!(freopen(bfr, "a", stdout)))
		error("can't append to summary file %s.", bfr);
	if (gettimeofday(&tp, (struct timezone *)NULL))
		error("can't get time of day.", CHN);
	printf("\n%s\t\t%s\t%s\t%s\tOwner: Bugs Bunny\n\tStatus: Received\n", pfile, ctime(&tp.tv_sec), mailhead[INDX_TAG].line, mailhead[SUBJ_TAG].found ? mailhead[SUBJ_TAG].line : "Subject:\n");
	(void)flock(lfd, LOCK_UN);
	(void)fclose(stdout);
}
示例#12
0
文件: cb.c 项目: 00001/plan9port
void
gottype(struct keyw *lptr)
{
	char *pt;
	struct keyw *tlptr;
	int c;
	while(1){
		pt = getnext(1);
		if((tlptr=lookup(pt,lastplace+1))!=0){
			putch(' ',YES);
			copy(tlptr->name);
			*pt='\0';
			lastplace = pt;
			if(tlptr->type == STRUCT){
				putch(tlptr->punc,YES);
				gotstruct();
				break;
			}
			lptr=tlptr;
			continue;
		}
		else{
			putch(lptr->punc,NO);
			while((c=getch())== ' ' || c == '\t');
			unget(c);
			break;
		}
	}
}
示例#13
0
void datendump(LIST *l)
{
	register struct Robot *rp;
	NODE *n;

	printf("Name            Spiele   Züge             Lebend    Kills"
		"         Panzerung             Munition\n");
	for(n=getfirst(l);n;n=getnext(l))
	{
		rp=getdata(n);
		printf("%-14.14s %4d %9d %7.0fø %4d %5.1f%% %4d %5.2fø %6d/%6d %5.1f%% %6d/%6d %5.1f%%\n",
			rp->name,
			rp->killed+rp->survived,
			rp->ticks,
			1.0*rp->ticks/(rp->killed+rp->survived),
			rp->survived,
			100.0*rp->survived/(rp->killed+rp->survived),
			rp->kills,
			1.0*rp->kills/(rp->killed+rp->survived),
			rp->armour,
			rp->startarmour,
			100.0*rp->armour/rp->startarmour,
			rp->mun,
			rp->startmun,
			100.0*rp->mun/rp->startmun
		);
	}
}
示例#14
0
void OjammAttack(GameState *gs, int target)
{
	if(gs->board[target].lost){
		gs->board[getnext(target,gs->player_count)].ojamms_pending += gs->board[target].ojamms_pending;
		gs->board[target].ojamms_pending = 0;
		return;
	}

	if(gs->board[target].ojamms_pending > gs->board[target].width_in_pieces)
		gs->board[target].ojamms_pending = gs->board[target].width_in_pieces;

	int offsetx = rand()%5;
	for(unsigned o = 0; o < gs->board[target].ojamms_pending; o++){
		Piece *ojamm = new Piece();
		ojamm->color = OJAMM;
		ojamm->falling = true;
		ojamm->x = (offsetx + o) % gs->board[target].width_in_pieces;
		ojamm->y = 0;
		ojamm->w = gs->board[target].piece_width;
		ojamm->h = gs->board[target].piece_height;

		gs->board[target].b[ojamm->x][0] = ojamm;
		FallPieces(gs,target);		
	}

	gs->board[target].ojamms_pending = 0;
	FallPieces(gs,target);
}
示例#15
0
int main(){
    int t,m,x1,x2,l,res,s,e;
    int j,i;
    scanf("%d",&t);
    while(t--){
        res = 0;
        scanf("%d",&m);
        l = 0;
        s = e = -1;
        while(1){
            scanf("%d %d",&x1, &x2);
            if(!x1 && !x2) break;
            points[l].x1 = x1;
            points[l].x2 = x2;
            l++;
        }
        qsort(points,l,sizeof(point),compare);
        s = e = 0;
        int emax_i = 0;
        for(i=0;i<l;){
            if(points[i].x2 < 0){
                i++;
                continue;
            }
            if(!s && !e){
                s = points[i].x1;
                e = points[i].x2;
                sol[res] = points[i];
                res++;
            }
            j = getnext(i,l);            
            if(j<0) break;
            if(points[j].x1<=0){
                s = points[j].x1;
                e = points[j].x2;
                i = j;
                sol[res-1] = points[i];
                continue;
            }
            e = points[j].x2;
            i = j;
            sol[res] = points[i];
            res++;
            if(e>=m) break;
        }

        if(s <= 0 && e >= m){
            printf("%d\n",res);
            for(i=0;i<res;i++){
                printf("%d %d\n",sol[i].x1, sol[i].x2);
            }
        }
        else{
            printf("0\n");
        }
        if(t!=0) printf("\n");
    }
    return 0;
}
示例#16
0
void push(int x)
{
	hash=hash-strq[qstart]*strq[qstart]+x*x;
	hash=hash+MOD;
	hash%=MOD;
	strq[qstart]=x;
	qstart=getnext(qstart);
}
示例#17
0
文件: view.c 项目: csimons/cswm
void
restack(void) {
    Client *c;
    XEvent ev;

    if(!sel)
        return;
    else
        XLowerWindow(dpy, sel->win);
    for(c = getnext(clients); c; c = getnext(c->next)) {
        if(c == sel)
            continue;
        XLowerWindow(dpy, c->win);
    }
    XSync(dpy, False);
    while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
示例#18
0
int
tty_sync_error(void)
{
	int ch, trouble, ack;

	trouble = FALSE;
	for (;;) {
		tt_putp(tty_ENQ);	/* send ENQ */
		ch = getnext(STRIP_PARITY);
		event_start(TIME_SYNC);	/* start the timer */

		/*
		   The timer doesn't start until we get the first character.
		   After that I expect to get the remaining characters of
		   the acknowledge string in a short period of time.  If
		   that is not true then these characters are coming from
		   the user and we need to send the ENQ sequence out again.
		*/
		for (ack = 0; ; ) {
			if (ack < TTY_ACK_SIZE - 2) {
				tty_ACK[ack] = ch;
				tty_ACK[ack + 1] = '\0';
			}
			if (ch == ACK_terminator) {
				return trouble;
			}
			if (++ack >= ACK_length) {
				return trouble;
			}
			ch = getnext(STRIP_PARITY);
			if (event_time(TIME_SYNC) > 400000) {
				break;
			}
		}

		set_attr(0);	/* just in case */
		put_crlf();
		if (trouble) {
			/* The terminal won't sync.  Life is not good. */
			return TRUE;
		}
		put_str(" -- sync -- ");
		trouble = TRUE;
	}
}
示例#19
0
int main(){
	int t,T;
	scanf("%d",&T);
	for(t=1;t<=T;t++){
		scanf("%s%s",&s2[1],&s1[1]);
		getnext();
		printf("%d\n",kmp());
	}
}
示例#20
0
文件: view.c 项目: csimons/cswm
void
zoom(Arg *arg) {
    unsigned int n;
    Client *c;

    if(!sel)
        return;

    for(n = 0, c = getnext(clients); c; c = getnext(c->next))
        n++;

    if((c = sel) == getnext(clients))
        if(!(c = getnext(c->next)))
            return;
    pop(c);
    focus(c);
    arrange();
}
示例#21
0
文件: view.c 项目: csimons/cswm
void
arrange(void) {
    unsigned int i, n, mw, mh, tw, th;
    Client *c;

    for(n = 0, c = getnext(clients); c; c = getnext(c->next))
        n++;
    /* window geoms */
    mh = (n > nmaster) ? sh / nmaster : sh / (n > 0 ? n : 1);
    mw = (n > nmaster) ? (sw * master) / 1000 : sw;
    th = (n > nmaster) ? sh / (n - nmaster) : 0;
    tw = sw - mw;

    for(i = 0, c = clients; c; c = c->next)
        if(c->view == view) {
            c->ismax = False;
            c->x = sx;
            c->y = sy;
            if(i < nmaster) {
                c->y += i * mh;
                c->w = mw - 2 * BORDERPX;
                c->h = mh - 2 * BORDERPX;
            }
            else {  /* tile window */
                c->x += mw;
                c->w = tw - 2 * BORDERPX;
                if(th > 2 * BORDERPX) {
                    c->y += (i - nmaster) * th;
                    c->h = th - 2 * BORDERPX;
                }
                else /* fallback if th <= 2 * BORDERPX */
                    c->h = sh - 2 * BORDERPX;
            }
            resize(c, False);
            i++;
        }
        else
            XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
    if(!sel || sel->view != view) {
        for(c = stack; c && c->view != view; c = c->snext);
        focus(c);
    }
    restack();
}
示例#22
0
文件: 1.d.c 项目: EyciaZhou/acm
int main() {
	long T;
	int n, i, j, q, p;
	char st[55], c;
	bool f;
	scanf("%ld", &T);
	while (T--) {
		for (i = 0; i < 1005; i++) {
			for (j = 0; j <= 26; j++) {
				tire[i].n[j] = -1;
			}
			tire[i].f = 0;
			tire[i].d = -1;
			tire[i].b = false;
		}
		scanf("%d", &n);
		p = 0;
		for (i = 0; i < n; i++) {
			scanf("%s", st);
			q = 0;
			for (j = 0; j < strlen(st); j++) {
				
				if (st[j] >= 'a' && st[j] <= 'z') {
					if (tire[q].n[st[j] - 'a'] < 0) {
						tire[q].n[st[j] - 'a'] = ++p;
						tire[p].d = st[j] - 'a';
						tire[p].fa = q;
					}
					q = tire[q].n[st[j] - 'a'];
				}
			}
			tire[q].b = true;
		}
		getchar();
		dof();
		q = 0;
		f = true;
		while (true) {
			c = getchar();
			if (c == '\n' || c == EOF) {
				break;
			}

			q = getnext(q, c - 'a');
			if (tire[q].b) {
				f = false;
			}
			
		}
		if (f) {
			printf("not infected\n");
		}else{
			printf("infected\n");
		}
	}
}
示例#23
0
int
getchp(int mask)
{				/* read a character with scan mode conversion */
	if (scan_mode) {
		tc_putp(req_for_input);
		fflush(stdout);
		return scan_key();
	} else
		return getnext(mask);
}
示例#24
0
文件: address.c 项目: daniw/mc
/**
 * Function to get the size of the Linkd List
 * @return size of the Linked List in number of data sets
 */
int getsize()
{
    nodePtr_t n = getfirst();
    int i = 0;
    while(n != NULL)
    {
        n = getnext(n);
        i++;
    }
    return i;
}
示例#25
0
void kmp()
{
	getnext();
	int i=0,j=0;
	while(i<lens)
	{
		if(j==-1||a[j]==s[i]) i++,j++;
		else j=next[j];
		if(j==lena) ans[res++]=i-lena;
	}
}
示例#26
0
/*
 *	sumcurr sums all entries with same uid/name (into tp->tacct record)
 *	writes it out, gets new entry
 */
void
sumcurr(struct tacct *tp)
{
	struct tacct tc;
	char *memcpy();

	memcpy(&tc, tp, sizeof(struct tacct));
	tacctadd(&tt, tp);	/* gets total of all uids */
	getnext(tp-&tb[0]);	/* get next one in same file */
	while (tp <= &tb[nfile])
		if (tp->ta_name[0] != '\0' &&
			tp->ta_uid == tc.ta_uid &&
			(uidsum || EQN(tp->ta_name, tc.ta_name))) {
			tacctadd(&tc, tp);
			tacctadd(&tt, tp);
			getnext(tp-&tb[0]);
		} else
			tp++;	/* look at next file */
	if (!totalonly)
		output(&tc);
}
示例#27
0
文件: crc.c 项目: nowke/cn2-lab
void CRC(length) {
    int CCITT[] = {1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1};
    int i=0, pos=0, newpos;
    while (pos < length-16) {

        for (i=pos; i<pos+16+1; ++i)
            result[i] = mod2add(result[i], CCITT[i-pos]);
        newpos = getnext(result, pos);
        if (newpos > pos+1)
            pos = newpos-1;
        ++pos;
    }
}
void init() {
    int now = 0;
    for (int i = 0; i < 3; i++)
    out[on++] = 'a';
    while (true) {
    int Min = 26, iv = 0;
    for (int i = 1; i < 26; i++) {
        if (vis2[now][i]) continue;
        int tmp = getnext(now, i);
        if (vis[tmp] < Min) {
        Min = vis[tmp];
        iv = i;
        }
    }
    int tmp = getnext(now, iv);
    if (vis[tmp] == 26) break;
    vis2[now][iv] = 1;
    now = tmp;
    vis[now]++;
    out[on++] = now % 26 + 'a';
    }
}
示例#29
0
文件: sudoku.c 项目: gnimnet/sudoku
int main(){
	setsudoku();//特定问题
	//initsudoku();//起始行为123456789
	printsudoku();
	if(getnext(0,0)){
		printf("Get It!\n");
		printsudoku();
	}
	else{
		printf("Not get it!\n");
	}
	return 0;
}
示例#30
0
	void Footholdtree::updatefh(PhysicsObject& phobj) const
	{
		if (phobj.fhid == 0)
		{
			phobj.fhid = getbelow(phobj.fx, phobj.fy);
		}
		else if (phobj.onground)
		{
			const Foothold& curfh = getfh(phobj.fhid);
			if (phobj.fx > curfh.getr())
			{
				phobj.fhid = getnext(phobj.fhid, false, phobj.fx, phobj.fy);
			}
			else if (phobj.fx < curfh.getl())
			{
				phobj.fhid = getnext(phobj.fhid, true, phobj.fx, phobj.fy);
			}
		}
		else
		{
			phobj.fhid = getbelow(phobj.fx, phobj.fy);
		}

		const Foothold& nextfh = getfh(phobj.fhid);
		phobj.fhlayer = nextfh.getlayer();
		phobj.fhslope = nextfh.getslope();

		float ground = nextfh.resolvex(phobj.fx);
		if (phobj.vspeed == 0.0f)
		{
			if (abs(ground - phobj.fy) <= abs(phobj.hspeed))
			{
				phobj.fy = ground;
			}
		}
		phobj.onground = phobj.fy == ground;
	}