コード例 #1
0
ファイル: two.cpp プロジェクト: Nexfer/DlinAriph
	veryLong veryLong::operator+(veryLong n1)
	{
		veryLong n;
		unsigned char *del;
		if (!binary)
		{
			turn(&number);
			turn(&n1.number);
			del=n.number;
			if ((znak=='+')&&(n1.znak=='+'))
			{
				n.number = summ(&number,&n1.number);
				n.znak='+';
			}
			if ((znak=='-')&&(n1.znak=='-'))
			{
				n.number = summ(&number,&n1.number);
				n.znak='-';
			}
			if ((znak=='+')&&(n1.znak=='-'))
			{
				if (cmp(&number,&n1.number) == 1)
					{
						n.number = sub(&number,&n1.number);
						n.znak='+';
					}
					else
					{
						n.number = sub(&n1.number,&number);
						n.znak='-';
					}
			}
			if ((znak=='-')&&(n1.znak=='+'))
			{
				if (cmp(&number,&n1.number) == 1)
					{
						n.number = sub(&number,&n1.number);
						n.znak='-';
					}
					else
					{
						n.number = sub(&n1.number,&number);
						n.znak='+';
					}
			}
			n.lenght = strlenn(&n.number);
			n.binary=binary;
			turn(&number);
			turn(&n1.number);
			turn(&n.number);
			if (del != NULL)
				free(del);
		}
		else
		{
			n.number = summb(&number,&n1.number,lenght,n1.lenght,&n.lenght);
			n.binary=binary;
		}
		return n;
	}
コード例 #2
0
int* sub(int* a,int* b,int size_a,int size_b,bool sign_a,bool sign_b,bool &sign_result,int &size_result)
{
	int* res;
	if(sign_a == sign_b)
	{
		size_result=size_a+1;
		if(size_a<size_b)
		{
			size_result=size_b+1;
		}

		res = (int*) malloc((size_result + 2)*sizeof(int));
	
		int* a1 = (int*) malloc((size_result + 2)*sizeof(int));
		int* b1 = (int*) malloc((size_result + 2)*sizeof(int));
		for(int i=0;i<size_result;++i)
			res[i]=0;
		for(int i=0;i<size_result;++i)
			b1[i]=0;
		for(int i=0;i<size_result;++i)
			a1[i]=0;
		for(int i=0;i<size_b;++i)
			b1[i]=b[i];
		for(int i=0;i<size_a;++i)
			a1[i]=a[i];

		sign_result=sign_a;
		if(is_bigger(b,size_b,a,size_a))
		{
			int* buff=b1;
			b1=a1;
			a1=buff;
			int buf=size_b;
			size_b=size_a;
			size_a=buf;
			sign_result=!sign_result;
		}
		for(int i=0;i<size_result;++i)
		{
			res[i]+=a1[i]-b1[i];
			if(res[i]<0 && i<size_result-1)
			{
				res[i]+=10;
				res[i+1]-=1;
			}
		}
		free(a1);
		free(b1);
	}
	else if(sign_a)
		res = summ(a,b,size_a,size_b,1,1,sign_result,size_result);
	else
		res = summ(a,b,size_a,size_b,0,0,sign_result,size_result);
	while (res[size_result-1] == 0)
		size_result-- ;
	
	return res;

}
コード例 #3
0
ファイル: two.cpp プロジェクト: Nexfer/DlinAriph
	veryLong veryLong::operator-(veryLong n1)
	{
		veryLong n;
		if (!binary)
		{
			turn(&number);
			turn(&n1.number);
			if ((znak=='+')&&(n1.znak=='+'))
			{
				if (cmp(&number,&n1.number) == 1)
					{
						n.number = sub(&number,&n1.number);
						n.znak='+';
					}
					else
					{
						n.number = sub(&n1.number,&number);
						n.znak='-';
					}
			}
			if ((znak=='-')&&(n1.znak=='+'))
			{
				if (cmp(&number,&n1.number) == 1)
					{
						n.number = sub(&number,&n1.number);
						n.znak='-';
					}
					else
					{
						n.number = sub(&n1.number,&number);
						n.znak='+';
					}
			}
			if ((znak=='+')&&(n1.znak=='-'))
			{
				n.number = summ(&number,&n1.number);
				n.znak='+';
			}
			if ((znak=='-')&&(n1.znak=='+'))
			{
				n.number = summ(&number,&n1.number);
				n.znak='-';
			}
			n.lenght = strlenn(&n.number);
			n.binary=binary;
			turn(&number);
			turn(&n1.number);
			turn(&n.number);
		}
		else
		{
			n.number = subb(&number,&n1.number,lenght,n1.lenght,&n.lenght);
			n.binary=binary;
		}
		return n;
	}
