예제 #1
0
int main(){
    
    bignum valor, aux, total;  
    int n, f, i, bill = 1;  
    char str[MAXDIGITS];  
    
    scanf("%d %d", &n, &f);
    while( n ) {  
           
        scanf("%s", &str );  
        stringToBignum( str, &valor );  

        for( i = 1; i < n; i++ ){
             scanf("%s", &str );  
             stringToBignum( str, &aux );
             
             add_bignum( &valor, &aux, &total );
             
             valor = total; 
        }
        
        printf("Bill #%d costs ", bill++ );
        print_bignum( &valor );  
        sprintf( str, "%d", f );
        stringToBignum( str, &aux );
        divide_bignum( &valor, &aux, &total );
        printf(": each friend should pay ");
        print_bignum(&total);  
        printf("\n\n");
        
        scanf("%d %d", &n, &f);
    }
    
    return 0;  
}  
/** Test Function */
int main( )
{
	bignum n1, n2, n3, zero;

	// Instantiate string buffers for big numbers a and b
	char* a = calloc( MAXDIGITS, sizeof( char ) );
	char* b = calloc( MAXDIGITS, sizeof( char ) );

	// Get big numbers a and b as strings
	printf( "a = " );
	fgets( a, MAXDIGITS, stdin );

	printf( "b = " );
	fgets( b, MAXDIGITS, stdin );

	// Remove the newline character (if present) from string buffers
	char* nl;
	if( ( nl = strchr( a, '\n' ) ) != NULL ) *nl = '\0';
	if( ( nl = strchr( b, '\n' ) ) != NULL ) *nl = '\0';

	// Create a and b big number instances via the string buffers
	string_to_bignum( a, &n1 );
	string_to_bignum( b, &n2 );

	// Test addition
	add_bignum( &n1, &n2, &n3 );
	printf( "a + b = " );
	print_bignum( &n3 );

	// Test comparison
	int comparison = compare_bignum( &n1, &n2 );
	printf( "a %s b\n", comparison == 0 ? "==" : ( comparison < 0 ? ">" : "<" ) );

	// Test subtraction
	subtract_bignum( &n1, &n2, &n3 );
	printf( "a - b = " );    
	print_bignum( &n3 );

	// Test multiplication
	multiply_bignum( &n1, &n2, &n3 );
	printf( "a * b = " );
	print_bignum( &n3 );

	// Test division
	int_to_bignum( 0, &zero );
	if( compare_bignum( &zero, &n2 ) == 0 )
	{
		printf( "a / b = NaN\n" );
	}
	else 
	{
		divide_bignum( &n1, &n2, &n3 );
		printf( "a / b = " );
		print_bignum( &n3 );
	}

	return 0;
}
예제 #3
0
파일: 1133.c 프로젝트: chenfengyuan/acm-hdu
int main(void)
{
	int i,j,n;
	char str[1000];char str3[1000];char str2[1000];
	cal_p();
	cal_fac();
	/* for(i=0;i<N;++i){ */
	/*     for(j=0;j<N;++j){ */
	/*         printf("%s ",print_bignum(str,p[i][j])); */
	/*     } */
	/*     printf("\n"); */
	/* } */
	/* for(i=0;i<N;++i){ */
	/*     printf("%d\t%s\n",i,print_bignum(str,fac[i])); */
	/* } */
	n=0;
	while(scanf("%d%d",&i,&j),i||j){
		++n;
		if(i>=j){
			printf("Test #%d:\n%s\n",n,print_bignum(str2,mul(mul(fac[i],fac[j]),p[i][j])));
		} else {
			printf("Test #%d:\n0\n",n);
		}
	}
	return 0;
}
예제 #4
0
파일: 10069.c 프로젝트: condy0919/uva-code
int main() {
    int i, j;

    bignum_t zero, one;
    init(&zero);
    one.val[0] = 1, one.len = 1;

    for (i = 0; i < 10001; ++i)
        for (j = 0; j < 101; ++j)
            init(&f[i][j]);

    scanf("%d", &n);
    while (n-- > 0) {
        scanf("%s %s", a, b);

        for (i = 0; a[i]; ++i) {
            f[i + 1][1] = f[i][1];
            if (a[i] == b[0])
                f[i + 1][1] = add(&f[i + 1][1], &one);
        }

        for (j = 1; b[j]; ++j) {
            for (i = j; a[i]; ++i) {
                f[i + 1][j + 1] = f[i][j + 1];
                if (a[i] == b[j])
                    f[i + 1][j + 1] = add(&f[i + 1][j + 1], &f[i][j]);
            }
        }
        print_bignum(&f[strlen(a)][strlen(b)]);
    }
    return 0;
}
예제 #5
0
파일: bignum.c 프로젝트: walrus7521/code
int main()
{
    int x = 195;
    bignum a, b, c;
    initialize_bignum(&a);
    initialize_bignum(&b);
    initialize_bignum(&c);
    int_to_bignum(x, &a);
    printf("a = "); print_bignum(&a); printf("\n");
    reverse_bignum(&a, &b);
    printf("b = "); print_bignum(&b); printf("\n");
    int_to_bignum(1221, &c);
    printf("c = "); print_bignum(&c); printf("\n");
    is_palindrome(&c);
    return 0;
}
예제 #6
0
int main() {
    char *in_string;
    bignum *sum = make_bignum_with_length( 0 );

    while( scanf( "%s", in_string ) != EOF ) {
        sum = add_bignums( make_bignum( in_string ), sum );
    }

    print_bignum( sum );
}
예제 #7
0
파일: bignum.c 프로젝트: armenr/algorist
int main(void) {
	int a,b;
	bignum n1,n2,n3,zero;

	while (scanf("%d %d",&a,&b) != EOF) {
		printf("a = %d    b = %d\n",a,b);
		int_to_bignum(a,&n1);
		int_to_bignum(b,&n2);

		add_bignum(&n1,&n2,&n3);
		printf("addition -- ");
		print_bignum(&n3);

		printf("compare_bignum a ? b = %d\n",compare_bignum(&n1, &n2));

		subtract_bignum(&n1,&n2,&n3);
		printf("subtraction -- ");
		print_bignum(&n3);

    multiply_bignum(&n1,&n2,&n3);
		printf("multiplication -- ");
    print_bignum(&n3);

		int_to_bignum(0,&zero);
		if(compare_bignum(&zero, &n2) == 0)
			printf("division -- NaN \n");
    else {
			divide_bignum(&n1,&n2,&n3);
			printf("division -- ");
                	print_bignum(&n3);
		}
		printf("--------------------------\n");
	}
	
	return 0;
}
예제 #8
0
int main(int argc, char *argv[]) {
  int n;
  int sum = 0;
  if (argc == 1) n = 5;
  else n = atoi(argv[1]);
  bignum cur_ans, cur, ans;
  int_to_bignum(1, &cur_ans);
  for(int i = 1; i <=n; i++) {
    int_to_bignum(i, &cur);
    multiply_bignum(&cur, &cur_ans, &ans);
    cur_ans = ans;
  }
  print_bignum(&ans);
  for(int i = 0; i <= ans.lastdigit; i++) {
    sum += ans.digits[i];
  }

  printf("The ans is %d\n",  sum);
  return 0;
}
int main(){
    //declaração das variáveis
    int i, ch, nl, np;
    int *Rep = NULL;
    bignum perm;
    char frase[MAXDIGITS];
    //Armazenado a frase digitada pelo usário
    printf ("Por favor digite a frase desejada\n");
    scanf (" %[^\n]", frase);
    //A função define, define a quantidade de letras e de palavras contidas na frase,  e as armazenas em nl e np respectivamente
    define (frase, &nl, &np);
    //A função reteptição armazena a quantidade de vezes que as letras (a-z) forma repetidas armazenado em um vetor
    Rep = repeticao (frase);
    //Controle caso a locação de memórias do vetor não for bem sucedida
    if (!Rep){
        printf ("Ocorreu um erro estranho\n");
        return 0;
    }   
    //Imprime os dados obitidos
    printf("----------------\n");
    printf ("A frase digitada foi: %s\n", frase);
    printf ("Ela possui %d letras e %d palavras\n", nl, np);
    printf("----------------\n");
    printf ("Letras repetidas\n");
    for (i=0; i<ALF; i++){
        ch = 97;
        if (Rep[i] != 0){
            printf("%c -> %d repeticoes\n",ch+i, Rep[i]);
        }
    }
    printf("----------------\n");
    //A funcao calclando_com_corretas calcula qual é o numero de combianacoes exatas
    calculando_com_corretas ( nl,  np, Rep, &perm);
    printf ("A frase digitada pode ser escrita de ");
    //Exibindo o resultado
    print_bignum (&perm);
    printf ("maneiras\n");
    //FIM DO PROGRAMA
    return 0;
}