int go2(int x,int left,int s){
    int i,j;
    v++;
    if(v>1000000){
        for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(a[i]>a[j]){swap(&a[i],&a[j]);}
        for(i=1;i<=m;i++)for(j=1;j<=m;j++)if(b[i]<b[j]){swap(&b[i],&b[j]);swap(&pb[i],&pb[j]);}
        for(i=1;i<=n;i++)c[i]=0;
        v=0;
        return 1;
    }
    if(x==m+1){
        int e=1;
        for(i=1;i<=n;i++)d[c[i]]++;
        for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(c[i]<c[j]){swap(&c[i],&c[j]);swap(&pc[i],&pc[j]);}
        for(i=1;i<=m;i++){
            printf("%d\n",d[i]);
            for(j=1;j<=d[i];j++)printf("%d ",pc[e++]);
            printf("\n");
        }
        exit(0);
    }
    for(i=s;i<=n;i++){
        if(c[i]||left<a[i])continue;
        c[i]=pb[x];
        pc[i]=a[i];
        if(left==a[i])j=go2(x+1,b[x+1],1);
        else j=go2(x,left-a[i],i+1);
        if(j)return 1;
        c[i]=0;
    }
    return 0;
}
Exemple #2
0
void go2 (const std::vector<std::string> &comands, const int deep){

    int pfd[2];
    pipe(pfd);

     if(!fork()){
        close(STDOUT_FILENO);
        dup2(pfd[1],STDOUT_FILENO);
        close(pfd[1]);
        close(pfd[0]);

        exec_command(comands[deep]);
    }
    else{
        close(STDIN_FILENO);
        dup2(pfd[0],STDIN_FILENO);
        close(pfd[1]);
        close(pfd[0]);

        if (deep+2 < comands.size())
            go2(comands, deep+1);
        else
        exec_last_command(comands[deep+1]);
    }

    if (deep != 0)
        exit (0);
}
int main(){
    int i,j;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    for(i=1;i<=m;i++){scanf("%d",&b[i]);pb[i]=i;}
    for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(a[i]<a[j]){swap(&a[i],&a[j]);}
    for(i=1;i<=m;i++)for(j=1;j<=m;j++)if(b[i]<b[j]){swap(&b[i],&b[j]);swap(&pb[i],&pb[j]);}
    j=go(1,b[1],1);
    go2(1,b[1],1);
}
int main(){
    int i,j;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    for(i=1;i<=m;i++){scanf("%d",&b[i]);pb[i]=i;}
    for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(a[i]<a[j]){swap(&a[i],&a[j]);}
    for(i=1;i<=m;i++)for(j=1;j<=m;j++)if(b[i]<b[j]){swap(&b[i],&b[j]);swap(&pb[i],&pb[j]);}
    for(i=1;i<=m;i++){
        for(j=1;j<=n;j++){
            if(b[i]>=a[j]){
                g[i]=j;
                break;
            }
        }
    }
    go(1,b[1],g[1]);
    go2(1,b[1],g[1]);
    go3(1,b[1],g[1]);
}
Exemple #5
0
int main (int, char**){

    char in[1024];
    fgets(in, 1024, stdin);

    auto f = open (LOG_PATH, O_CREAT|O_WRONLY|O_APPEND);
    write (f, in, strnlen(in, 1024));
    close(f);

    auto commands = split(std::string(in), '|');
    for  (auto& c : commands)
        replace (c,"\n","");

    if (commands.size() > 1)
        go2 (commands, 0);
    else if (commands.size())
        exec_last_command(commands[0]);

    sleep(1);
    return 0;
}
int go1(int fo,int fm,int fc,int f,int count,int mcount,unsigned char pass)
{
	char k[count],r[mcount];
	int l = 3 +(f*8),s = 1,q,o = 0,i,j;
	static int f1 = -1;
	unsigned char x,s_x0,s_x1,s_x2,temp,temp1,store,pass1,d;
	printf("START of go1\n");
//	printf("fo is %d\n",fo);
//	printf("fm is %d\n",fm);
//	printf("fc is %d\n",fc);
	printf("l in go1 is %d\n",l);
	lseek(fo,SEEK_SET,0);
	read(fo,&k,count);
	lseek(fm,SEEK_SET,0);
	read(fm,&r,mcount);
	d = k[l];
//	q = (11- 3) / 8;
//	printf("q in go1 is%d\n",q);
	if(d != '\0')
	{
		for(i = l;i < (l + 3);i++)
		{
			for(j = 0;j < mcount;j++)
			{
				if(k[i] == r[j])
				{
					x = j;
					break;
				}
				else
					continue;

			}
			if(j == mcount)
			{
				printf("Exit from go1\n");
				return(1);
			}
			if(i == l)
			{
				x = x << 4;
				s_x0 = x;
			}
			if(i == l+1)
			{
				x = x << 1;
				s_x1 = x;
			}
			if(i == l + 2)
			{
				pass1 = x;
				printf("pass1 in go1 is%d\n",pass1);
				x = x >> 2;
				s_x2 = x;
			}
		}
		pass = pass << 7;
		temp = pass | s_x0;
		temp1 = temp | s_x1;
		store = temp1 | s_x2;
		o++;
		f1++;
//		l += 8;
		write(fc,&store,1);
		printf("store in go1 is %d\n",store);
		go2(fo,fm,fc,f1,count,mcount,pass1);
	printf("END of go1\n");
	}
Exemple #7
0
output(){ /* print the output for the states */

  int i, j, k, c;

  settab();
  arrset("yyact");

  for( i=0; i<nstate; ++i ){ /* output the stuff for state i */
    nolook = (tystate[i]==0);
    closure(i);
    /* output actions */
    aryfil( temp1, nterms+1, 0 );
    for( j=0; j<cwset; ++j ){ /* look at the items */
      c = *( wsets[j].pitem );
      if( c>0 && c<NTBASE && temp1[c]==0 ) temp1[c] = go2(i,c);
      }

    if( i == 1 ) temp1[1] = ACCEPTCODE;

    /* now, we have the shifts; look at the reductions */

    lastred = 0;
    for( j=0; j<cwset; ++j ){
      c = *( wsets[j].pitem );
      if( c<=0 ){ /* reduction */
        lastred = -c;
        for( k=1; k<=nterms; ++k ){
          if( ((wsets[j].ws[k>>4])&(1<<(k&017))) != 0 ) {
            if( temp1[k] == 0 ) temp1[k] = c;
            else if( temp1[k]<0 ){ /* reduce/reduce conflict */
              settty();
              printf("\n%d: reduce/reduce conflict (red'ns %d and %d ) on %s",
                i, -temp1[k], lastred, symnam(k) );
              if( -temp1[k] > lastred ) temp1[k] = -lastred;
              ++zzrrconf;
              settab();
              }
            else { /* potential shift/reduce conflict */
              switch( precftn( lastred, k ) ) {

            case 0: /* precedence does not apply */

                settty();
                printf("\n%d: shift/reduce conflict (shift %d, red'n %d) on %s", i,
			temp1[k], lastred, symnam(k) );
                ++zzsrconf;
                settab();
                break;

            case 1: /*  reduce */

                temp1[k] = -lastred;
                break;

            case 2: /* error, binary operator */

                temp1[k] = ERRCODE;
                break;

            case 3: /* shift ... leave the entry alone */

                break;
                }
              }
            }
          }
        }
      }
    wract(i);
    }