-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfft.c
118 lines (98 loc) · 2.96 KB
/
fft.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//https://thehuxley.com/problem/1036
#include <stdio.h>
#include <string.h>
#define MAXN 10000
int p[MAXN];//coeficientes de p
int q[MAXN];//coeficientes de q
int r[MAXN];//coeficientes de resultado
static int caso = 0; //numero de casos
void imprimir(int tamanho, int atual)
{
if (tamanho == atual)
{
printf("\n");
return;
}
else
{
printf(" %d",r[atual]);
imprimir(tamanho,atual+1);
}
}
void poli_multiplier(int array1[],int array2[], int tamanho_a,int tamanho_b,int array3[], int index_a, int index_b)
//index_a fica travado e index_b vai aumentando até que index_b == tamanho_b, dai recomeça e vai até index_a == tamanho_a e index_b == tamanho b
{
int grau_result = index_a+index_b;
int anterior = r[grau_result];
//printf("p[%d]*q[%d] = r[%d], anterior[%d] = %d →→ r[%d] = ",index_a,index_b,grau_result,grau_result,anterior,grau_result);
//printf("%d*%d\n", array1[index_a],array2[index_b]);
if(index_b == tamanho_b)
{
if(index_a < tamanho_a-1)
{
r[grau_result] = ((array1[index_a]*array2[index_b])+anterior);
// printf("%d\n",r[grau_result]);
poli_multiplier(array1,array2,tamanho_a,tamanho_b,array3,index_a+1,0);
}
else if (index_a == tamanho_a-1)//chegou ao fim
{
r[grau_result] = ((array1[index_a]*array2[index_b])+anterior);
//printf("%d\n",r[grau_result]);
caso = caso+1;
return;
}
}
else //index_b != tamanho_b
{
r[grau_result]=((array1[index_a]*array2[index_b])+anterior);
//printf("%d\n",r[grau_result]);
poli_multiplier(array1,array2,tamanho_a,tamanho_b,array3,index_a,index_b+1);
}
}
int scan_coef(int numero_de_coef, int counter, int tipo) //escaneia até chegar no numero maximo de coeficientes = grau+1
{
if (counter>=numero_de_coef) //caso de parada
{
return counter;
}
int coef;
scanf("%d",&coef);
//printf("coef%d:%d\n",counter,coef);
if(tipo == 1)
{
p[counter] = coef;
return scan_coef(numero_de_coef,counter+1,tipo);
}
else
{
q[counter] = coef;
return scan_coef(numero_de_coef,counter+1,tipo);
}
}
void scan_eof() //scaneia até chegar em EOF
{
int g1,g2;
int hm = scanf("%d",&g1);
if(hm == EOF)
{
return;
}
scanf("%d",&g2);
memset(p,0,sizeof(p));
memset(q,0,sizeof(q));
int tamanho_p = scan_coef(g1+1,0,1); //numero de coeficientes em p
int tamanho_q = scan_coef(g2+1,0,2); //numero de coeficientes em q
int tamanho_r = g1+g2+1; //numero de coeficientes em r
//printf("~~tamanho do r[]:%d~~\n",tamanho_r);
//limpa_array(r,MAXN,0);
memset(r,0,sizeof(r));
poli_multiplier(p,q,tamanho_p,tamanho_q,r,0,0);
printf("Caso #%d:", caso);
imprimir(tamanho_r, 0);
scan_eof();
}
int main ()
{
scan_eof();
return 0;
}