Esempio n. 1
0
main()//m为4,n为5,其它为1,3,11,15,32
{
	int m=1,n=1,i,j,z,x,k,y,t,l,zuida;//m=4张,n=5种,x就为它最大的连续的那一个数,b记录已用的张数
	int a[10],b[MAX];
	for(i=0;i<MAX;i++)
		b[i]=0;
	printf("please input the m and n: ");
	while(m!=0 && n!=0)
	{
		scanf("%d %d",&m,&n);
		printf("please input the value:");
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);//存储各个数
		paixu(a,n);//对输入的几个数排序
		for(i=0;i<n;i++)
			b[i]=a[i];//第一轮
		zuida=jisuan(m,n);//计算总共有多少种可重复的可能,是n的m次方
		t=1;
		k=0;
		l=n;
		for(;i<zuida;)
		{
			t=i;
			for(j=0;j<l;j++)
			{
				b[i]=b[t-(n+k*5)+k]+a[j];
				printf("%d ",b[i]);
				i++;
				if(i==(t+5))
					k++;
				if(k==5)
				{
					k=0;
					n=n*n;
				}
			}
		}
		printf("\n");
		z=1;//我记得前面没有改变z的值嘎,为什么这里不给它赋值就不得行呀
		y=1;
		x=1;
		printf("\n%d ",z);
		while(y==1)//m为4,n为5,其它为1,3,11,15,32
		{
			for(i=0;i<zuida && x==1;i++)
			{
				if(z==b[i])
				{
					x=0;
					z++;
					printf("%d ",z);
				}
			}
			if(x==1)
				y=0;
			x=1;
		}
		printf("\n\n1-%d\n",z-1);
	}
}
Esempio n. 2
0
//when popping one char in charstack, two nums will be popped.
void pop_pro(stacknum *list_num, stackchar *list_char)
{
	int pop_num1,pop_num2,res;
	char pop_char1;
	pop_num1=pop_num_stack(list_num);//pop the first elem
	pop_num2=pop_num_stack(list_num);//pop the second elem
	pop_char1=pop_char_stack(list_char);//pop the top operator

	res=jisuan( pop_char1, pop_num1,  pop_num2);//calcu the res and push it into the numstack
	push_num_stack(list_num, res);
}
Esempio n. 3
0
int main(int argc, char *argv[])
{

	double ps[10][14]; int i, j;
	double r[] = { 1.5,2,3,4,5,6,9,12,15,20,30,45,60,90 };// AB/2 
	double p1[] = { 50,60,60,100,250,40,30,20,50,5 };//一层电阻率 
	double p2[] = { 40,30,20,50,5,50,60,60,100,250 };//二层电阻率 
	double h[] = { 2,4,6,8,10,2,4,6,8,10 };//层厚度 

	FILE *fp;
	fp = fopen("xxx.txt", "w");
	for (i = 0; i<10; i++)
	{

		for (j = 0; j<14; j++)
		{
			ps[i][j] = jisuan(r[j], p1[i], p2[i], h[i]);

			//fprintf(fp,"%f\t%f\t",r[j]/2/h[i],ps[i][j]/p1[i]);

			//printf("%f\t%f\t",r[j]/2/h[i],ps[i][j]/p1[i]);
		}
		//fprintf(fp,"\n");
		//printf("\n");
	}
	for (j = 0; j<14; j++)
	{
		for (i = 0; i<10; i++)
		{
			printf("%f\t%f\t", r[j] / 2 / h[i], ps[i][j] / p1[i]);
			fprintf(fp, "%f\t%f\t", r[j] / 2 / h[i], ps[i][j] / p1[i]);
		}
		fprintf(fp, "\n");
		printf("\n");
	}
	return 0;
}
Esempio n. 4
0
struct Node* regular_expression_syntax_tree(char *s)
{
	int i,j,f=0;
	inpp=outpp=0;
	for(i=0;;i++)
	{
		if(!isprint(s[i]) && s[i]!='\t' && s[i]!='\n' && s[i]!='\0')return NULL;
		switch(s[i])
		{
		case '*':
		case '\0':
		case '|':
			while(inpp>0 && priority[in[inpp]]>=priority[s[i]])
				if(jisuan(in[inpp--])==-1)return NULL;
			in[++inpp]=s[i];
			if(s[i]=='|')f=0;
			break;
		case '(':
			if(f)
			{
				while(inpp>0 && priority[in[inpp]]>=priority['&'])
					if(jisuan(in[inpp--])==-1)return NULL;
				in[++inpp]='&';
			}
			in[++inpp]=s[i];
			f=0;
			break;
		case ')':
			while(inpp>0 && in[inpp]!='(')
				if(jisuan(in[inpp--])==-1)return NULL;
			if(inpp--==0)return NULL;
			f=1;
			break;
		case '@':
			char regular[16];
			for(j=0;s[++i]!='@' && s[i]!='\0' && j<15;j++)regular[j]=s[i];
			if(s[i]!='@')return NULL;
			regular[j]='\0';
			for(j=0;j<regular_table_size;j++)if(strcmp(regular,regulars[j].name)==0)break;
			if(j==regular_table_size || regulars[j].tree==NULL)return NULL;
			if(f)
			{
				while(inpp>0 && priority[in[inpp]]>=priority['&'])
					if(jisuan(in[inpp--])==-1)return NULL;
				in[++inpp]='&';
			}
			out[++outpp]=copyTree(regulars[j].tree);
			f=1;
			break;
		case '\\':
		default:
			int trans=0;
			if(s[i]=='\\')
			{
				i++;
				trans=1;
			}
			if(f)
			{
				while(inpp>0 && priority[in[inpp]]>=priority['&'])
					if(jisuan(in[inpp--])==-1)return NULL;
				in[++inpp]='&';
			}
			int t;
			if(!trans && s[i]=='$')t='$'+256;
			else t=s[i];
			struct Node *x=newNode(t,NULL,NULL);
			if(trans || s[i]!='$')
			{
				isinput[s[i]]=1;
				x->n=++cc;
				C[x->n]=s[i];
			}
			out[++outpp]=x;
			f=1;
			break;
		}
		if(s[i]=='\0')break;
	}
	if(inpp!=1 || outpp!=1)return NULL;
	return out[1];
}