コード例 #4
0
ファイル: main.c プロジェクト: TanyaZavyalova/LongArith
unsigned char *stepen(unsigned char **numberOne,unsigned char **numberTwo,unsigned char *znak)
{
	int i,flag;
	unsigned  char *firstNumber,*st,*incr;
	firstNumber = (unsigned char*)malloc(strlen((*numberOne)+2));
	st = (unsigned char*)malloc(block);
	incr = (unsigned char*)malloc(4);
	st[0]='0';
	st[1]='\0';
	incr[0]='1';
	incr[1]='\0';
	if ((*znak)=='+')
		flag=0;
	else
		flag=1;
	strcpy(firstNumber,(*numberOne));
	while(1)
	{
		st = summ(&st,&incr);
		if (strcmp(st,(*numberTwo)) == 0)
			break;
		if (flag==1)
			if ((*znak)=='+')
				(*znak)='-';
			else
				(*znak)='+';
		firstNumber = mul(&(*numberOne),&firstNumber);
	}
	return firstNumber;
}
コード例 #5
0
	Review_pp unpack() const{
		auto rr = Reviewer_pp((Reviewer::Memo(reviewer)).unpack());
		auto pr = Product_pp((Product::Memo(product)).unpack());
		strlt sents;
		for (auto s : sentences) sents.push_back(strt(s));
		strt summ(summary);
		strt txt(text);
		return builder::b()->build(id,summ,sents,score,time,rr,help,pr,txt);
	}
