-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.cpp
More file actions
73 lines (60 loc) · 1.62 KB
/
Copy pathmod.cpp
File metadata and controls
73 lines (60 loc) · 1.62 KB
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
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include "mod.h"
using namespace std;
vector<double> mod(vector<double> t, vector<double> d){
vector<double> result;
vector<double> m; //middle polynomial
while(1){
int i;
//------------print the vector t ----------------//
// i = 0;
// for(;i<t.size();i++){
// cout << t[i] <<' ';
// }
// cout<<endl;
//-----------print the vector d ---------------//
// i = 0;
// for(;i<d.size();i++){
// cout << d[i] <<' ';
// }
// cout<<endl;
double factor = ((double)t[t.size()-1])/d[d.size()-1];
i=0;
int j=0;
for(;i<d.size();i++){
m.push_back(d[i]*factor);
}
//-----------print the vector m ---------------//
// i = 0;
// for(;i<m.size();i++){
// cout << m[i] <<' ';
// }
// cout<<endl;
i=m.size()-1;
j=t.size()-1;
for(;j>=0;j--,i--){
if(i>=0) {result.push_back(t[j]-m[i]);}
else {result.push_back(t[j]);}
}
while(result[0]==0&&result.size()>0){
result.erase(result.begin());
}
m.clear();
t.clear();
t = result;
result.clear();
reverse(t.begin(),t.end());
//bei zheng chu le
if(t.size() == 0){
t.push_back(0);
return t;
}
if(d.size()>t.size()){
break;
}
}
return t;
}