コード例 #6
0
ファイル: fwsum1.c プロジェクト: JennyferM023/COP3514
main()
{
int a[N], i;

for (i = 0; i < N; i++) {
   *(a+i)  = i;
}

summ(a);
}
コード例 #7
0
long long int sumupto(long long int d)
{
    int i=0;
    long long int ans = sum(d);
    while(d>0)
    {
        int digit = d%10;
        ans += (digit*(sum(d)-digit)*pow(10,i)) + summ(digit-1)*pow(10,i) +sumdd(i)*digit;
        //printf("d=%ld,digit=%d,i=%d,ans=%lld\n",d,digit,i,ans);
        i++;
        d /=10;
    }
    return ans;
}
コード例 #8
0
ファイル: main.c プロジェクト: TanyaZavyalova/LongArith
unsigned char *mul(unsigned char **numberOne,unsigned char **numberTwo)
{
    unsigned char *result,*help,*del;
    int i,j,carry,temp;
    result = (unsigned char*)malloc(block);
	for (i=0;i<strlen((*numberOne))*strlen((*numberTwo))+5;i++)
		result[i]='0';
	i=0;
    help = (unsigned char*)malloc(strlen((*numberOne))*strlen((*numberTwo))+5);
    while (1)
    {
        if ((*numberTwo)[i] == '\0')
            break;
        for (j=0;j<i;j++)
            help[j]='0';
        j=0;carry=0;
        while(1)
        {
            if ((*numberOne)[j] == '\0')
                break;
            temp = ((*numberTwo)[i]-48)*((*numberOne)[j]-48);
            help[i+j] = (temp+carry)%10+48;
            carry = (temp+carry) / 10;
            j++;
        }
		if (carry != 0)
		{
			help[i+j] = carry+48;
			help[i+j+1]='\0';
		}
		else
			help[i+j] = '\0';
		if (i != 0)
		{
			del=result;
			result = summ(&result,&help);
			free(del);
		}
		else
			strncpy(result,help,strlen(help)+1);
        i++;
    }
	free(help);
    return result;
}
コード例 #9
0
int main()
{
	gen_fact_inv();
	gen_bernolli();
	summ();
	gen_power();
	ll t=input();
	while(t--)
	{
		ll m,k,x,n,i,ans = 0;
		n=input();
		m=input();
		ll p=1;
		for(i=0;i<=m+2;i++)
		{
			if(f[m][i])
				ans = (ans + f[m][i]*p)%mod;
			p = (p*n)%mod;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
コード例 #10
0
int _tmain(int argc, _TCHAR* argv[])
{
    srand(time(NULL));
    int** a=(int**)malloc(7*sizeof(int*));
    for (int i = 0; i < 7; i++)
	{
        a[i]=(int*) malloc(8*sizeof(int));
	}

	for (int i = 0; i < 7; i++)
	{
        for (int j = 0; j < 8; j++)
		{
            a[i][j]=rand()%30;
            printf("%d ",a[i][j]);
		}
        printf("\n");
	}
	
    int* b=(int*)malloc(8*sizeof(int)) ;
    for (int i = 0; i < 8; i++)
    {
        b[i]=summ(i, a);
    }
	
    printf("\n");

    for (int j = 0; j < 8; j++)
		{
            printf("%d ",b[j]);
		}
	
    printf("\nmin summ from %d, max summ from %d cols\n",min(b), max(b));
    
	system("pause");
	return 0;
}
コード例 #11
0
ファイル: longArith.c プロジェクト: TanyaZavyalova/TCHMK
int main(int argc, char *argv[])
{
    FILE *output;
    char *inputFirst,*inputSecond,*inputThird;
    int lengthFirst,lengthSecond,i,binary,module,lengthModule;
    unsigned char *numberOne,*numberTwo,*remainder,*numModule;
	unsigned char sign1,sign2,sign3;
	char sign;
	if (argc < 5 )
	{
		printf("\nEnter correct parameters\n");
		return 0;
	}
    if (argc < 6)
	{
		binary=0;
		module=0;
	}
    if (argc == 6)
	{
		if (strcmp(argv[5],"-b") == 0)
		{
			binary=1;
			module=0;
		}
		else
		{
			binary=0;
			module=1;
			inputThird=argv[5];
			lengthModule = readd(&numModule,inputThird,&sign3);
		}
	}
	if (argc == 7)
	{
		binary=1;
		module=1;
		inputThird=argv[6];
		lengthModule = readb(&numModule,inputThird);
	}
	
	inputFirst =argv[1];
    inputSecond=argv[3];

    if(!binary)
    {

        output = fopen(argv[4],"w");
    }
    else
    {
        output = fopen(argv[4],"wb");
    }

	sign=argv[2][0];
	switch(sign)
	{
		case '+' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((sign1=='+')&&(sign2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((sign1=='-')&&(sign2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
				if ((sign1=='+')&&(sign2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((sign1=='-')&&(sign2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=summb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '-' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((sign1=='+')&&(sign2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((sign1=='-')&&(sign2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
				if ((sign1=='+')&&(sign2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((sign1=='-')&&(sign2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=subb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '*' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				if (((sign1=='+')&&(sign2=='+'))||((sign1=='-')&&(sign2=='-')))
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
				}
				else
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=mulb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '/' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				if (((sign1=='+')&&(sign2=='+'))||((sign1=='-')&&(sign2=='-')))
				{
					fprintf(output,"%s",divv(&numberOne,&numberTwo,&remainder));
				}
				else
				{
					fprintf(output,"-%s",divv(&numberOne,&numberTwo,&remainder));
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lengthFirst);
				turnb(&numberTwo,lengthSecond);
				numberOne=divvb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst,&remainder,&lengthSecond);
				turnb(&numberOne,lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '%' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				divv(&numberOne,&numberTwo,&remainder);
				fprintf(output,"%s",remainder);
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lengthFirst);
				turnb(&numberTwo,lengthSecond);
				divvb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst,&remainder,&lengthSecond);
				turnb(&remainder,lengthSecond);
				fwrite(remainder,lengthSecond,1,output);
				free(remainder);
			}
			break;

		case '^' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				numberOne=degree(&numberOne,&numberTwo,&sign1);
				turn(&numberOne);
				if (sign1=='+')
					fprintf(output,"%s",numberOne);
				else
					fprintf(output,"-%s",numberOne);
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=degreeb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;
		default:
			break;
	}

    fclose(output);

	if (module)
	{
		if(!binary)
		{
			output = fopen(argv[4],"w");
			divv(&numberOne,&numModule,&remainder);
			fprintf(output,"%s",remainder);
		}
		else
		{
			output = fopen(argv[4],"wb");
			turnb(&numberOne,lengthFirst);
			turnb(&numModule,lengthModule);
			divvb(&numberOne,&numModule,lengthFirst,lengthModule,&lengthFirst,&remainder,&lengthModule);
			turnb(&remainder,lengthModule);
			fwrite(remainder,lengthModule,1,output);
		}
		fclose(output);
	    
	}
    return 0;
}
コード例 #12
0
	friend const BigInt operator+(BigInt const a, BigInt const b)
	{
		BigInt res;
		res.num = summ(a.num,b.num,a.size,b.size,a.sign,b.sign,res.sign,res.size);
		return res;
	}
コード例 #13
0
ファイル: main.c プロジェクト: TanyaZavyalova/LongArith
unsigned char *divv(unsigned char **numberOne,unsigned char **numberTwo,unsigned char **ostatok)
{
	int i,j,k,q;
	unsigned char *delimoe,*delitel,*answer;
	delimoe = (unsigned char*)malloc(2*strlen((*numberOne)));
	delitel = (unsigned char*)malloc(2*strlen((*numberTwo)));
	answer = (unsigned char*)malloc(2*strlen((*numberOne)));
	q=0;
	i=0;j=0;
	while(1)
	{
		if ((*numberOne)[i]=='\0')
			break;
		if ((j != 0) || ((*numberOne)[i] != '0'))
		{
			delimoe[j]=(*numberOne)[i];
			delimoe[j+1]='\0';
		}
		else
			j--;
		if (cmp(&delimoe,&(*numberTwo)) > 0)
		{
			for (k=0;k<=strlen((*numberTwo));k++)
				delitel[k]=(*numberTwo)[k];
			k=1;
			while(1)
			{
				if (cmp(&delitel,&delimoe) > 0)
				{
					if (strcmp(delitel,delimoe) != 0)
					{
                        if (strlen(delitel) != 1)
                            turn(&delitel);
                        if ((strlen(*numberTwo)) != 1)
                            turn(&(*numberTwo));
                        delitel = sub(&delitel,&(*numberTwo));
                        if (strlen(delitel) != 1)
                            turn(&delitel);
                        if ((strlen(*numberTwo)) != 1)
                            turn(&(*numberTwo));
                        k--;
					}
					answer[q]=k+48;
					q++;
					break;
				}
				else
				{
					if (strlen(delitel) != 1)
						turn(&delitel);
					if ((strlen(*numberTwo)) != 1)
						turn(&(*numberTwo));
					delitel=summ(&delitel,&(*numberTwo));
					if (strlen(delitel) != 1)
						turn(&delitel);
					if ((strlen(*numberTwo)) != 1)
						turn(&(*numberTwo));
					k++;
				}
			}
			if (strlen(delimoe) != 1)
				turn(&delimoe);
			if (strlen(delitel) != 1)
				turn(&delitel);
			delimoe = sub(&delimoe,&delitel);
			if (strlen(delimoe) != 1)
				turn(&delimoe);
			if (strlen(delitel) != 1)
				turn(&delitel);
			j=strlen(delimoe);
			if ((strlen(delimoe) == 1) && (delimoe[0]=='0'))
				j=0;
			i++;
		}
		else
		{
			if (q != 0)
			{
				answer[q]='0';
				q++;
			}
			j++;
			i++;
		}
        
	}
	if (q != 0)
		answer[q]='\0';
	else
	{
		answer[0]='0';
		answer[1]='\0';
	}
	if (j != 0)
		(*ostatok)=delimoe;
	else
	{
		(*ostatok)=delimoe;
		(*ostatok)[1]='\0';
	}
    
	return answer;
}
コード例 #14
0
ファイル: main.c プロジェクト: TanyaZavyalova/LongArith
int main(int argc, char *argv[])
{
    char *inputFirst,*inputSecond,*inputThird;
    FILE *output;
    int lenghtFirst,lenghtSecond,i,binary,module,lenghtModule;
    unsigned char *numberOne,*numberTwo,*ostatok,*numModule;
	unsigned char znak1,znak2,znak3;
	char znak;
	if (argc < 5 )
	{
		printf("\nEnter correct parameters\n");
		return 0;
	}
	if (argc == 7)
	{
		binary=1;
		module=1;
		inputThird=argv[6];
		lenghtModule = readb(&numModule,inputThird);
	}
	if (argc == 6)
	{
		if (strcmp(argv[5],"-b") == 0)
		{
			binary=1;
			module=0;
		}
		else
		{
			binary=0;
			module=1;
			inputThird=argv[5];
			lenghtModule = readd(&numModule,inputThird,&znak3);
		}
	}
	if (argc < 6)
	{
		binary=0;
		module=0;
	}
    
    
	inputFirst =argv[1];
    inputSecond=argv[3];
    
    if(!binary)
    {
        
        output = fopen(argv[4],"w");
    }
    else
    {
        output = fopen(argv[4],"wb");
    }
    
	znak=argv[2][0];
	switch(znak)
	{
		case '+' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((znak1=='+')&&(znak2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((znak1=='-')&&(znak2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
				if ((znak1=='+')&&(znak2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((znak1=='-')&&(znak2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=summb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '-' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((znak1=='+')&&(znak2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((znak1=='-')&&(znak2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
				if ((znak1=='+')&&(znak2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((znak1=='-')&&(znak2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=subb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '*' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				if (((znak1=='+')&&(znak2=='+'))||((znak1=='-')&&(znak2=='-')))
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
				}
				else
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=mulb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '/' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				if (((znak1=='+')&&(znak2=='+'))||((znak1=='-')&&(znak2=='-')))
				{
					fprintf(output,"%s",divv(&numberOne,&numberTwo,&ostatok));
				}
				else
				{
					fprintf(output,"-%s",divv(&numberOne,&numberTwo,&ostatok));
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lenghtFirst);
				turnb(&numberTwo,lenghtSecond);
				numberOne=divvb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst,&ostatok,&lenghtSecond);
				turnb(&numberOne,lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '%' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				divv(&numberOne,&numberTwo,&ostatok);
				fprintf(output,"%s",ostatok);
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lenghtFirst);
				turnb(&numberTwo,lenghtSecond);
				divvb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst,&ostatok,&lenghtSecond);
				turnb(&ostatok,lenghtSecond);
				fwrite(ostatok,lenghtSecond,1,output);
				free(ostatok);
			}
			break;
            
		case '^' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				numberOne=stepen(&numberOne,&numberTwo,&znak1);
				turn(&numberOne);
				if (znak1=='+')
					fprintf(output,"%s",numberOne);
				else
					fprintf(output,"-%s",numberOne);
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=stepenb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
		default:
			break;
	}
    
    fclose(output);
    
	if (module)
	{
		if(!binary)
		{
			output = fopen(argv[4],"w");
			divv(&numberOne,&numModule,&ostatok);
			fprintf(output,"%s",ostatok);
		}
		else
		{
			output = fopen(argv[4],"wb");
			turnb(&numberOne,lenghtFirst);
			turnb(&numModule,lenghtModule);
			divvb(&numberOne,&numModule,lenghtFirst,lenghtModule,&lenghtFirst,&ostatok,&lenghtModule);
			turnb(&ostatok,lenghtModule);
			fwrite(ostatok,lenghtModule,1,output);
		}
		fclose(output);
	    
	}
    return 0;
}
コード例 #15
0
ファイル: function.c プロジェクト: TanyaZavyalova/TCHMK
unsigned char *divv(unsigned char **numberOne,unsigned char **numberTwo,unsigned char **remainder)
{
	int i,j,k,q;
	unsigned char *dividend,*divisor,*answer;
	dividend = (unsigned char*)malloc(2*strlen((*numberOne)));
	divisor = (unsigned char*)malloc(2*strlen((*numberTwo)));
	answer = (unsigned char*)malloc(2*strlen((*numberOne)));
	q=0;
	i=0;j=0;
	while(1)
	{
		if ((*numberOne)[i]=='\0')
			break;
		if ((j != 0) || ((*numberOne)[i] != '0'))
		{
			dividend[j]=(*numberOne)[i];
			dividend[j+1]='\0';
		}
		else
			j--;
		if (cmp(&dividend,&(*numberTwo)) > 0)
		{
			for (k=0;k<=strlen((*numberTwo));k++)
				divisor[k]=(*numberTwo)[k];
			k=1;
			while(1)
			{
				if (cmp(&divisor,&dividend) > 0)
				{
					if (strcmp(divisor,dividend) != 0)
					{
					if (strlen(divisor) != 1)
						turn(&divisor);
					if ((strlen(*numberTwo)) != 1)
						turn(&(*numberTwo));
					divisor = sub(&divisor,&(*numberTwo));
					if (strlen(divisor) != 1)
						turn(&divisor);
					if ((strlen(*numberTwo)) != 1)
						turn(&(*numberTwo));
					k--;
					}
					answer[q]=k+48;
					q++;
					break;
				}
				else
				{
					if (strlen(divisor) != 1)
						turn(&divisor);
					if ((strlen(*numberTwo)) != 1)
						turn(&(*numberTwo));
					divisor=summ(&divisor,&(*numberTwo));
					if (strlen(divisor) != 1)
						turn(&divisor);
					if ((strlen(*numberTwo)) != 1)
						turn(&(*numberTwo));
					k++;
				}
			}
			if (strlen(dividend) != 1)
				turn(&dividend);
			if (strlen(divisor) != 1)
				turn(&divisor);
			dividend = sub(&dividend,&divisor);
			if (strlen(dividend) != 1)
				turn(&dividend);
			if (strlen(divisor) != 1)
				turn(&divisor);
			j=strlen(dividend);
			if ((strlen(dividend) == 1) && (dividend[0]=='0'))
				j=0;
			i++;
		}
		else
		{
			if (q != 0)
			{
				answer[q]='0';
				q++;
			}
			j++;
			i++;
		}

	}
	if (q != 0)
		answer[q]='\0';
	else
	{
		answer[0]='0';
		answer[1]='\0';
	}
	if (j != 0)
		(*remainder)=dividend;
	else
	{
		(*remainder)=dividend;
		(*remainder)[1]='\0';
	}

	return answer;
}
コード例 #16
0
ファイル: main.cpp プロジェクト: vitfil/ananas-labs
int main(int argc, char **argv)
{
    QApplication appication(argc,argv,false);
    aDatabase db;
    QString log, globalConfig, localConfig;
    const QString test_name = "test saldo1";
    log = 		aTests::parseCommandLine(argc,argv,"--log");
    globalConfig = 	aTests::parseCommandLine(argc,argv,"--globalconfig");
    localConfig = 	aTests::parseCommandLine(argc,argv,"--localconfig");

    QMap<QString,QString> mapGlobal = aTests::readConfig(globalConfig,log);
    QMap<QString,QString> mapLocal = aTests::readConfig(localConfig,log);

    createConfiguration(mapGlobal,mapLocal,log);

    if(db.init(mapLocal["db_rc"]))
    {
        aTests::print2log(log,test_name,"OK",QString("database init"));
        if(db.update())
        {
            aTests::print2log(log,test_name,"OK",QString("database update"));
        }
        else
        {
            aTests::print2log(log,test_name,"ERROR",QString("database update"));
            return 1;
        }
    }
    else
    {
        aTests::print2log(log,test_name,"ERROR",QString("database init"));
        return 1;
    }

    int count_doc =10;
    int count_table_line=10;

    if(mapLocal.find("document count")!=mapLocal.end())
    {
        count_doc = mapLocal["document count"].toInt();
    }
    else
    {
        aTests::print2log(log,test_name,"WARNING",QString("can't find parametr `document count'"));
    }
    if(mapLocal.find("document table count")!=mapLocal.end())
    {
        count_table_line = mapLocal["document table count"].toInt();
    }
    else
    {
        aTests::print2log(log,test_name,"WARNING",QString("can't find parametr `document table count'"));
    }
    int i=0;
    int j;
    aCatalogue* cat1 = new aCatalogue("Контрагенты",&db);
    if(cat1)
    {
        aTests::print2log(log,test_name,"OK",QString("catalogue1 create"));
    }
    else
    {
        aTests::print2log(log,test_name,"ERROR",QString("catalog1 create"));
        return 1;
    }
    aCatalogue* cat2 = new aCatalogue("Товары",&db);
    if(cat2)
    {
        aTests::print2log(log,test_name,"OK",QString("catalogue2 create"));
    }
    else
    {
        aTests::print2log(log,test_name,"ERROR",QString("catalog2 create"));
        return 1;
    }

    delete_cat(cat1);
    delete_cat(cat2);
    if(create_cat(cat1,"contragent", count_doc)==0)
    {
        aTests::print2log(log,test_name,"OK",QString("catalogue1 fill"));
    }
    else
    {
        aTests::print2log(log,test_name,"WARNING",QString("catalog1 fill"));
    }

    if(create_cat(cat2,"towar",count_table_line)==0)
    {
        aTests::print2log(log,test_name,"OK",QString("catalogue2 fill"));
    }
    else
    {
        aTests::print2log(log,test_name,"WARNING",QString("catalog2 fill"));
    }

    cat1->Select();

    if(cat1->First())
    {
        aTests::print2log(log,test_name,"OK",QString("catalogue1 select"));
    }
    else
    {
        aTests::print2log(log,test_name,"ERROR",QString("catalogue1 select"));
        return 1;
    }
    cat2->Select();

    aDocument *doc = new aDocument("Тестовый документ",&db);
    if(doc)
    {
        aTests::print2log(log,test_name,"OK",QString("test document created"));
    }
    else
    {
        aTests::print2log(log,test_name,"ERROR",QString("test document created"));
        return 1;
    }

    aARegister *ar = new aARegister("Главная книга",&db);
    if(ar)
    {
        aTests::print2log(log,test_name,"OK",QString("aAregister created"));
    }
    else
    {
        aTests::print2log(log,test_name,"ERROR",QString("aAregister created"));
        return 1;

    }
    ar->SetDocument(doc);
    ar->SetTable("Таблица");
    QValueList<Q_ULLONG> l;
    for ( i=0; i<count_doc; i++)
    {
        doc->New();
        doc->SetValue("Номер",i);
        doc->SetValue("Дата", QDateTime::currentDateTime());
        doc->SetValue("Основание", QString("тестовое основание #%1").arg(i));
        doc->SetValue("Контрагент", cat1->sysValue("id"));
        doc->Update();
        l.append(doc->getUid());
        aTests::print2log(log,test_name,"NOTE",QString("create doc %1").arg(doc->getUid()));
        cat2->First();
        for(j=0; j<count_table_line; j++)
        {
            doc->TableSelect("Таблица");
            doc->TableNewLine("Таблица");
            doc->TableSetValue("Таблица","Наименование",cat2->sysValue("id"));
            doc->TableSetValue("Таблица","Количество",j+1);
            doc->TableSetValue("Таблица","Цена",1);
            doc->TableSetValue("Таблица","Сумма",j+1);
            doc->TableUpdate("Таблица");
            ar->New();
            ar->SetValue("Дебет","41.2");
            ar->SetValue("Кредит","60");
            ar->SetValue("Количество",j+1);
            ar->SetValue("Сумма",j+1);
            ar->SetValue("Товар",cat2->sysValue("id"));
            ar->SetValue("Контрагент",cat1->sysValue("id"));
            ar->Update();
            cat2->Next();
        }
        cat1->Next();
        if(doc->Conduct()==0)
        {
            aTests::print2log(log,test_name,"OK",QString("document conducted"));
        }
        else
        {
            aTests::print2log(log,test_name,"ERROR",QString("document conducted"));
            return 1;
        }

    }

    bool unconduct=false;

    if(mapLocal.find("unconduct")!=mapLocal.end() && mapLocal["unconduct"].lower()=="true")
    {
        unconduct = true;
    }
    else
    {
        aTests::print2log(log,test_name,"WARNING",QString("can't find parametr `unconduct"));
    }

    QValueList<Q_ULLONG>::iterator it;
    if(unconduct)
    {

        for ( it = l.begin(); it != l.end(); ++it )
        {
            doc->select(*it);
            aTests::print2log(log,test_name,"NOTE",QString("unconduct  doc %1").arg(*it));
            if(doc->IsConducted()) doc->UnConduct();
        }
    }


    int delete_first =0;
    int delete_last=0;

    if(mapLocal.find("delete first")!=mapLocal.end())
    {
        delete_first = mapLocal["delete first"].toInt();
    }
    else
    {
        aTests::print2log(log,test_name,"WARNING",QString("can't find parametr `delete first"));
    }
    if(mapLocal.find("delete last")!=mapLocal.end())
    {
        delete_last = mapLocal["delete last"].toInt();
    }
    else
    {
        aTests::print2log(log,test_name,"WARNING",QString("can't find parametr `delete last'"));
    }

    QString delete_line;
    int doc_nl=0;
    int docline=0;
    if(mapLocal.find("delete line")!=mapLocal.end())
    {

        delete_line = mapLocal["delete line"];
        if(delete_line.section(":",0,0)!="")
        {
            doc_nl=delete_line.section(":",0,0).toInt();
            docline=delete_line.section(":",1,1).toInt();
        }
        if(!doc_nl || !docline)
        {
            aTests::print2log(log,test_name,"WARNING",QString("value of parametr `delete line' is invalid"));

        }

    }
    else
    {
        aTests::print2log(log,test_name,"WARNING",QString("can't find parametr `delete line"));
    }
    int count=0;
    for ( it = l.begin(); it != l.end(); ++it )
    {
        count++;
        if(count==doc_nl)
        {
            doc->select(*it);
            aTests::print2log(log,test_name,"NOTE",QString("delete line %1 doc in  %2 ").arg(docline).arg(*it));
            //doc->TableDeleteLine();
        }
    }

    QString change_res;
    int doc_chr=0;
    int doc_chr_ln=0;
    if(mapLocal.find("change line res")!=mapLocal.end())
    {

        change_res = mapLocal["change line res"];
        if(change_res.section(":",0,0)!="")
        {
            doc_chr=change_res.section(":",0,0).toInt();
            doc_chr_ln=change_res.section(":",1,1).toInt();
        }
        if(!doc_chr || !doc_chr_ln)
        {
            aTests::print2log(log,test_name,"WARNING",QString("value of parametr `change line res' is invalid"));

        }

    }
    else
    {
        aTests::print2log(log,test_name,"WARNING",QString("can't find parametr `change line res"));
    }

    count =0;
    for ( it = l.begin(); it != l.end(); ++it )
    {
        count++;
        if(count==doc_chr)
        {
            doc->select(*it);
            aTests::print2log(log,test_name,"NOTE",QString("change doc %1 line %1 ").arg(*it).arg(doc_chr_ln));
            //	doc->TableSelect("Таблица");
            //	doc->TableSetValue("Таблица","Товар",100);
            //	doc->TableUpdate();
        }
    }

    count =0;
    //QValueList<Q_ULLONG>::iterator it;
    for ( it = l.begin(); it != l.end(); ++it )
    {
        count++;
        if(count<=delete_first|| count>count_doc-delete_last)
        {
            doc->select(*it);
            aTests::print2log(log,test_name,"NOTE",QString("delete doc %1").arg(*it));
            doc->Delete();
        }
    }
    cat1->First();
    for ( i=0; i<count_doc; i++)
    {

        QVariant summa= ar->getSaldo(QDateTime::currentDateTime(),"Контрагент",cat1->sysValue("id"),"Сумма");
        double sum = summ(0,count_table_line);
        if(i<delete_first)
        {
            sum = 0;
        }
        if(i>=count_doc-delete_last)
        {
            sum = 0;
        }
        if(unconduct) sum=0;
        if(summa==sum)
        {
            aTests::print2log(log,test_name,"OK",QString("saldo kontragent %1=%2").arg(summa.toString()).arg(sum));
        }
        else
        {
            aTests::print2log(log,test_name,"ERROR",QString("saldo kontragent %1!=%2").arg(summa.toString()).arg(sum));
        }
        cat1->Next();
    }
    cat2->First();
    for ( i=0; i<count_table_line; i++)
    {

        QVariant summa= ar->getSaldo(QDateTime::currentDateTime(),"Товар",cat2->sysValue("id"),"Количество");
        int cnt = count_doc-delete_first-delete_last;

        if(unconduct) cnt=0;

        if(summa==(i+1)*cnt)
        {
            aTests::print2log(log,test_name,"OK",QString("saldo tovar%1=%2").arg(summa.toString()).arg((i+1)*cnt));
        }
        else
        {
            aTests::print2log(log,test_name,"ERROR",QString("saldo tovar%1!=%2").arg(summa.toString()).arg((i+1)*cnt));
        }
        if(!cat2->Next()) break;
    }
//	aTests::print2log(log,test_name,"NOTE","delete cat1");
    delete cat1;
//	aTests::print2log(log,test_name,"NOTE","delete cat2");
    delete cat2;
//	aTests::print2log(log,test_name,"NOTE","delete doc");
    delete doc;
//	aTests::print2log(log,test_name,"NOTE","delete ar");
    delete ar;
    aTests::print2log(log,test_name,"OK","end test");
//abort();
//	exit(0);
    db.done();
    return 0;
}
コード例 #17
0
std::vector<RealGradient>
CNSFVWENOSlopeLimiting::limitElementSlope() const
{
  const Elem * elem = _current_elem;

  /// current element id
  dof_id_type _elementID = elem->id();

  /// number of conserved variables
  unsigned int nvars = 5;

  /// number of sides surrounding an element
  unsigned int nside = elem->n_sides();

  /// vector for the limited gradients of the conserved variables
  std::vector<RealGradient> ugrad(nvars, RealGradient(0., 0., 0.));

  /// initialize local cache for reconstructed element gradients
  std::vector<RealGradient> rugrad(nvars, RealGradient(0., 0., 0.));

  /// a small number to avoid dividing by zero
  Real eps = 1e-7;

  /// initialize oscillation indicator
  std::vector<std::vector<Real>> osci(nside + 1, std::vector<Real>(nvars, 0.));

  /// initialize weight coefficients
  std::vector<std::vector<Real>> weig(nside + 1, std::vector<Real>(nvars, 0.));

  /// initialize summed coefficients
  std::vector<Real> summ(nvars, 0.);

  /// compute oscillation indicators, nonlinear weights and their summ for each stencil

  rugrad = _rslope.getElementSlope(_elementID);

  for (unsigned int iv = 0; iv < nvars; iv++)
  {
    osci[0][iv] = std::sqrt(rugrad[iv] * rugrad[iv]);

    weig[0][iv] = _lweig / std::pow(eps + osci[0][iv], _dpowe);

    summ[iv] = weig[0][iv];
  }

  for (unsigned int is = 0; is < nside; is++)
  {
    unsigned int in = is + 1;

    if (elem->neighbor(is) != NULL)
    {
      dof_id_type _neighborID = elem->neighbor(is)->id();
      rugrad = _rslope.getElementSlope(_neighborID);

      for (unsigned int iv = 0; iv < nvars; iv++)
      {
        osci[in][iv] = std::sqrt(rugrad[iv] * rugrad[iv]);

        weig[in][iv] = 1. / std::pow(eps + osci[in][iv], _dpowe);

        summ[iv] += weig[in][iv];
      }
    }
  }

  /// compute the normalized weight

  for (unsigned int iv = 0; iv < nvars; iv++)
    weig[0][iv] = weig[0][iv] / summ[iv];

  for (unsigned int is = 0; is < nside; is++)
  {
    unsigned int in = is + 1;

    if (elem->neighbor(is) != NULL)
      for (unsigned int iv = 0; iv < nvars; iv++)
        weig[in][iv] = weig[in][iv] / summ[iv];
  }

  /// compute the limited slope

  rugrad = _rslope.getElementSlope(_elementID);

  for (unsigned int iv = 0; iv < nvars; iv++)
    ugrad[iv] = weig[0][iv] * rugrad[iv];

  for (unsigned int is = 0; is < nside; is++)
  {
    unsigned int in = is + 1;

    if (elem->neighbor(is) != NULL)
    {
      dof_id_type _neighborID = elem->neighbor(is)->id();
      rugrad = _rslope.getElementSlope(_neighborID);

      for (unsigned int iv = 0; iv < nvars; iv++)
        ugrad[iv] += weig[in][iv] * rugrad[iv];
    }
  }

  return ugrad;
}